monet / monet.js

monet.js - Monadic types library for JavaScript
https://monet.github.io/monet.js/
MIT License
1.6k stars 114 forks source link

sequenceValidation doesn't work for Fail as stated in docs #250

Open jtzero opened 2 years ago

jtzero commented 2 years ago

the docs state that Failures will be accumulated in a list https://github.com/monet/monet.js/blob/56685952939f4c976be1ce588eb3b1f5eacd2a99/docs/LIST.md?plain=1#L316-L332

const { Success, Fail, List } = require("monet");

> List.fromArray([
...   Success("a"),
...   Success("b"),
...   Success("c")
... ]).sequenceValidation()
{
  val: {
    isNil: false,
    head_: 'a',
    tail_: {
      isNil: false,
      head_: 'b',
      tail_: [Object],
      size_: 2,
      '@@type': 'monet.js/List'
    },
    size_: 3,
    '@@type': 'monet.js/List'
  },
  isSuccessValue: true,
  '@@type': 'monet.js/Validation'
}
> // => Success(List("a", "b", "c"))
undefined
>
> List.fromArray([
...   Success("a"),
...   Success("b"),
...   Fail("c"),
...   Fail("d"),
...   Success("e")
... ]).sequenceValidation()
{ val: 'cd', isSuccessValue: false, '@@type': 'monet.js/Validation' }

And unless I;ve done this wrong, the type in the second example is returned as a string and not a list

    "monet": "^0.9.3",
> node --version
v16.13.0