dbrattli / Expression

Pragmatic functional programming for Python inspired by F#
https://expression.readthedocs.io
MIT License
421 stars 30 forks source link

Is Option or Result type have apply function? #145

Open linitachi opened 1 year ago

linitachi commented 1 year ago

Is your feature request related to a problem? Please describe. I want to using applicative in expression, like this example https://github.com/dbrattli/OSlash/wiki/Functors,-Applicatives,-And-Monads-In-Pictures#applicatives

Describe the solution you'd like

a = Some(5)
b = lambda x: Some(x)
a.apply(b)

thanks!

phi-friday commented 1 year ago

You can use a method bind.

import expression as ex

a = ex.Some(5)
b = lambda x: ex.Some(x)
a.bind(b)
linitachi commented 1 year ago

Thanks for your reply! I think bind is a flatmap and it's diffenrent from applicative, if there are any applicative just like fp-ts apply? https://gcanti.github.io/fp-ts/modules/Apply.ts.html

Thank you again for your reply!

phi-friday commented 1 year ago

Thanks for your reply! I think bind is a flatmap and it's diffenrent from applicative, if there are any applicative just like fp-ts apply? https://gcanti.github.io/fp-ts/modules/Apply.ts.html

Thank you again for your reply!

@linitachi I'm sorry I left a comment without reading it properly.

u3kkasha commented 7 months ago

@linitachi Check this out : Effects

u3kkasha commented 5 months ago

You can also use the member function called map2 >>> Some(8).map2(lambda x,y: x+y, Some(6)) Some 14