dry-python / returns

Make your functions return something meaningful, typed, and safe!
https://returns.rtfd.io
BSD 2-Clause "Simplified" License
3.48k stars 115 forks source link

Add `Identity` monad #469

Open sobolevn opened 4 years ago

sobolevn commented 4 years ago

We need this to wrap regular values into a monad. This might be required when you have a function like this:

@kinded
def do_something(c: KindN[V, E, D], f: Callable[[V], N]) -> KindN[N, E, D]: ...

And you want to call it with just a plain value, like 1. Then, you wrap it into Identity(1) and pass into do_something with no problems.

Maybe does not fit for several reasons:

  1. It does not support all possible methods, like rescue
  2. It treats None differently, we should be able to wrap Identity(None) as is
sobolevn commented 4 years ago

On the other hand, it would be very strange thing to have. Maybe we can leave that for the end user?

sobolevn commented 4 years ago

Use Success

sobolevn commented 4 years ago

https://habr.com/ru/post/429104/

sobolevn commented 4 years ago

https://twitter.com/Oli_kitty/status/1293722185958227968