Skip to content

Instantly share code, notes, and snippets.

@DrBoolean
Last active February 16, 2017 22:14
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 DrBoolean/c721b29ba7fd724912bfadda65723257 to your computer and use it in GitHub Desktop.
Save DrBoolean/c721b29ba7fd724912bfadda65723257 to your computer and use it in GitHub Desktop.
Sum Product extend example
const {Tuple} = require('fantasy-tuples')
const Either = require('data.either') // missing extend, but could pr
Tuple(current_user, age)
.map(age => age + 1)
.extend(({_1: user, _2: age}) =>
Object.assign({}, user, {age}))
// Tuple(current_user, current_user_with_age)
// ^ notice this only ever changes the _2, but you can see _1 while you work.
Either.of([1,2,3])
.map(arr => arr.slice(1))
.extend(either =>
either.concat(Either.fromNullable([4])))
// Right([2,3,4])
// ^ notice this only ever changes the Right, but you get the whole Right.
// Untested, but ya know...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment