Migrated links, lyrics and properties

This commit is contained in:
marc
2025-03-23 21:46:04 +01:00
parent c097811e40
commit d596861a2e
47 changed files with 1403 additions and 844 deletions

View File

@@ -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)