March 2019
Intermediate to advanced
208 pages
5h 11m
English
If you’re still a bit uncertain of what Belt.Option.map and Belt.Option.flatMap do, here’s what they’d look like if we were to implement them ourselves:
| | let myMap = (optValue: option('a), f: ('a) => 'b) : option('b) => { |
| | switch (optValue) { |
| | | Some(value) => Some(f(value)) |
| | | None => None |
| | } |
| | }; |
| | let myFlatMap = (optValue: option('a), f: ('a) => option('b)) : |
| | option('b) => { |
| | switch (optValue) { |
| | | Some(value) => f(value) |
| | | None => None |
| | } |
| | }; |
The annotation f: (’a) => option(’b) signifies a function taking a parameter of type ’a and returning a value of type option(’b).
Similarly, ...
Read now
Unlock full access