Skip to content

Instantly share code, notes, and snippets.

@yelouafi
Created July 17, 2015 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yelouafi/c919f3ccc553cfc325cb to your computer and use it in GitHub Desktop.
Save yelouafi/c919f3ccc553cfc325cb to your computer and use it in GitHub Desktop.
// anError : Object
// mapError : (Stream a, anError -> Stream a) => Stream a
Stream.prototype.mapError = function(f) {
return this.isEmpty ? this
: this.isAbort ? f(this.error)
: this.isCons ? Stream.Cons(this.head, this.tail.mapError(f))
: Stream.Future(
this.promise.then(
s => s.mapError(f),
Stream.Abort))
}
Stream.Cons(1, Stream.Abort('Error!!'))
.mapError(err => Stream.Cons(2, Stream.Empty))
.log()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment