These are chat archives for ramda/ramda

26th
Jan 2017
Brendan Annable
@BrendanAnnable
Jan 26 2017 04:12
Anybody know why R.flip does not work with R.juxt?
Brendan Annable
@BrendanAnnable
Jan 26 2017 04:35
or alternatively, is there a better function for doing R.map(foo => foo(bar))?
James Forbes
@JAForbes
Jan 26 2017 06:09
Hey is this a bug:
typeof R.either(R.identity, R.identity, 1)
//=> function

typeof R.either(R.identity,R.identity)(1)
//=> number
Brad Compton (he/him)
@Bradcomp
Jan 26 2017 06:26
R.either
Brad Compton (he/him)
@Bradcomp
Jan 26 2017 06:26
Looks like it's expected behavior given the type sig.
Robin Wenglewski
@rweng
Jan 26 2017 09:19
Hi, quick question: Is it intended that R.clone([instanceOfClass]) does not call the #clone() method available on the Class, but only checks at the first level (the array) whether a #clone() method exists?
Ismael
@ZaoIsmael
Jan 26 2017 09:44

hi, I need help for a method

i have this structure and need get ids

const data = {
  id:1,
  leaf:[
    {
      id:2,
      leaf:[]
    },
    {
      id:3,
      leaf:[
        {
          id:5,
          leaf:[]
        },
        {
          id:6,
          leaf:[
            {
              id:8,
              leaf:[]
            }
          ]
        }
      ]
    },
    {
      id:4,
      leaf:[
        {
          id:7,
          leaf:[]
        }
      ]
    }
  ]
}
const id = 1
getLeaf(id, data) // output [2,3,4,5,6,7,8]

const id = 3
getLeaf(id, data) // output [5,6,8]
James Forbes
@JAForbes
Jan 26 2017 09:45
@Bradcomp hmm interesting, seems broken, I get why we need multiple invocations for variadic functions like compose or pipe, but either isn't variadic

@JAForbes i'm rewrite my code use recursion. It's look better:

 R = require('ramda');

function applyMask(mask, value) {
   var mch = R.head(mask)
   var vch = R.head(value)

   if(mch == '') {
      return ''
   } else {
      if(mch === 'd') {
         return vch === '' ? '_' + applyMask(R.tail(mask), value)  : vch + applyMask(R.tail(mask), R.tail(value));
      } else {
         return mch + applyMask(R.tail(mask), value); 
      }
   }    
}

But steel have ugly if-else

@alex-deas thanks i'm already read this.
Rick Medina
@rickmed
Jan 26 2017 13:42
On the recursion comment above, has anyone has had recursion problems in js? do you use trampolining just in case?
Kurt Milam
@kurtmilam
Jan 26 2017 14:17
What do I need to do in order to get a new date each time I call setTime?
const theTimeLens = lensProp( `theTime` )
const setTheTime = set( theTimeLens, new Date() )

console.log( setTheTime( {} ) ) // {"theTime":"2017-01-26T14:17:01.205Z"}
console.log( setTheTime( {} ) ) // {"theTime":"2017-01-26T14:17:01.205Z"}
I understand the issue, but I'm drawing a blank on how to get around it.
Kevin Wallace
@kedashoe
Jan 26 2017 17:42
@JAForbes the problem is that the function either returns can have any arity. I tried to address the issue here: ramda/ramda#2007
Rick Medina
@rickmed
Jan 26 2017 17:44
@kurtmilam shouldn't that work as is? maybe wrap new date in a function?
Brad Compton (he/him)
@Bradcomp
Jan 26 2017 18:33
@kurtmilam this will work, but I would probably recommend against it. Why not just write a custom setter?
Gabe Johnson
@gabejohnson
Jan 26 2017 21:01
@kurtmilam I agree w/ @Bradcomp but here’s a very slight change to your code that works
curried functions + side-effects = ?
Keith Alexander
@kwijibo
Jan 26 2017 22:16
@ZaoIsmael something like
const getLeaf = (node, startID) => 
    node.leaf.reduce((accum,child)=> 
        [  ...accum
           , ...getLeaf(child, (node.id==startID? child.id : startID))
         ], (node.id==startID? [node.id] : [])
     )
although that's not quite right because it includes your start ID, and you just want the children
Kurt Milam
@kurtmilam
Jan 26 2017 22:17
@rickmed: It doesn't work as is. new Date() is only fired once, when setTheTime is defined.
@Bradcomp Thanks! This is an artificial 'problem' that I ran into while getting my feet wet with react, but I wanted to see what options were available to me, should I ever run into it in real life.
@gabejohnson Also nice. I had considered trying a solution like yours and Brad's, but gave up too early, having convinced myself it wouldn't work :)
I guess the two solutions work because new Date() isn't called until the obj is passed into the wrapper function?
Gabe Johnson
@gabejohnson
Jan 26 2017 22:29
@kurtmilam correct