Open juxeii opened 1 year ago
@jasondelaat, thank you for this fantastically useful, yet unbloated, library!
I would like to see this for Either
as well, but perhaps instead of defining new methods, the Maybe.maybe
and Either.either
methods can simply be modified (since they appear to simply be or_else
named differently) such that the identity function is the default value for the second argument to those methods, since that is arguably the most common use case, and having to repeat lambda x: x
(or identity
, if that is defined somewhere) is tiresome and unnecessarily verbose.
For example:
class Maybe(pymonad.monad.Monad, Generic[T]):
...
def maybe(self: 'Maybe[S]', default_value: T, extraction_function: Callable[[S], T] = lambda x: x) -> T:
...
class Either(pymonad.monad.Monad, Generic[M, T]):
...
def either(
self: 'Either[M, S]', left_function: Callable[[M], T], right_function: Callable[[S], T] = lambda x: x
) -> T:
...
I'd be happy to submit a PR, if this is something you're agreeable to.
Hi,
could you please add
or_else
to the Maybe monad?