You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, it's been brought to my attention that this is not a "lawful" use of a functor because it doesn't compose?
constf=(v)=>v.name;constg=JSON.stringify;constfandTheng=(a)=>g(f(a));constuser={name: null};console.log(Maybe.of(user).map(f).map(g).inspect(),// Nothing Maybe.of(user).map(fandTheng).inspect()// Just(null) );// not equal, breaks the law of composition!
I haven't finished the book so sorry if this is address further on.
PS: I think the inspect method has a bug in the recursion as this example will break it.
The text was updated successfully, but these errors were encountered:
ChuckJonas
changed the title
Maybe "map" function doesn't compose
Maybe class "map" function doesn't compose
Mar 26, 2021
I'd be remiss if I didn't mention that the "real" implementation will split Maybe into two types: one for something and the other for nothing. This allows us to obey parametricity in map so values like null and undefined can still be mapped over and the universal qualification of the value in a functor will be respected. You'll often see types like Some(x) / None or Just(x) / Nothing instead of a Maybe that does a null check on its value.
Because of the simplified implementation, there are no Just(null) and Just(undefined).
There is no recursion in Maybe.prototype.inspect. And inspect is weird in Firefox.
I'd be remiss if I didn't mention that the "real" implementation will split Maybe into two types: one for something and the other for nothing. This allows us to obey parametricity in map so values like null and undefined can still be mapped over and the universal qualification of the value in a functor will be respected. You'll often see types like Some(x) / None or Just(x) / Nothing instead of a Maybe that does a null check on its value.
Because of the simplified implementation, there are no Just(null) and Just(undefined). There is no recursion in Maybe.prototype.inspect. And inspect is weird in Firefox.
I couldn't understand that paragraph. Thank you for explaining it clearly.
In chapter 8,
Maybe
is defined as follows:Then an example is provided using a
.
style:However, it's been brought to my attention that this is not a "lawful" use of a functor because it doesn't compose?
I haven't finished the book so sorry if this is address further on.
PS: I think the
inspect
method has a bug in the recursion as this example will break it.The text was updated successfully, but these errors were encountered: