Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
Created July 19, 2013 15:27
Show Gist options
  • Select an option

  • Save hughfdjackson/6039990 to your computer and use it in GitHub Desktop.

Select an option

Save hughfdjackson/6039990 to your computer and use it in GitHub Desktop.
var Sandbox = function(val, err){
this.val = val;
this.err = err;
}
Sandbox.prototype.map = function(fn){
if ( this.err ) return this;
try {
return new Sandbox(fn(this.val));
} catch(e) {
return new Sandbox(undefined, e)
}
}
Sandbox.prototype.get = function(defaultCase){
if ( ! defaultCase ) throw Error('default required');
if ( this.err ) return defaultCase;
else return this.val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment