Migrated links, lyrics and properties
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import itertools
|
||||
from collections.abc import Callable, Iterable, Iterator
|
||||
from typing import Protocol, Self, TypeVar
|
||||
from typing import Generic, Protocol, Self, TypeVar
|
||||
|
||||
|
||||
class SupportsLessThan(Protocol):
|
||||
@@ -20,3 +22,28 @@ def groupby(
|
||||
) -> Iterator[tuple[KeyT, GroupT]]:
|
||||
for k, g in itertools.groupby(sorted(it, key=key_fn), key=key_fn):
|
||||
yield k, group_fn(g)
|
||||
|
||||
|
||||
U = TypeVar("U")
|
||||
V = TypeVar("V")
|
||||
|
||||
|
||||
def map_none(fn: Callable[[U], V], value: U | None) -> V | None:
|
||||
if value is None:
|
||||
return None
|
||||
return fn(value)
|
||||
|
||||
|
||||
class FnChain(Generic[U]):
|
||||
def __init__(self, fn: Callable[[], U], /):
|
||||
self._fn: Callable[[], U] = fn
|
||||
|
||||
def __or__(self, next_fn: Callable[[U], V], /) -> FnChain[V]:
|
||||
return FnChain(lambda: next_fn(self._fn()))
|
||||
|
||||
def result(self) -> U:
|
||||
return self._fn()
|
||||
|
||||
@classmethod
|
||||
def transform(cls, x: V, /) -> FnChain[V]:
|
||||
return FnChain(lambda: x)
|
||||
|
||||
Reference in New Issue
Block a user