These are chat archives for ramda/ramda

29th
Oct 2016
Travis LaDuke
@laduke
Oct 29 2016 04:49
Is there a thing to test when you're using an ADT library ? assert.equal(S.head([1]), Just(1))
> assert.equal(S.head([1]), S.Just(1));
AssertionError: Just(1) == Just(1)
:(
James Forbes
@JAForbes
Oct 29 2016 04:51
Maybe: assertEqual = R.compose(assert.equal, R.toString)? Less hacky than it seems because a lot of FL libraries take their toString implementations pretty seriously.
Alternatively, R.equals will do a recursive value equality check, instead of a reference equality check
So something like
const assertEquals = 
  R.when(
    R.complement(R.equals)
   ,function(a,b){ 
          throw new Error("Not equal.  Expected "+a+" Actual: "+ b)
   }
  )
Or even just: assert.deepEqual
Travis LaDuke
@laduke
Oct 29 2016 04:56
oh that works
James Forbes
@JAForbes
Oct 29 2016 04:57
:thumbsup:
Travis LaDuke
@laduke
Oct 29 2016 05:00
I was thinking I'd write a bunch of easy tests along the lines of the little schemer but more for ramda/ADT and see if they made me smarter.
Got blocked pretty quick
James Forbes
@JAForbes
Oct 29 2016 06:31
I've been meaning to read that book for a long time! Be great to see how your project turns out
Keith Cirkel
@keithamus
Oct 29 2016 22:24

Hey Ramda folk, I have an object, with 2 keys, a and b. a is a number and b is an array. I want to write some pointfree code to assert that a is gt the length of b. I have

R.pipe(R.props(['a', 'b']), R.map(R.ifElse(R.has('length'), R.length, R.identity)), R.apply(R.gt))

But it feels super unwieldy, as it's doing multiple operations

I feel like I really just want an R.paths function, which can take a 2d array of paths to pluck from my object
or perhaps I could use where - if I could somehow assert on related keys?
Or perhaps there is a function which I can pass an array of functions to, and an object, and it'll apply those functions returning an array of results?
Brad Compton (he/him)
@Bradcomp
Oct 29 2016 22:49
@keithamus You might want to look at converge
@ram-bot
const obj = {a: 2, b: [1, 2, 3]}

converge(gt, [prop('a'), path(['b', 'length'])])(obj)
ram-bot
@ram-bot
Oct 29 2016 22:49
false
Keith Cirkel
@keithamus
Oct 29 2016 22:50
Ahhhh swweeet thanks @Bradcomp, that's so much better!