These are chat archives for ramda/ramda

20th
Mar 2017
Matthew Willhite
@miwillhite
Mar 20 2017 19:34

@vijaytv Still just paying around, may not be relevant anymore ;)

function f (ls) {
  return ifElse(
    isEmpty,
    identity,
    compose(
      apply(useWith(prepend, [identity, compose(f, tail)])),
      splitWhen(equals(0))
    )
  )(ls);
}

f([2,3,4,0,3,4,0,2]);

//=> [[2, 3, 4], [3, 4], [2]]

I’m not sure how to get rid of the explicit recursion, though I imagine there is a way…

Denis Stoyanov
@xgrommx
Mar 20 2017 19:43
@miwillhite what is case?
Matthew Willhite
@miwillhite
Mar 20 2017 21:40
@xgrommx no idea :sweat_smile: Just saw that user wanted [2,3,4,0,3,4,0,2] -> [[2, 3, 4], [3, 4], [2]] (split on 0)
Matthew Willhite
@miwillhite
Mar 20 2017 21:48
Also, I wrote splitWhen a while back to solve a very similar problem but ended up never using it. So was just trying to justify it somehow ;)
Denis Stoyanov
@xgrommx
Mar 20 2017 21:53
:smile:
compose(
  map(map(parseInt)), 
  split('0'), 
  join('')
)([2,3,4,0,3,4,0,2])
Matthew Willhite
@miwillhite
Mar 20 2017 21:55
:+1:
Denis Stoyanov
@xgrommx
Mar 20 2017 21:56
I think this is just a joke :smile: (I don't think that it will be useful, but split/join is isomorphism for string and array)
Matthew Willhite
@miwillhite
Mar 20 2017 21:59
I really just took it as an exercise to look at recursion (knowing that I generally want to find a higher level abstraction) and trying to remember what inspired splitWhen. In my case I had a list of more complex objects with steps placed throughout.
It was actually for a form builder where a user could build out a form definition. Then they could place a “step” field wherever they wanted to introduce a step in a wizard like format.
but yeah…this is a very monday Monday so really just chewing on things to wake me up a bit :joy:
Denis Stoyanov
@xgrommx
Mar 20 2017 22:06
const splitWhenDeep = curry((p, xs) => {
  if(xs.length === 0) return [];
  const [first, [_, ...rest]] = splitWhen(p, xs)

  return [first, ...splitWhenDeep(p, rest)]
}); 

splitWhenDeep(equals(0))([2,3,4,0,3,4,0,2])
Matthew Willhite
@miwillhite
Mar 20 2017 22:18
That looks a lot like my first implementation (though I didn’t use destructuring). Then I wanted to try to make it using more ramda functions because it seems like people like that ;)
Julio Borja Barra
@juboba
Mar 20 2017 22:23
@skatcat31 ??
Robert Mennell
@skatcat31
Mar 20 2017 22:23
@juboba reference?
Julio Borja Barra
@juboba
Mar 20 2017 22:24
you referenced me
Robert Mennell
@skatcat31
Mar 20 2017 22:26
Ah that was some time ago wasn't it? :point_up: March 14, 2017 9:45 AM was you asking for some examples of using bitwise operators
Julio Borja Barra
@juboba
Mar 20 2017 22:26
ohhh
yes, how did you find that?
I'm new to gitter
I'm an IRC guy haha
Robert Mennell
@skatcat31
Mar 20 2017 22:28
I just scrolled up. I'm new to gitter as of last year really. I was an IRC lurker for the longest time( I miss bash.org updates )
Julio Borja Barra
@juboba
Mar 20 2017 22:28
:P
Daniel Skelton
@dskelton-r7
Mar 20 2017 22:34
@xgrommx add 100 into your string example input array 😛
Denis Stoyanov
@xgrommx
Mar 20 2017 22:36
:point_up: March 20, 2017 11:56 PM @dskelton-r7
Robert Mennell
@skatcat31
Mar 20 2017 22:49
compose(
  map(map(parseInt)), 
  split(/\|0\||\|/), 
  join('|')
)([2,3,4,0,3,4,0,2])
This should catch those cases
Julio Borja Barra
@juboba
Mar 20 2017 22:54
@skatcat31 thanks!, just read that about bitwise ops!