These are chat archives for ramda/ramda

10th
May 2016
Hardy Jones
@joneshf
May 10 2016 04:06
You could also go the Traversable route.
Find an applicative that has the effects you want.
Your effect being that an index is incremented
Seems like the State data type. but probably could be simpler.
Lewis
@6ewis
May 10 2016 13:26
is there a way to remove properties in bulk?
bessides doing a R.dissoc multiple times
Aldwin Vlasblom
@Avaq
May 10 2016 13:37
This message was deleted
R.omit
Lewis
@6ewis
May 10 2016 13:47
@Avaq gracias
Tim Navrotskyy
@dypsilon
May 10 2016 15:43
Hi is it possible to map over bluebird promises like we do with functors?
I'm trying to use promise returning function with compose...
Raine Virta
@raine
May 10 2016 15:44
yes but not with map
Stefano Vozza
@svozza
May 10 2016 15:45
bluebirds map function is a bit weird
Brad Compton (he/him)
@Bradcomp
May 10 2016 15:45
@dypsilon Would it be possible to use something like this: https://github.com/futurize/futurize
Stefano Vozza
@svozza
May 10 2016 15:45
you'll need to use a Future
Raine Virta
@raine
May 10 2016 15:46
const then = R.invoker(1, 'then'); const fn = pipe(then(doWhatever), then(doSomethingElse));
Tim Navrotskyy
@dypsilon
May 10 2016 15:46
Hm, I'm using most.js on the other end, so I would probably need to convert futures to promises.
Brad Compton (he/him)
@Bradcomp
May 10 2016 15:46
oh
Tim Navrotskyy
@dypsilon
May 10 2016 15:46
I think, I'd rather look for some phantasy land compatible promise library...
Raine Virta
@raine
May 10 2016 15:47
then they are not promises
Brad Compton (he/him)
@Bradcomp
May 10 2016 15:49
With Promises, .then() does what map does as well as what chain does in futures. What are you trying to do?
Tim Navrotskyy
@dypsilon
May 10 2016 15:50
Basically I just want to compose normal functions with promise returning functions using point-free style.
Raine Virta
@raine
May 10 2016 15:50
I just gave you the answer
R.pipeP @dypsilon
Brad Compton (he/him)
@Bradcomp
May 10 2016 15:51
Yeah, I agree with @raine
Raine Virta
@raine
May 10 2016 15:51
there's also that
Tim Navrotskyy
@dypsilon
May 10 2016 15:52
@raine thanks, I was answering Brad's question. composeP and pipeP look simpler, so I would probably use that.
Also there are some implementations which satisfy both - fantasy-land and ES 2015
Brad Compton (he/him)
@Bradcomp
May 10 2016 15:55
@dypsilon One thing to be aware of is that with pipeP and composeP, the first function to be called must return a Promise, or else things will break. Sometimes it helps to have a function like toPromise you can stick at the beginning of your composition.
const toPromise = Promise.resolve.bind(Promise)
Tim Navrotskyy
@dypsilon
May 10 2016 15:56
@Bradcomp thank you, that's useful
thanks everyone
Brad Compton (he/him)
@Bradcomp
May 10 2016 16:06
I was JUST reading that
Lewis
@6ewis
May 10 2016 16:33
is there a fast way to change the name object keys?
Lewis
@6ewis
May 10 2016 16:35
@Bradcomp that's beautiful
R.renameKeys
ram-bot
@ram-bot
May 10 2016 16:36
Error: No such function renameKeys
Lewis
@6ewis
May 10 2016 16:36
too bad it's not in the lib
Brad Compton (he/him)
@Bradcomp
May 10 2016 16:38
We have it as a lib function in most of our projects. It's really helpful sometimes
Lewis
@6ewis
May 10 2016 17:04
Unexpected token
Brad Compton (he/him)
@Bradcomp
May 10 2016 17:08
@6ewis You need to use computed properties:
  const renameKeysOf = (prefix) => 
      renameKeys(
        {[`${prefix}_line_1`]: 'line_1',
         [`${prefix}_line_2`]: 'line_2',
         [`${prefix}_line_3`]: 'line_3',
         [`${prefix}_line_4`]: 'line_4',
         [`${prefix}_locality`]: 'locality',
         [`${prefix}_region`]: 'region',
         [`${prefix}_postal_code`]: 'postal_code',
         [`${prefix}_country_name`]: 'country_name'
       });
Template strings are really expressions, not strings, so you can't use them directly as keys
Putting the expression in brackets will use the result of evaluating the expression as the key for the object
Lewis
@6ewis
May 10 2016 17:10
@Bradcomp ah thanks
Brad Compton (he/him)
@Bradcomp
May 10 2016 17:10
Lewis
@6ewis
May 10 2016 17:12
@Bradcomp got it ;)
Brad Compton (he/him)
@Bradcomp
May 10 2016 17:12
:+1:
Lewis
@6ewis
May 10 2016 17:13
@Bradcomp honestly though you should give clojurescript a try. it's amazing
Brad Compton (he/him)
@Bradcomp
May 10 2016 17:17
@6ewis It's tempting because, like JavaScript, I could use the same language on the client and server. Also, I do like Scheme.
Lewis
@6ewis
May 10 2016 17:27
This message was deleted
Slađan Ristić
@sladiri
May 10 2016 21:51

Hi, I have a problem that I want to R.set() in a particular condition with R.cond(), but the value for R.set() should only be computed then, not before. Is this doable "lazily"?

For example this is a problem for R.cond, if calc(key) does not take undefined key
[R.always(R.not(R.isNil(key))), R.always(R.set(lens, calc(key), obj))],

Brad Compton (he/him)
@Bradcomp
May 10 2016 22:03
@sladiri Without a working example, I can only speculate, but the most likely issue is that JavaScript eagerly evaluates its function parameters. You might be able to wrap your call in a function, thus delaying evaluation until the condition is checked.
R.unless(R.isNil, key => R.set(lens, calc(key), obj));
In the above example, calc(key) won't be evaluated if key isNil
Slađan Ristić
@sladiri
May 10 2016 22:16
@Bradcomp Thank you a lot, I think this should work, I will try it.
The whole thing would have been this, I was playing around with Ramda:
const lens = R.lensProp(key);
return R.cond([
  [R.always(R.equals(key, ICOL)), R.always(R.set(lens, parseDecimal(car[key]), obj))],
  [R.T, R.always(obj)]
        ])(key);
Taylor Hurt
@thurt
May 10 2016 22:21
Quick question: looking for ideas on how to divide a list of tuples into a length 2 list like: [[1,2], [1,2], [1,2]] -> [[1,1, 1], [2, 2, 2]]
Brad Compton (he/him)
@Bradcomp
May 10 2016 22:22
@ram-bot transpose([[1,2], [1,2], [1,2]] )
ram-bot
@ram-bot
May 10 2016 22:22
[ [ 1, 1, 1 ], [ 2, 2, 2 ] ]
Brad Compton (he/him)
@Bradcomp
May 10 2016 22:23
:-D
Taylor Hurt
@thurt
May 10 2016 22:23
thanks! I am new :)
Brad Compton (he/him)
@Bradcomp
May 10 2016 22:24
Welcome!
@sladiri
R.ifElse(
  R.equals(ICOL), 
  key => R.set(lens, parseDecimal(car[key]), obj), 
  R.always(obj)
)(key)
Assuming ICOL, lens, and obj are defined in a closure
Slađan Ristić
@sladiri
May 10 2016 22:43
@Bradcomp Thank you again, they are indeed defined in a closure. Learned something new with transpose as well. :)
Brad Compton (he/him)
@Bradcomp
May 10 2016 22:45
:+1:
Brad Compton (he/him)
@Bradcomp
May 10 2016 23:23
R.pipeK