-
-
Notifications
You must be signed in to change notification settings - Fork 510
Description
Hi,
I just want to start of by saying that i am fairly new to functional programming and fp-ts, so forgive me if there is some obvious flaw in my code or if my understanding of "Do notation" is off.
I just had a crack at "Do notation". I Have only implemented it for the Option data type, and therefore i don't know if this will work as well for other data types. The implementation uses an exception to short circuit, and i'm unsure what implications this might have?
Personally i think the syntax is more neat than other ones i've seen.
Looks like this:
binding(bind => {
const number1 = bind(some(5))
const number2 = bind(some(10))
return some(number1 + number2)
}
The type of number1 and number2 is type safe and inferred as number by the compiler. Same goes for the return type of course.
The syntax is inspired by the Kotlin fp library, arrow.
The branch is available here
https://github.com/Herlevsen/fp-ts/tree/monad-binding
I've added 3 tests at the bottom of test/Option.ts.
What do you think?
Thanks