Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
|
|
@ -2,7 +2,6 @@
|
|||
from __future__ import annotations
|
||||
from itertools import chain
|
||||
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import Iterable
|
||||
from typing import List
|
||||
|
|
@ -10,6 +9,7 @@ from typing import TypeVar
|
|||
|
||||
|
||||
T = TypeVar("T")
|
||||
U = TypeVar("U")
|
||||
|
||||
|
||||
class MList(List[T]):
|
||||
|
|
@ -17,15 +17,15 @@ class MList(List[T]):
|
|||
def unit(cls, value: Iterable[T]) -> MList[T]:
|
||||
return cls(value)
|
||||
|
||||
def bind(self, func: Callable[[T], MList[Any]]) -> MList[Any]:
|
||||
def bind(self, func: Callable[[T], MList[U]]) -> MList[U]:
|
||||
return MList(chain.from_iterable(map(func, self)))
|
||||
|
||||
def __rshift__(self, func: Callable[[T], MList[Any]]) -> MList[Any]:
|
||||
def __rshift__(self, func: Callable[[T], MList[U]]) -> MList[U]:
|
||||
return self.bind(func)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Chained int and string functions
|
||||
# Chained int and string functions.
|
||||
print(
|
||||
MList([1, 99, 4])
|
||||
.bind(lambda val: MList([val + 1]))
|
||||
|
|
@ -39,14 +39,14 @@ if __name__ == "__main__":
|
|||
>> (lambda val: MList([f"${val}.00"]))
|
||||
)
|
||||
|
||||
# Cartesian product of [1..5] and [6..10]
|
||||
# Cartesian product of [1..5] and [6..10].
|
||||
print(
|
||||
MList(range(1, 6)).bind(
|
||||
lambda x: MList(range(6, 11)).bind(lambda y: MList([(x, y)]))
|
||||
)
|
||||
)
|
||||
|
||||
# Pythagorean triples with elements between 1 and 25
|
||||
# Pythagorean triples with elements between 1 and 25.
|
||||
print(
|
||||
MList(range(1, 26)).bind(
|
||||
lambda x: MList(range(x + 1, 26)).bind(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue