These are chat archives for ramda/ramda

1st
Sep 2016
Churchill Lee
@FeliciousX
Sep 01 2016 08:01
const arrOfFunctions = map( manipulateFn, arr );
map( fn => compose( fn, someFn ), arrOfFunctions );
how would one make this pointfree?
Aldwin Vlasblom
@Avaq
Sep 01 2016 08:06

@FeliciousX Unfortunately, Ramda's compose is variadic. If you have a binary compose which you can flip, like Sanctuary's compose, then it would be:

map(flip(S.compose)(someFn), arrOfFunctions);

If you want to stay purely with Ramda's semantics, you should be able to work around it using useWith:

map(useWith(compose, [identity, someFn]), arrOfFunctions)
Or maybe the placeholder will work, I'm not sure:
@ram-bot map(compose(__, add(1)), [add(1)]) [0](1) //3?
ram-bot
@ram-bot
Sep 01 2016 08:08
g.call is not a function
Aldwin Vlasblom
@Avaq
Sep 01 2016 08:10
This message was deleted
@ram-bot compose(__, add(1))(add(1))(1)
ram-bot
@ram-bot
Sep 01 2016 08:10
g.call is not a function
Aldwin Vlasblom
@Avaq
Sep 01 2016 08:11
@ram-bot compose(add(1), add(1))(1)
ram-bot
@ram-bot
Sep 01 2016 08:11
3
Aldwin Vlasblom
@Avaq
Sep 01 2016 08:11
Hm, so it doesn't look like the placeholder works. Maybe I'm missing something.
Churchill Lee
@FeliciousX
Sep 01 2016 08:18
D:
Denis Stoyanov
@xgrommx
Sep 01 2016 08:22
maybe we need compose2 in Ramda? Like B = S(K(S))(S)
Aldwin Vlasblom
@Avaq
Sep 01 2016 08:25
Denis Stoyanov
@xgrommx
Sep 01 2016 08:26
:smile:
ugly js
b = s (k s) k
Aldwin Vlasblom
@Avaq
Sep 01 2016 08:28
And yes, compose2 is one of the big missing things in Ramda, I would agree. But I guess it's very easy to create, or import from any other FP lib.
Aldwin Vlasblom
@Avaq
Sep 01 2016 08:52
@ram-bot
const list = [{a: 1}, {a: 1}, {a: 2}, {a: 3}, {a: 2}, {a: 1}];
groupWith(eqProps('a'), list)
ram-bot
@ram-bot
Sep 01 2016 08:52
[ [ { a: 1 }, { a: 1 } ],
  [ { a: 2 } ],
  [ { a: 3 } ],
  [ { a: 2 } ],
  [ { a: 1 } ] ]
Aldwin Vlasblom
@Avaq
Sep 01 2016 08:52
Look at the last entry. I think that's a bug in groupWith, probably some off-by-one-error.
Hold on. Is the list expected to be sorted?
Ah. Yes, seems like it is implied by the examples.
Bravi
@Bravilogy
Sep 01 2016 10:22
Does ramda have equivalent to Math.pow ?
I would like to pass base (number) as a second argument
Bravi
@Bravilogy
Sep 01 2016 10:34
nvm, figured it out
Rafe
@rjmk
Sep 01 2016 11:11
@JAForbes On zipCall from one of your previous solutions, you may be interested in joneshf/ziparray
Denis Stoyanov
@xgrommx
Sep 01 2016 11:18
@rjmk ZipArray, couldn't in js because we cannot to create infinity list.
Churchill Lee
@FeliciousX
Sep 01 2016 11:27
@Bravilogy what's ur solution? :D
Scott Christopher
@scott-christopher
Sep 01 2016 11:48
Rafe
@rjmk
Sep 01 2016 11:52
@xgrommx Also, it's still a useful Apply even if not an Applicative
Denis Stoyanov
@xgrommx
Sep 01 2016 12:07
@scott-christopher I know about it
Denis Stoyanov
@xgrommx
Sep 01 2016 12:34
function * zipWith (f, xs, ys) {
  let x = xs.next()
  let y = ys.next()
  while(!x.done && !y.done) {
    yield f(x.value, y.value)
    x = xs.next()
    y = ys.next()
  }
}

function * of(value) {
  for(;;) { yield value }
}

function * ap (fs, xs) {
  yield * zipWith((f, v) => f(v), fs, xs)
}
generators more powerful than arrays. Also we can get result pretty easy [...gen]
Ryan Zeigler
@rzeigler
Sep 01 2016 13:08
maybe this is just me, but I strongly dislike generators
particularly the fact that they can receive value back in
what even is control flow?
LeonineKing1199
@LeonineKing1199
Sep 01 2016 15:44
Generators are hecka cool though! You can decouple storage methods from algorithms and have everything just work! For example, instead of maping over a List, you can instead just map over an iterators range! This would allow you to write one function that could work for multiple container types
This is basically all of C++ in a nutshell.
LeonineKing1199
@LeonineKing1199
Sep 01 2016 15:49

particularly the fact that they can receive value back in

This is what the co module uses and co is one of the better async control flow libraries.

Ryan Zeigler
@rzeigler
Sep 01 2016 15:58
i feel like I can already decouple storage methods from algorithms. in particular, clojure has shown the only thing you actually need is a reduce implementation
or at least, they brought it to the mainstream
LeonineKing1199
@LeonineKing1199
Sep 01 2016 15:58
That's fine but at the same time, in JS, you can iterate over a Map, Set, Array of just a generator itself.
Doing all that with one algorithm is pretty cool!
Ryan Zeigler
@rzeigler
Sep 01 2016 16:00
lots of people like them, i just don’t feel it
LeonineKing1199
@LeonineKing1199
Sep 01 2016 16:02
Generators are interesting though. In JS, they sort of represent an isolated context that you can communicate with using iterators. Iterators are the mechanism that allow two isolated contexts to communicate with each other.
I tihnk that gives a lot of algorithmic power
Brian Gates
@brian-gates
Sep 01 2016 17:38
How can I clean this up?
// req -> node -> Query
var findRelated = R.curry(
  (req, node) => node.findRelated(labels(req), findArguments(req))
);
actually, hang on, that example isn't correct
Brian Gates
@brian-gates
Sep 01 2016 17:43
// req -> node -> Query
var findRelated = R.curry(
  (req, node) => node.findRelated.apply(node, findArguments(req))
);
there.
that works.
Denys Dovhan
@denysdovhan
Sep 01 2016 18:47
hi, is there any function like zipWith and zip but for more that two arrays. I mean something like this:
R.zip([1, 2, 3], ['a', 'b', 'c'], ['1', '2', '3']); //=> [[1, 'a', '1'], [2, 'b', '2'], [3, 'c', '3']]
I have an array of matrixes and I need to concatenate each of their rows
Brad Compton (he/him)
@Bradcomp
Sep 01 2016 18:54
@denysdovhan That doesn't exist in Ramda, but could you use
R.transpose
ram-bot
@ram-bot
Sep 01 2016 18:54
[R.transpose ∷ [[a]] → [[a]]](http://ramdajs.com/docs/#transpose)
Denys Dovhan
@denysdovhan
Sep 01 2016 18:58
that means if I have array of 4 arrays 7x7, I need to get one array with 7 rows and 4x7=28 cols:
[
  [1, 2],
  [3, 4]
], [
  [5, 6],
  [7, 8]
], [
  [9, 10],
  [11, 12]
]
// should be:
[
  [1, 2, 5, 6, 9, 10],
  [3, 4, 7, 8, 11, 12]
]
Denys Dovhan
@denysdovhan
Sep 01 2016 19:06
@Bradcomp thanks for transpose ;)
Denis Stoyanov
@xgrommx
Sep 01 2016 20:40
@ram-bot
const arr = [[
  [1, 2],
  [3, 4]
], [
  [5, 6],
  [7, 8]
], [
  [9, 10],
  [11, 12]
]];

reduce((acc, next) => 
       (acc[0] = concat(head(acc))(head(next)), acc[1] = concat(last(acc))(last(next)), acc), 
       [[], []], arr)
ram-bot
@ram-bot
Sep 01 2016 20:40
[] does not have a method named "concat"
Denis Stoyanov
@xgrommx
Sep 01 2016 20:40
@denysdovhan Look
@denysdovhan ugly, but works
Denys Dovhan
@denysdovhan
Sep 01 2016 20:42
@xgrommx I've already solve that problem, but thank you
Denis Stoyanov
@xgrommx
Sep 01 2016 20:51
@denysdovhan Also I realised this one reduce(zipWith(concat))(head(arr))(tail(arr))
Denys Dovhan
@denysdovhan
Sep 01 2016 21:05
@xgrommx I did that with transpose and concat in map
Denis Stoyanov
@xgrommx
Sep 01 2016 22:15
Ramda need unzip as in haskell and in lodash (for this one lodash more powerful)
_.unzipWith(arr, _.concat)