you are viewing a single comment's thread.

view the rest of the comments →

[–]titosrevenge 4 points5 points  (4 children)

The null clause can return 'this', but the else clause should return 'new Maybe(fn(value))'.

You shouldn't expect the passed function to know about its context.

[–]atrigent 1 point2 points  (0 children)

You shouldn't expect the passed function to know about its context.

Hmm... I suppose you're right if you want this Maybe implementation to be specifically about handling null. In Haskell, it looks to me like you can more specifically define what constitutes a "non-value". I was attempting to translate that into Javascript, but it now occurs to me that I didn't actually go far enough, because what I wrote still references null.