Created
August 22, 2017 17:49
-
-
Save mcsf/ebe5ad7be99275c54b35fa88ad40613c to your computer and use it in GitHub Desktop.
Coin-flip chaining: more concision with `lift`
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
import { concat, liftN } from 'ramda' | |
const flip = () => [ [ 'h' ], [ 't' ] ] | |
const concatFlips = liftN(2, concat) | |
const twoFlips = concatFlips(flip(), flip()) | |
const threeFlips = concatFlips(twoFlips, flip()) | |
twoFlips | |
// [ [ 'h', 'h' ], [ 'h', 't' ], [ 't', 'h' ], [ 't', 't' ] ] | |
threeFlips | |
// [ [ 'h', 'h', 'h' ], | |
// [ 'h', 'h', 't' ], | |
// [ 'h', 't', 'h' ], | |
// [ 'h', 't', 't' ], | |
// [ 't', 'h', 'h' ], | |
// [ 't', 'h', 't' ], | |
// [ 't', 't', 'h' ], | |
// [ 't', 't', 't' ] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment