either-fantasy
A fantasyland either implementation
var either =// # Right values gets acted onvar right = eitherconsole// => 'Hello actOn actOn'// # Left values shortcutsvar left = eitherleft'passThrough'console// => 'passThrough'// # Function utilconsole// => 'Good'console// => 'Bad'{ return v + v }{ throw 'Bad' }{ return 'Good' }
Example use: JavaScript can only exit a function in one of two ways, either return something or throw something. This can be modeled with a either
, where errors shortcuts chains and values gets acted on.