Created
September 16, 2013 09:36
-
-
Save mattfield/6578528 to your computer and use it in GitHub Desktop.
Either functor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Either = function(left, right){ | |
this.left = left; | |
this.right = right; | |
}; | |
Either.prototype.map = function(f){ | |
return this.right ? | |
Either(this.left, f(this.right)) : | |
Either(f(this.left), this.left); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment