These are chat archives for ramda/ramda

23rd
Jul 2015
Graeme Yeates
@megawac
Jul 23 2015 16:50
is R.bind backwards? I was about to tell a user to just R.map(R.bind(context), fns)
David Chambers
@davidchambers
Jul 23 2015 17:39
There’s a good argument to be made for flipping the arguments.
Tobias Pflug
@gilligan
Jul 23 2015 18:38
evening
anyone suggestions on how to collapse multiple occurrences of a specified set of characters in a string into a single one ? like f(['x', 'y'], 'abcxxdefyy') => 'abcxdefy' ?
David Chambers
@davidchambers
Jul 23 2015 18:46
This isn’t the answer, but it’s similar to what you want to do:
> R.pipe(R.split(''), R.dropRepeats, R.join(''))('abcxxdefyy')
'abcxdefy'
Tobias Pflug
@gilligan
Jul 23 2015 18:47
yeah i saw dropRepeats - only problem is it does too much ;-)
David Chambers
@davidchambers
Jul 23 2015 18:48
This is another avenue to explore:
> R.pipe(R.split(''), R.aperture(2))('abcxxdefyy')
[ [ 'a', 'b' ],
  [ 'b', 'c' ],
  [ 'c', 'x' ],
  [ 'x', 'x' ],
  [ 'x', 'd' ],
  [ 'd', 'e' ],
  [ 'e', 'f' ],
  [ 'f', 'y' ],
  [ 'y', 'y' ] ]
Tobias Pflug
@gilligan
Jul 23 2015 18:49
i'll play around a bit ;-)
David Chambers
@davidchambers
Jul 23 2015 18:57
Here’s an inelegant solution:
R.pipe(R.split(''),
       R.reduce(R.ifElse(R.both(R.pipe(R.nthArg(1), R.contains(R.__, ['x', 'y'])),
                                R.converge(R.equals, R.last, R.nthArg(1))),
                         R.identity,
                         R.concat),
                ''))
Tobias Pflug
@gilligan
Jul 23 2015 18:57
thanks
David Chambers
@davidchambers
Jul 23 2015 18:59
It’s clearer with a lambda:
R.pipe(R.split(''),
       R.reduce((s, c) => R.contains(c, ['x', 'y']) && c === R.last(s) ? s : s + c,
                ''))