These are chat archives for ramda/ramda

19th
Jul 2017
Tomáš Konrády
@tommmyy
Jul 19 2017 10:52
Hello,
is it possible to make code bellow point-free?
``const containsAll = R.curry((xs, ys) => R.compose(R.isEmpty, R.difference)(xs, ys))``
Pygmalion
@PygmalionPolymorph
Jul 19 2017 11:17
I think you can just use `const containsAll = R.compose(R.isEmpty, R.difference);`
Tomáš Konrády
@tommmyy
Jul 19 2017 12:16
@murmox yes, but you can't use currying then...
``````containsAll(xs, ys) // ok
containsAll(xs)(ys) // error``````
Pygmalion
@PygmalionPolymorph
Jul 19 2017 12:28
Would this not work?
``const containsAll = R.curry(R.compose(R.isEmpty, R.difference))``
Tomáš Konrády
@tommmyy
Jul 19 2017 12:30
@murmox yes it works :) thanks
Pygmalion
@PygmalionPolymorph
Jul 19 2017 12:30
@tommmyy No problem :)
Denis Stoyanov
@xgrommx
Jul 19 2017 13:08
polyPascal :smile:
``````const polyPlus = (xs, ys) => {
if(xs.length === 0) return ys
else if(ys.length === 0) return xs

const [f, ...fs] = xs
const [g, ...gs] = ys

return [f+g, ...polyPlus(fs, gs)]
}

const polyMult = (xs, ys) => {
if(xs.length && ys.length) {
const [f, ...fs] = xs
const [g, ...gs] = ys

return [f*g, ...polyPlus(polyMult([f], gs), polyMult(fs, ys))]
}
return []
}

const polyExp = (xs, n) => Array.from({length: n}, () => xs).reduce(polyMult, [1, 1])

const polyPascal = compose(map(n => polyExp([1,1], n)), range(0))

polyPascal(4)``````
Ben52
@Ben52
Jul 19 2017 19:47
What function would I use thats comparable to Elm's mapN functions? http://package.elm-lang.org/packages/elm-lang/core/5.1.1/List#map2
Gabe Johnson
@gabejohnson
Jul 19 2017 19:51
Ben52
@Ben52
Jul 19 2017 19:52
Oh wow! I couldn’t wrap my head around lift, is that all it is?
just combines Lists using a function?
Gabe Johnson
@gabejohnson
Jul 19 2017 19:53
Well in the case of Array/List yes
Ben52
@Ben52
Jul 19 2017 19:53
cool thanks
What other cases are there?
Gabe Johnson
@gabejohnson
Jul 19 2017 19:53
Wait. Maybe it's not the same
`map2` works pair-wise
Gabe Johnson
@gabejohnson
Jul 19 2017 20:00
@Ben52 I was wrong. I'm not sure what the answer is
Ben52
@Ben52
Jul 19 2017 20:01
Still can’t grok `lift`
Gabe Johnson
@gabejohnson
Jul 19 2017 20:07
@Ben52 my bad. `lift` works like `map{n}` for other `Apply`s. Not for `List`/`Array` though
Like `Maybe` or `Result`
Ben52
@Ben52
Jul 19 2017 20:08
forgive me for asking, but how do I create a Maybe or Result in JS?
Gabe Johnson
@gabejohnson
Jul 19 2017 20:09
You'd need a lib that has them
But I don't think it's actively developed