Last active
February 16, 2017 22:14
-
-
Save DrBoolean/c721b29ba7fd724912bfadda65723257 to your computer and use it in GitHub Desktop.
Sum Product extend example
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
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