Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Bind in ReScript (not to import JS, but to bind multiple Option or Result)

$
0
0

In scala, we can write the following by comprehension notation.

val result = for {
  a <- Some(1)
  b <- Some(2)
} yield a + b

In fsharp, we can use computation expressions.

let result = 
  option {
    let! a = Some 1
    let! b = Some 2
    return a + b
  }

In fp-ts, it is as follows

const result = pipe(
    O.bindTo("a")(O.some(1)),
    O.bind("b", () => O.some(2)),
    O.map(({ a, b }) => a + b)
  );
}

Can I write a similar process in rescript?
I don’t want the nesting to be too deep when chaining flatMaps.


Viewing all articles
Browse latest Browse all 2592

Trending Articles