OSlash

raw JSON →
2.0.0 verified Fri May 01 auth: no python

A functional programming library providing Functors, Applicatives, and Monads for Python 3.12+. Current version 2.0.0, stable release with PEP 695 type parameters and strict type checking. Maintained on an irregular cadence by dbrattli.

pip install oslash
error ModuleNotFoundError: No module named 'oslash.maybe'
cause In OSlash v2.0.0, submodules like `oslash.maybe` were removed in favor of direct imports.
fix
Change import from from oslash.maybe import Maybe to from oslash import Maybe.
error TypeError: unsupported operand type(s) for >>: 'NoneType' and 'function'
cause Used `>>` on Python's built-in None instead of OSlash's Nothing() singleton.
fix
Use Nothing() from oslash instead of plain None.
error ImportError: cannot import name 'Right' from 'oslash'
cause `Right` and `Left` constructors are not exported; use `Either.right` and `Either.left` methods or the class constructors.
fix
Use from oslash import Either; value = Either.right(42) or Either(42, is_right=True).
error AttributeError: 'Maybe' object has no attribute 'bind'
cause The method for monadic bind is `>>` operator, not `.bind()`.
fix
Use >> operator, e.g., maybe >> lambda x: Just(x+1).
breaking Python 3.12 minimum: OSlash v2.0.0 requires Python 3.12+ and will not install on older versions.
fix Upgrade to Python 3.12 or higher, or pin to an older OSlash version (<2.0.0) if you must use an older Python.
deprecated Old import paths like `from oslash.maybe import Maybe` or `from oslash.either import Either` no longer work in v2.0.0.
fix Use direct imports: `from oslash import Maybe, Either, List`.
gotcha The `List` monad's `bind` (>>) expects a function that returns a list of monadic values, not a plain list. Misuse can lead to unexpected behavior.
fix Always wrap plain values in the monad (e.g., `lambda x: Just(x)`) when using >>.

Basic usage of Maybe monad with map and bind (>>).

from oslash import Maybe, Just, Nothing

result = Just(42).map(lambda x: x * 2)
print(result)
# Output: Just(84)

result2 = Nothing() >> (lambda x: Just(x * 2))
print(result2)
# Output: Nothing()