mlms13 / bs-decode

Type-safe JSON decoding for ReasonML and OCaml
https://mlms13.github.io/bs-decode/docs/what-and-why
MIT License
103 stars 18 forks source link

Add letops support #127

Closed mlms13 closed 1 year ago

mlms13 commented 1 year ago

I think this is basically all we need to do:

let ( let* ) = flat_map;
let (let+) = (m, f) => map(f, m);
let (and+) = (m1, m2) => map2((a, b) => (a, b), m1, m2);

But we probably don't want to define (and+) in terms of map2, since map2 is likely going away (#119). So instead, we should probably just add a let pair function that does exactly what (and+) wants, and we can define it in terms of apply.

Then decoders can be used like:

let decode = {
  open Decode;
  let+ company = field("company_id", string)
  and+ employee = field("employee_id", string);
  {employee, company};
};

The checklist:

mlms13 commented 1 year ago

This was fixed in #136