Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add or_else #29

Open
juxeii opened this issue Apr 11, 2023 · 2 comments
Open

Please add or_else #29

juxeii opened this issue Apr 11, 2023 · 2 comments

Comments

@juxeii
Copy link

juxeii commented Apr 11, 2023

Hi,

could you please add or_else to the Maybe monad?

@chuckwondo
Copy link

@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:
        ...

@chuckwondo
Copy link

I'd be happy to submit a PR, if this is something you're agreeable to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants