These are chat archives for ramda/ramda

14th
Apr 2016
James Forbes
@JAForbes
Apr 14 2016 09:15

I'm finding I'm writing nAry(0, thunk) a lot.

The thunk in question is a stream in flyd.

const b = a.map(transformer)

But in flyd, you can also set the current value of the stream

b( newValue )

And sometimes this is useful, but a lot of the time I want to make the stream readonly. It would be a lot nicer to read R.nullary(stream) than
R.nAry(0, stream)

Any oppositions to a nullary fn?

nullary is at least a word coworkers can google and get an idea what is going on
Ricardo Pallas
@RPallas92
Apr 14 2016 10:55
If I have a Task with an array of values inside, and I want to do a trasnformation to each value of the array, should I do map(map())? Or there is a cleaner way?
Scott Christopher
@scott-christopher
Apr 14 2016 12:53
@RPallas92 If you only need to do it once, then map(map(f)) is fine.
If you find yourself repeating that, you could use a Compose data type that allows for composing two applicatives together.
Scott Christopher
@scott-christopher
Apr 14 2016 12:58
Something like:
const Compose_(F, G) = class Compose {
  constructor(value) {
    this.value = value;
  }
  map(f) {
    return new Compose(R.map(R.map(f), this.value));
  }
  ap(other) {
    return new Compose(R.ap(R.map(R.ap, this.value), other.value));
  }
  static of(x) {
    return new Compose(F.of(G.of(x)));
  }
}
Scott Christopher
@scott-christopher
Apr 14 2016 13:03
Then you should be able to compose Task and Array like:
const TaskArray = Compose_(Task, { of: x => [x] });
const c = new TaskArray(someExistingTaskOfArray);
const mappedTaskArray = map(fn, c).value;
As mentioned above, it's a bit excessive if you just want to map the odd instance, but it comes in handy if you're going to be working with applicatives of the two types.
Ricardo Pallas
@RPallas92
Apr 14 2016 14:04
Thank you @scott-christopher :smile:
Walle Cyril
@GrosSacASac
Apr 14 2016 22:36

I have some object like this
{a: 1, b: 2}

having x=1, what is the easiest way to know that the key is "a" ? I am sure x is in the values because I have if (Object.values(object1).includes(x)) before

Brad Compton (he/him)
@Bradcomp
Apr 14 2016 22:42
Instead of Object.values could you use R.toPairs()?
Then you have access to the keys and values together
Brad Compton (he/him)
@Bradcomp
Apr 14 2016 23:00
I don't claim this is ideal, but maybe something like this? http://goo.gl/CsoeY5
Walle Cyril
@GrosSacASac
Apr 14 2016 23:55
@Bradcomp can you decide http://goo.gl/6guEQr ?
I don't need to reuse, this happens only at 1 place