kothon


Namekothon JSON
Version 0.3.1 PyPI version JSON
download
home_page
SummaryA Python library that brings Kotlin's Sequence class functionalities and the power of functional programming to Python for more expressive and efficient data processing.
upload_time2024-03-10 13:20:48
maintainer
docs_urlNone
author
requires_python>=3.9
licenseMIT License Copyright (c) 2024 KlausH09 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords python functional-programming kotlin-sequences data-processing lazy-evaluation type-hints
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Kothon

![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2FKlausH09%2Fkothon%2Fmain%2Fpyproject.toml)
![GitHub License](https://img.shields.io/github/license/KlausH09/kothon)
![PyPI - Status](https://img.shields.io/pypi/status/kothon)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/KlausH09/kothon/tests.yml)
![Static Badge](https://img.shields.io/badge/coverage-100%25-success)

[//]: # (Using a static badge for 100% code coverage is justified because your test pipeline ensures coverage never falls below 100%, making dynamic updates unnecessary.)

Kothon is a Python library designed to bring the elegance and functionality of Kotlin's Sequence class into the Python
ecosystem. With an emphasis on functional programming paradigms, Kothon enables Python developers to leverage
lazy-evaluated sequences, allowing for efficient and expressive data processing pipelines.

## Features

- **Functional Programming**: Embrace functional programming with a rich set of operators
  like `map`, `filter`, `reduce`, and much more, enabling you to write more declarative and concise code.
- **Strongly Typed**: Leveraging Python's type hints for clearer, more robust code.
- **Lazy Evaluation**: Kothon sequences are evaluated lazily, meaning computations are deferred until the value is
  needed, enhancing performance especially for large datasets.
- **Interoperability**: Seamlessly integrate with existing Python codebases, enjoying the benefits of Kotlin-like
  sequences without disrupting your current workflow.
- **Easy to Use**: Kothon's API is designed to be intuitive for both Python and Kotlin developers, ensuring a smooth
  learning curve.

## Installation

To install Kothon, simply run the following command in your terminal:

```bash
pip install kothon
```

## Quick Start

Here's a quick example to get you started with Kothon:

```python
from kothon import Seq

input_data = [0, 1, None, 2, 3, None, 4]

# Apply some functional operations
result = Seq(input_data) \
    .filter_not_none() \
    .filter(lambda x: x % 2 == 0) \
    .map(lambda x: x * 2) \
    .to_list()

print(result)  # Output: [0, 4, 8]
```

Alternatively, utilize `pipe` for a more Pythonic approach.

```python
from kothon import pipe, filter_not_none, kothon_filter, kothon_map

input_data = [0, 1, None, 2, 3, None, 4]

# Apply some functional operations
result = pipe(
    input_data,
    filter_not_none,
    kothon_filter(lambda x: x % 2 == 0),
    kothon_map(lambda x: x * 2),
).to_list()

print(result)  # Output: [0, 4, 8]
```

## Existing functions in `Seq`

- [filter](#filter)
- [filter_not_none](#filter_not_none)
- [filter_is_instance](#filter_is_instance)
- [map](#map)
- [map_not_none](#map_not_none)
- [flat_map](#flat_map)
- [flatten](#flatten)
- [associate](#associate)
- [associate_by](#associate_by)
- [associate_with](#associate_with)
- [group_by](#group_by)
- [to_list](#to_list)
- [to_set](#to_set)
- [all](#all)
- [none](#none)
- [any](#any)
- [max](#max)
- [max_or_none](#max_or_none)
- [max_by](#max_by)
- [max_by_or_none](#max_by_or_none)
- [min](#min)
- [min_or_none](#min_or_none)
- [min_by](#min_by)
- [min_by_or_none](#min_by_or_none)
- [single](#single)
- [single_or_none](#single_or_none)
- [first](#first)
- [first_or_none](#first_or_none)
- [last](#last)
- [last_or_none](#last_or_none)
- [drop](#drop)
- [drop_while](#drop_while)
- [take](#take)
- [take_while](#take_while)
- [sorted](#sorted)
- [sorted_by](#sorted_by)
- [sorted_desc](#sorted_desc)
- [sorted_by_desc](#sorted_by_desc)
- [chunked](#chunked)
- [enumerate](#enumerate)
- [shuffled](#shuffled)
- [reduce](#reduce)
- [reduce_or_none](#reduce_or_none)
- [sum](#sum)
- [sum_or_none](#sum_or_none)
- [distinct](#distinct)
- [distinct_by](#distinct_by)
- [for_each](#for_each)
- [join_to_string](#join_to_string)
- [partition](#partition)

### filter

Filters elements based on a predicate.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3, 4, 5])
>>> seq.filter(lambda x: x % 2 == 0).to_list()
[2, 4]
>>>
```

### filter_not_none

Filters out `None` values from the sequence.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, None, 2, None, 3])
>>> seq.filter_not_none().to_list()
[1, 2, 3]
>>>
```

### filter_is_instance

Filters elements of the sequence based on their type.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 'two', 3, 'four', 5])
>>> seq.filter_is_instance(str).to_list()
['two', 'four']
>>>
```

### map

Applies a function to each element in the sequence.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3])
>>> seq.map(lambda x: x * x).to_list()
[1, 4, 9]
>>>
```

### map_not_none

Applies a function to each element and filters out `None` results.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3, 4])
>>> seq.map_not_none(lambda x: x * 2 if x % 2 == 0 else None).to_list()
[4, 8]
>>>
```

### flat_map

Applies a function to each element that returns an iterable and flattens the result.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3])
>>> seq.flat_map(lambda x: [x, -x]).to_list()
[1, -1, 2, -2, 3, -3]
>>>
```

### flatten

Flattens a sequence of iterables into a single sequence.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([[1, 2], [3, 4], [5]])
>>> seq.flatten().to_list()
[1, 2, 3, 4, 5]
>>>
```

### associate

Transforms elements into key-value pairs and aggregates them into a dictionary.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(["a", "bb", "ccc"])
>>> seq.associate(lambda x: (x, len(x)))
{'a': 1, 'bb': 2, 'ccc': 3}
>>>
```

### associate_by

Creates a dictionary from the sequence by determining keys using a specified key selector function.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(["apple", "banana", "cherry"])
>>> seq.associate_by(lambda x: x[0])
{'a': 'apple', 'b': 'banana', 'c': 'cherry'}
>>>
```

### associate_with

Creates a dictionary from the sequence with elements as keys and values determined by a value selector function.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3])
>>> seq.associate_with(lambda x: x * x)
{1: 1, 2: 4, 3: 9}
>>>
```

### group_by

Groups elements based on a key function.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(["one", "two", "three"])
>>> seq.group_by(len)
{3: ['one', 'two'], 5: ['three']}
>>>
```

### to_list

Converts the sequence to a list.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3])
>>> seq.to_list()
[1, 2, 3]
>>>
```

### to_set

Converts the sequence to a set.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 2, 3, 3])
>>> seq.to_set()
{1, 2, 3}
>>>
```

### all

Checks if all elements satisfy a condition.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([2, 4, 6])
>>> seq.all(lambda x: x % 2 == 0)
True
>>> seq.all(lambda x: x > 5)
False
>>>
```

### none

Checks if no elements satisfy a condition.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 3, 5])
>>> seq.none(lambda x: x % 2 == 0)
True
>>> seq.none(lambda x: x < 5)
False
>>>
```

### any

Checks if any elements satisfy a condition.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3])
>>> seq.any(lambda x: x % 2 == 0)
True
>>> seq.any(lambda x: x > 5)
False
>>>
```

### max

Finds the maximum element.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 3, 2])
>>> seq.max()
3
>>>
```

### max_or_none

Finds the maximum element, or returns `None` for an empty sequence.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 3, 2])
>>> seq.max_or_none()
3
>>> seq = Seq([])
>>> seq.max_or_none()
>>>
```

### max_by

Finds the element which maximizes a specified function.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(['a', 'abc', 'ab'])
>>> seq.max_by(len)
'abc'
>>>
```

### max_by_or_none

Like `max_by`, but returns `None` for an empty sequence.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(['a', 'abc', 'ab'])
>>> seq.max_by_or_none(len)
'abc'
>>> seq = Seq([])
>>> seq.max_by_or_none(len)
>>>
```

### min

Finds the minimum element.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([3, 1, 2])
>>> seq.min()
1
>>>
```

### min_or_none

Finds the minimum element, or returns `None` for an empty sequence.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 3, 2])
>>> seq.min_or_none()
1
>>> seq = Seq([])
>>> seq.min_or_none()
>>>
```

### min_by

Finds the element which minimizes a specified function.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(['abc', 'a', 'ab'])
>>> seq.min_by(len)
'a'
>>>
```

### min_by_or_none

Like `min_by`, but returns `None` for an empty sequence.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(['abc', 'a', 'ab'])
>>> seq.min_by_or_none(len)
'a'
>>> seq = Seq([])
>>> seq.min_by_or_none(len)
>>>
```

### single

Returns the single element of the sequence, and throws an error if the sequence does not contain exactly one element.

```python
>>> from kothon import Seq
>>>
>>> Seq([9]).single()
9
>>> # Seq([]).single()  # ERROR
>>> # Seq([1, 2]).single()  # ERROR
>>>
```

### single_or_none

Returns the single element of the sequence, or `None` if the sequence is empty. Throws an error if the sequence contains more than one element.

```python
>>> from kothon import Seq
>>>
>>> Seq([9]).single_or_none()
9
>>> Seq([]).single_or_none()
>>> Seq([1, 2]).single_or_none()
>>>
```

### first

Returns the first element of the sequence. Throws an error if the sequence is empty.

```python
>>> from kothon import Seq
>>>
>>> Seq([7, 8, 9]).first()
7
>>> # Seq([]).first()  # ERROR
>>>
```

### first_or_none

Returns the first element of the sequence, or `None` if the sequence is empty.

```python
>>> from kothon import Seq
>>>
>>> Seq([7, 8, 9]).first_or_none()
7
>>> Seq([]).first_or_none()
>>>
```

### last

Returns the last element of the sequence. Throws an error if the sequence is empty.

```python
>>> from kothon import Seq
>>>
>>> Seq([7, 8, 9]).last()
9
>>> # Seq([]).last()  # ERROR
>>>
```

### last_or_none

Returns the last element of the sequence, or `None` if the sequence is empty.

```python
>>> from kothon import Seq
>>>
>>> Seq([7, 8, 9]).last_or_none()
9
>>> Seq([]).last_or_none()
>>>
```

### drop

Returns a new sequence with the first `n` elements removed.

```python
>>> from kothon import Seq
>>>
>>> Seq([1, 2, 3, 4]).drop(2).to_list()
[3, 4]
>>>
```

### drop_while

Returns a new sequence by dropping elements as long as the predicate is true.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3, 4, 1])
>>> seq.drop_while(lambda x: x < 3).to_list()
[3, 4, 1]
>>>
```

### take

Returns a new sequence containing the first `n` elements.

```python
>>> from kothon import Seq
>>>
>>> Seq([1, 2, 3, 4]).take(2).to_list()
[1, 2]
>>>
```

### take_while

Returns a new sequence by taking elements as long as the predicate is true.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3, 4, 1])
>>> seq.take_while(lambda x: x < 3).to_list()
[1, 2]
>>>
```

### sorted

Returns a new sequence with elements sorted in ascending order.

```python
>>> from kothon import Seq
>>>
>>> Seq([3, 1, 4]).sorted().to_list()
[1, 3, 4]
>>>
```

### sorted_by

Sorts elements by a specified key function.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(['apple', 'banana', 'cherry'])
>>> seq.sorted_by(lambda x: x[0]).to_list()
['apple', 'banana', 'cherry']
>>>
```

### sorted_desc

Returns a new sequence with elements sorted in descending order.

```python
>>> from kothon import Seq
>>>
>>> Seq([3, 1, 4]).sorted_desc().to_list()
[4, 3, 1]
>>>
```

### sorted_by_desc

Sorts elements by a specified key function in descending order.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(['apple', 'banana', 'cherry'])
>>> seq.sorted_by_desc(lambda x: x[0]).to_list()
['cherry', 'banana', 'apple']
>>>
```

### chunked

Splits the sequence into chunks of the specified size.

```python
>>> from kothon import Seq
>>>
>>> Seq([1, 2, 3, 4, 5]).chunked(2).to_list()
[[1, 2], [3, 4], [5]]
>>>
```

### enumerate

Adds an index to each element of the sequence.

```python
>>> from kothon import Seq
>>>
>>> Seq(['a', 'b', 'c']).enumerate().to_list()
[(0, 'a'), (1, 'b'), (2, 'c')]
>>>
```

### shuffled

Returns a new sequence with elements shuffled in random order.

```python
>>> import random
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3, 4, 5])
>>> rng = random.Random(42)  # custom pseudo-random number generator, Optional
>>> seq.shuffled(rng).to_list()
[4, 2, 3, 5, 1]
>>>
```

### reduce

Reduces the sequence to a single value by applying a binary operation. Throws an error if the sequence is empty.

```python
>>> from kothon import Seq
>>>
>>> Seq([1, 2, 3, 4]).reduce(lambda x, y: x + y)
10
>>>
```

### reduce_or_none

Like `reduce`, but returns `None` for an empty sequence.

```python
>>> from kothon import Seq
>>>
>>> Seq([1, 2, 3, 4]).reduce_or_none(lambda x, y: x + y)
10
>>> Seq([]).reduce_or_none(lambda x, y: x + y)
>>>
```

### sum

Sums the elements in the sequence. Throws an error if the sequence is empty.

```python
>>> from kothon import Seq
>>>
>>> Seq([1, 2, 3, 4]).sum()
10
>>>
```


### sum_or_none

Calculates the sum of all elements in the sequence, or returns `None` if the sequence is empty.

```python
>>> from kothon import Seq
>>>
>>> Seq([1, 2, 3, 4]).sum_or_none()
10
>>> Seq([]).sum_or_none()
>>>
```

### distinct

Returns a new sequence with distinct elements.

```python
>>> from kothon import Seq
>>>
>>> Seq([1, 2, 2, 3, 3]).distinct().to_list()
[1, 2, 3]
>>>
```

### distinct_by

Returns a new sequence with elements that are distinct based on the specified key function.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(['apple', 'banana', 'apricot'])
>>> seq.distinct_by(lambda x: x[0]).to_list()
['apple', 'banana']
>>>
```

### for_each

Applies an action to each element of the sequence.

```python
>>> from kothon import Seq
>>>
>>> result = []
>>> Seq([1, 2, 3]).for_each(lambda x: print(x))
1
2
3
>>>
```

### join_to_string

Concatenates elements of the sequence into a single string with specified separators and optional prefix/suffix.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq(['apple', 'banana', 'cherry'])
>>> seq.join_to_string(separator=", ", prefix="[", suffix="]")
'[apple, banana, cherry]'
>>>
```

### partition

Splits the sequence into two sequences based on a predicate. The first sequence contains elements for which the predicate is true, and the second contains elements for which it is false.

```python
>>> from kothon import Seq
>>>
>>> seq = Seq([1, 2, 3, 4, 5])
>>> true_part, false_part = seq.partition(lambda x: x % 2 == 0)
>>> true_part
[2, 4]
>>> false_part
[1, 3, 5]
>>>
```

## Contributing

We welcome contributions! If you have improvements or bug fixes, please feel free to create a pull request.

## Acknowledgments

Kothon is inspired by the Kotlin Sequence class and the broader functional programming paradigm. We are grateful to the
Kotlin community for their innovative work, which has inspired the creation of this library.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "kothon",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Klaus Happacher <k.happacher@gmail.com>",
    "keywords": "python,functional-programming,kotlin-sequences,data-processing,lazy-evaluation,type-hints",
    "author": "",
    "author_email": "Klaus Happacher <k.happacher@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/89/4a/d465829c1b52ed644e95e8e1b5ba5eb05d7d7905e54d551b93e51947cce2/kothon-0.3.1.tar.gz",
    "platform": null,
    "description": "# Kothon\n\n![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2FKlausH09%2Fkothon%2Fmain%2Fpyproject.toml)\n![GitHub License](https://img.shields.io/github/license/KlausH09/kothon)\n![PyPI - Status](https://img.shields.io/pypi/status/kothon)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/KlausH09/kothon/tests.yml)\n![Static Badge](https://img.shields.io/badge/coverage-100%25-success)\n\n[//]: # (Using a static badge for 100% code coverage is justified because your test pipeline ensures coverage never falls below 100%, making dynamic updates unnecessary.)\n\nKothon is a Python library designed to bring the elegance and functionality of Kotlin's Sequence class into the Python\necosystem. With an emphasis on functional programming paradigms, Kothon enables Python developers to leverage\nlazy-evaluated sequences, allowing for efficient and expressive data processing pipelines.\n\n## Features\n\n- **Functional Programming**: Embrace functional programming with a rich set of operators\n  like `map`, `filter`, `reduce`, and much more, enabling you to write more declarative and concise code.\n- **Strongly Typed**: Leveraging Python's type hints for clearer, more robust code.\n- **Lazy Evaluation**: Kothon sequences are evaluated lazily, meaning computations are deferred until the value is\n  needed, enhancing performance especially for large datasets.\n- **Interoperability**: Seamlessly integrate with existing Python codebases, enjoying the benefits of Kotlin-like\n  sequences without disrupting your current workflow.\n- **Easy to Use**: Kothon's API is designed to be intuitive for both Python and Kotlin developers, ensuring a smooth\n  learning curve.\n\n## Installation\n\nTo install Kothon, simply run the following command in your terminal:\n\n```bash\npip install kothon\n```\n\n## Quick Start\n\nHere's a quick example to get you started with Kothon:\n\n```python\nfrom kothon import Seq\n\ninput_data = [0, 1, None, 2, 3, None, 4]\n\n# Apply some functional operations\nresult = Seq(input_data) \\\n    .filter_not_none() \\\n    .filter(lambda x: x % 2 == 0) \\\n    .map(lambda x: x * 2) \\\n    .to_list()\n\nprint(result)  # Output: [0, 4, 8]\n```\n\nAlternatively, utilize `pipe` for a more Pythonic approach.\n\n```python\nfrom kothon import pipe, filter_not_none, kothon_filter, kothon_map\n\ninput_data = [0, 1, None, 2, 3, None, 4]\n\n# Apply some functional operations\nresult = pipe(\n    input_data,\n    filter_not_none,\n    kothon_filter(lambda x: x % 2 == 0),\n    kothon_map(lambda x: x * 2),\n).to_list()\n\nprint(result)  # Output: [0, 4, 8]\n```\n\n## Existing functions in `Seq`\n\n- [filter](#filter)\n- [filter_not_none](#filter_not_none)\n- [filter_is_instance](#filter_is_instance)\n- [map](#map)\n- [map_not_none](#map_not_none)\n- [flat_map](#flat_map)\n- [flatten](#flatten)\n- [associate](#associate)\n- [associate_by](#associate_by)\n- [associate_with](#associate_with)\n- [group_by](#group_by)\n- [to_list](#to_list)\n- [to_set](#to_set)\n- [all](#all)\n- [none](#none)\n- [any](#any)\n- [max](#max)\n- [max_or_none](#max_or_none)\n- [max_by](#max_by)\n- [max_by_or_none](#max_by_or_none)\n- [min](#min)\n- [min_or_none](#min_or_none)\n- [min_by](#min_by)\n- [min_by_or_none](#min_by_or_none)\n- [single](#single)\n- [single_or_none](#single_or_none)\n- [first](#first)\n- [first_or_none](#first_or_none)\n- [last](#last)\n- [last_or_none](#last_or_none)\n- [drop](#drop)\n- [drop_while](#drop_while)\n- [take](#take)\n- [take_while](#take_while)\n- [sorted](#sorted)\n- [sorted_by](#sorted_by)\n- [sorted_desc](#sorted_desc)\n- [sorted_by_desc](#sorted_by_desc)\n- [chunked](#chunked)\n- [enumerate](#enumerate)\n- [shuffled](#shuffled)\n- [reduce](#reduce)\n- [reduce_or_none](#reduce_or_none)\n- [sum](#sum)\n- [sum_or_none](#sum_or_none)\n- [distinct](#distinct)\n- [distinct_by](#distinct_by)\n- [for_each](#for_each)\n- [join_to_string](#join_to_string)\n- [partition](#partition)\n\n### filter\n\nFilters elements based on a predicate.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3, 4, 5])\n>>> seq.filter(lambda x: x % 2 == 0).to_list()\n[2, 4]\n>>>\n```\n\n### filter_not_none\n\nFilters out `None` values from the sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, None, 2, None, 3])\n>>> seq.filter_not_none().to_list()\n[1, 2, 3]\n>>>\n```\n\n### filter_is_instance\n\nFilters elements of the sequence based on their type.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 'two', 3, 'four', 5])\n>>> seq.filter_is_instance(str).to_list()\n['two', 'four']\n>>>\n```\n\n### map\n\nApplies a function to each element in the sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3])\n>>> seq.map(lambda x: x * x).to_list()\n[1, 4, 9]\n>>>\n```\n\n### map_not_none\n\nApplies a function to each element and filters out `None` results.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3, 4])\n>>> seq.map_not_none(lambda x: x * 2 if x % 2 == 0 else None).to_list()\n[4, 8]\n>>>\n```\n\n### flat_map\n\nApplies a function to each element that returns an iterable and flattens the result.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3])\n>>> seq.flat_map(lambda x: [x, -x]).to_list()\n[1, -1, 2, -2, 3, -3]\n>>>\n```\n\n### flatten\n\nFlattens a sequence of iterables into a single sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([[1, 2], [3, 4], [5]])\n>>> seq.flatten().to_list()\n[1, 2, 3, 4, 5]\n>>>\n```\n\n### associate\n\nTransforms elements into key-value pairs and aggregates them into a dictionary.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([\"a\", \"bb\", \"ccc\"])\n>>> seq.associate(lambda x: (x, len(x)))\n{'a': 1, 'bb': 2, 'ccc': 3}\n>>>\n```\n\n### associate_by\n\nCreates a dictionary from the sequence by determining keys using a specified key selector function.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([\"apple\", \"banana\", \"cherry\"])\n>>> seq.associate_by(lambda x: x[0])\n{'a': 'apple', 'b': 'banana', 'c': 'cherry'}\n>>>\n```\n\n### associate_with\n\nCreates a dictionary from the sequence with elements as keys and values determined by a value selector function.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3])\n>>> seq.associate_with(lambda x: x * x)\n{1: 1, 2: 4, 3: 9}\n>>>\n```\n\n### group_by\n\nGroups elements based on a key function.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([\"one\", \"two\", \"three\"])\n>>> seq.group_by(len)\n{3: ['one', 'two'], 5: ['three']}\n>>>\n```\n\n### to_list\n\nConverts the sequence to a list.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3])\n>>> seq.to_list()\n[1, 2, 3]\n>>>\n```\n\n### to_set\n\nConverts the sequence to a set.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 2, 3, 3])\n>>> seq.to_set()\n{1, 2, 3}\n>>>\n```\n\n### all\n\nChecks if all elements satisfy a condition.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([2, 4, 6])\n>>> seq.all(lambda x: x % 2 == 0)\nTrue\n>>> seq.all(lambda x: x > 5)\nFalse\n>>>\n```\n\n### none\n\nChecks if no elements satisfy a condition.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 3, 5])\n>>> seq.none(lambda x: x % 2 == 0)\nTrue\n>>> seq.none(lambda x: x < 5)\nFalse\n>>>\n```\n\n### any\n\nChecks if any elements satisfy a condition.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3])\n>>> seq.any(lambda x: x % 2 == 0)\nTrue\n>>> seq.any(lambda x: x > 5)\nFalse\n>>>\n```\n\n### max\n\nFinds the maximum element.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 3, 2])\n>>> seq.max()\n3\n>>>\n```\n\n### max_or_none\n\nFinds the maximum element, or returns `None` for an empty sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 3, 2])\n>>> seq.max_or_none()\n3\n>>> seq = Seq([])\n>>> seq.max_or_none()\n>>>\n```\n\n### max_by\n\nFinds the element which maximizes a specified function.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq(['a', 'abc', 'ab'])\n>>> seq.max_by(len)\n'abc'\n>>>\n```\n\n### max_by_or_none\n\nLike `max_by`, but returns `None` for an empty sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq(['a', 'abc', 'ab'])\n>>> seq.max_by_or_none(len)\n'abc'\n>>> seq = Seq([])\n>>> seq.max_by_or_none(len)\n>>>\n```\n\n### min\n\nFinds the minimum element.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([3, 1, 2])\n>>> seq.min()\n1\n>>>\n```\n\n### min_or_none\n\nFinds the minimum element, or returns `None` for an empty sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 3, 2])\n>>> seq.min_or_none()\n1\n>>> seq = Seq([])\n>>> seq.min_or_none()\n>>>\n```\n\n### min_by\n\nFinds the element which minimizes a specified function.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq(['abc', 'a', 'ab'])\n>>> seq.min_by(len)\n'a'\n>>>\n```\n\n### min_by_or_none\n\nLike `min_by`, but returns `None` for an empty sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq(['abc', 'a', 'ab'])\n>>> seq.min_by_or_none(len)\n'a'\n>>> seq = Seq([])\n>>> seq.min_by_or_none(len)\n>>>\n```\n\n### single\n\nReturns the single element of the sequence, and throws an error if the sequence does not contain exactly one element.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([9]).single()\n9\n>>> # Seq([]).single()  # ERROR\n>>> # Seq([1, 2]).single()  # ERROR\n>>>\n```\n\n### single_or_none\n\nReturns the single element of the sequence, or `None` if the sequence is empty. Throws an error if the sequence contains more than one element.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([9]).single_or_none()\n9\n>>> Seq([]).single_or_none()\n>>> Seq([1, 2]).single_or_none()\n>>>\n```\n\n### first\n\nReturns the first element of the sequence. Throws an error if the sequence is empty.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([7, 8, 9]).first()\n7\n>>> # Seq([]).first()  # ERROR\n>>>\n```\n\n### first_or_none\n\nReturns the first element of the sequence, or `None` if the sequence is empty.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([7, 8, 9]).first_or_none()\n7\n>>> Seq([]).first_or_none()\n>>>\n```\n\n### last\n\nReturns the last element of the sequence. Throws an error if the sequence is empty.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([7, 8, 9]).last()\n9\n>>> # Seq([]).last()  # ERROR\n>>>\n```\n\n### last_or_none\n\nReturns the last element of the sequence, or `None` if the sequence is empty.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([7, 8, 9]).last_or_none()\n9\n>>> Seq([]).last_or_none()\n>>>\n```\n\n### drop\n\nReturns a new sequence with the first `n` elements removed.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([1, 2, 3, 4]).drop(2).to_list()\n[3, 4]\n>>>\n```\n\n### drop_while\n\nReturns a new sequence by dropping elements as long as the predicate is true.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3, 4, 1])\n>>> seq.drop_while(lambda x: x < 3).to_list()\n[3, 4, 1]\n>>>\n```\n\n### take\n\nReturns a new sequence containing the first `n` elements.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([1, 2, 3, 4]).take(2).to_list()\n[1, 2]\n>>>\n```\n\n### take_while\n\nReturns a new sequence by taking elements as long as the predicate is true.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3, 4, 1])\n>>> seq.take_while(lambda x: x < 3).to_list()\n[1, 2]\n>>>\n```\n\n### sorted\n\nReturns a new sequence with elements sorted in ascending order.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([3, 1, 4]).sorted().to_list()\n[1, 3, 4]\n>>>\n```\n\n### sorted_by\n\nSorts elements by a specified key function.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq(['apple', 'banana', 'cherry'])\n>>> seq.sorted_by(lambda x: x[0]).to_list()\n['apple', 'banana', 'cherry']\n>>>\n```\n\n### sorted_desc\n\nReturns a new sequence with elements sorted in descending order.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([3, 1, 4]).sorted_desc().to_list()\n[4, 3, 1]\n>>>\n```\n\n### sorted_by_desc\n\nSorts elements by a specified key function in descending order.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq(['apple', 'banana', 'cherry'])\n>>> seq.sorted_by_desc(lambda x: x[0]).to_list()\n['cherry', 'banana', 'apple']\n>>>\n```\n\n### chunked\n\nSplits the sequence into chunks of the specified size.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([1, 2, 3, 4, 5]).chunked(2).to_list()\n[[1, 2], [3, 4], [5]]\n>>>\n```\n\n### enumerate\n\nAdds an index to each element of the sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq(['a', 'b', 'c']).enumerate().to_list()\n[(0, 'a'), (1, 'b'), (2, 'c')]\n>>>\n```\n\n### shuffled\n\nReturns a new sequence with elements shuffled in random order.\n\n```python\n>>> import random\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3, 4, 5])\n>>> rng = random.Random(42)  # custom pseudo-random number generator, Optional\n>>> seq.shuffled(rng).to_list()\n[4, 2, 3, 5, 1]\n>>>\n```\n\n### reduce\n\nReduces the sequence to a single value by applying a binary operation. Throws an error if the sequence is empty.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([1, 2, 3, 4]).reduce(lambda x, y: x + y)\n10\n>>>\n```\n\n### reduce_or_none\n\nLike `reduce`, but returns `None` for an empty sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([1, 2, 3, 4]).reduce_or_none(lambda x, y: x + y)\n10\n>>> Seq([]).reduce_or_none(lambda x, y: x + y)\n>>>\n```\n\n### sum\n\nSums the elements in the sequence. Throws an error if the sequence is empty.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([1, 2, 3, 4]).sum()\n10\n>>>\n```\n\n\n### sum_or_none\n\nCalculates the sum of all elements in the sequence, or returns `None` if the sequence is empty.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([1, 2, 3, 4]).sum_or_none()\n10\n>>> Seq([]).sum_or_none()\n>>>\n```\n\n### distinct\n\nReturns a new sequence with distinct elements.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> Seq([1, 2, 2, 3, 3]).distinct().to_list()\n[1, 2, 3]\n>>>\n```\n\n### distinct_by\n\nReturns a new sequence with elements that are distinct based on the specified key function.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq(['apple', 'banana', 'apricot'])\n>>> seq.distinct_by(lambda x: x[0]).to_list()\n['apple', 'banana']\n>>>\n```\n\n### for_each\n\nApplies an action to each element of the sequence.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> result = []\n>>> Seq([1, 2, 3]).for_each(lambda x: print(x))\n1\n2\n3\n>>>\n```\n\n### join_to_string\n\nConcatenates elements of the sequence into a single string with specified separators and optional prefix/suffix.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq(['apple', 'banana', 'cherry'])\n>>> seq.join_to_string(separator=\", \", prefix=\"[\", suffix=\"]\")\n'[apple, banana, cherry]'\n>>>\n```\n\n### partition\n\nSplits the sequence into two sequences based on a predicate. The first sequence contains elements for which the predicate is true, and the second contains elements for which it is false.\n\n```python\n>>> from kothon import Seq\n>>>\n>>> seq = Seq([1, 2, 3, 4, 5])\n>>> true_part, false_part = seq.partition(lambda x: x % 2 == 0)\n>>> true_part\n[2, 4]\n>>> false_part\n[1, 3, 5]\n>>>\n```\n\n## Contributing\n\nWe welcome contributions! If you have improvements or bug fixes, please feel free to create a pull request.\n\n## Acknowledgments\n\nKothon is inspired by the Kotlin Sequence class and the broader functional programming paradigm. We are grateful to the\nKotlin community for their innovative work, which has inspired the creation of this library.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 KlausH09  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A Python library that brings Kotlin's Sequence class functionalities and the power of functional programming to Python for more expressive and efficient data processing.",
    "version": "0.3.1",
    "project_urls": {
        "Documentation": "https://github.com/KlausH09/kothon/blob/main/README.md",
        "Homepage": "https://github.com/KlausH09/kothon",
        "Issues": "https://github.com/KlausH09/kothon/issues",
        "Repository": "https://github.com/KlausH09/kothon.git"
    },
    "split_keywords": [
        "python",
        "functional-programming",
        "kotlin-sequences",
        "data-processing",
        "lazy-evaluation",
        "type-hints"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e03c9932e3f67a7e5f3e08462c639461a43126c24cf37252e61d1d9ef1457174",
                "md5": "4f11fde7e398cb7143283af12f7b82f1",
                "sha256": "33fb0d36c4d1cb2d5e199d47e2e50f32240bdb2f7dc4431a360cac7090716d2e"
            },
            "downloads": -1,
            "filename": "kothon-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4f11fde7e398cb7143283af12f7b82f1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 23465,
            "upload_time": "2024-03-10T13:20:46",
            "upload_time_iso_8601": "2024-03-10T13:20:46.598368Z",
            "url": "https://files.pythonhosted.org/packages/e0/3c/9932e3f67a7e5f3e08462c639461a43126c24cf37252e61d1d9ef1457174/kothon-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "894ad465829c1b52ed644e95e8e1b5ba5eb05d7d7905e54d551b93e51947cce2",
                "md5": "e04fbe5f46a54a5928b4f156abaad0f4",
                "sha256": "bac79042f1feb27baf8f6d898d4309008ccdfad1a2ac7d0df2f304c5b260ab91"
            },
            "downloads": -1,
            "filename": "kothon-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e04fbe5f46a54a5928b4f156abaad0f4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 28447,
            "upload_time": "2024-03-10T13:20:48",
            "upload_time_iso_8601": "2024-03-10T13:20:48.472076Z",
            "url": "https://files.pythonhosted.org/packages/89/4a/d465829c1b52ed644e95e8e1b5ba5eb05d7d7905e54d551b93e51947cce2/kothon-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-10 13:20:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "KlausH09",
    "github_project": "kothon",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "kothon"
}
        
Elapsed time: 0.20023s