Your implementation of the just value constructor is wrong:
staticjust(value){if(value===null||value===undefined){thrownewError("Can't construct a value from null/undefined");}returnnewMaybe(value);}
just must not know anything about value. It is like forbidding the array functor to deal with nested arrays:
[[1],[2,3],[4,5]].map(xs=>xs.length);// [1,2,2]
This is a perfectly valid example. With this in mind it is also valid to map over a value of type just<nothing>.
If a value is of type just<a> or nothing is not determined inside of a constructor, it is determined at the call side where the constructor is invoked.
Your implementation of the
just
value constructor is wrong:just
must not know anything aboutvalue
. It is like forbidding the array functor to deal with nested arrays:This is a perfectly valid example. With this in mind it is also valid to map over a value of type
just<nothing>
.If a value is of type
just<a>
ornothing
is not determined inside of a constructor, it is determined at the call side where the constructor is invoked.Yup, that's a fair criticism - I will update my example.
Thanks!!!