feat(rx): add cond fabric
This commit is contained in:
parent
737f21bf06
commit
e7e6491cc3
2 changed files with 15 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ from .bindable import Bindable
|
||||||
from .chain import chain
|
from .chain import chain
|
||||||
from .combine import combine
|
from .combine import combine
|
||||||
from .concat import concat
|
from .concat import concat
|
||||||
|
from .cond import cond
|
||||||
from .const import const
|
from .const import const
|
||||||
from .filter import filter # noqa: W0622 # pylint: disable=W0622
|
from .filter import filter # noqa: W0622 # pylint: disable=W0622
|
||||||
from .map import map # noqa: W0622 # pylint: disable=W0622
|
from .map import map # noqa: W0622 # pylint: disable=W0622
|
||||||
|
|
@ -18,6 +19,7 @@ __all__ = [
|
||||||
"chain",
|
"chain",
|
||||||
"combine",
|
"combine",
|
||||||
"concat",
|
"concat",
|
||||||
|
"cond",
|
||||||
"const",
|
"const",
|
||||||
"filter",
|
"filter",
|
||||||
"map",
|
"map",
|
||||||
|
|
|
||||||
13
src/snakia/core/rx/cond.py
Normal file
13
src/snakia/core/rx/cond.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
|
|
||||||
|
def cond[**P, T, F](
|
||||||
|
condition: Callable[P, bool],
|
||||||
|
if_true: Callable[P, T],
|
||||||
|
if_false: Callable[P, F],
|
||||||
|
) -> Callable[P, T | F]:
|
||||||
|
return lambda *args, **kw: (
|
||||||
|
if_true(*args, **kw)
|
||||||
|
if condition(*args, **kw)
|
||||||
|
else if_false(*args, **kw)
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue