Skip to content

Instantly share code, notes, and snippets.

@mcsf
Created August 22, 2017 17:49
Show Gist options
  • Save mcsf/ebe5ad7be99275c54b35fa88ad40613c to your computer and use it in GitHub Desktop.
Save mcsf/ebe5ad7be99275c54b35fa88ad40613c to your computer and use it in GitHub Desktop.
Coin-flip chaining: more concision with `lift`
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