These are chat archives for ramda/ramda

25th
Sep 2017
James Forbes
@JAForbes
Sep 25 2017 01:20
np :thumbsup: I don't think I pushed for anything :D @barneycarroll
arian‮
@arian-swydo
Sep 25 2017 12:07
Is there a better way to do the following: fn => compose(apply(fn), concat([]), flatten, of)
basically, I don't care if an array is returned or not, I convert it to an array and apply that array to the next fn
Kurt Milam
@kurtmilam
Sep 25 2017 12:07
of may be useful here.
arian‮
@arian-swydo
Sep 25 2017 12:11
ah wait concat is useless here
@kurtmilam how would you name such a function?
Kurt Milam
@kurtmilam
Sep 25 2017 12:12
I probably wouldn't name it :)
I'd probably try to figure out whether it makes sense to have a function that works on variable input types like that.
arian‮
@arian-swydo
Sep 25 2017 12:13
haha, well, I have a lot of these, and I keep prefixing them with lazy, but they're really not lazy, I guess more like "forgiving"
Kurt Milam
@kurtmilam
Sep 25 2017 12:16
Can you figure out a way to move the of outside of the function so the function always gets an array?
arian‮
@arian-swydo
Sep 25 2017 12:48

yeah, I removed it all together, was a terrible idea as you suggested, it's a little bit more specific now

compose(
    apply(onSetActive),
    converge(
        unapply(identity),
        [identity, isNotNil]
    )
),

passes true or false as second array element, depending on if first is nil

still makes very little sense, or god knows how to name it
but I'm trying :)
Kurt Milam
@kurtmilam
Sep 25 2017 13:04
@arian-swydo Try ap( onSetActive, isNotNil )
Kurt Milam
@kurtmilam
Sep 25 2017 13:09
@arian-swydo To untangle the knot in steps, I believe this does what your current function does:
converge(
    onSetActive,
    [identity, isNotNil]
)
And I believe that can be further simplified to ap( onSetActive, isNotNil ).
I haven't tested though, and I'm going off of memory a bit, so let me know if that doesn't work.
arian‮
@arian-swydo
Sep 25 2017 13:22
Thanks, that's what I keep doing wrong, not seeing the simple structures
Kurt Milam
@kurtmilam
Sep 25 2017 13:23
It can take a while to learn the API well enough to know what to employ where.
I've been using it for a while, and I'm still learning things.
Casey Link
@Ramblurr
Sep 25 2017 14:31
anyone used ramda with google closure compiler ADVANCED optimizations to remove dead code?
Joey Figaro
@joeyfigaro
Sep 25 2017 16:44
Hey all. If I have an array of strings from an app’s request logs where each string looks like 2017-07-25 11:43 -04:00: POST /api/x/y 500 56 - 455.112 ms how can I group them by status code (500 in this case)?
Casey Link
@Ramblurr
Sep 25 2017 16:57
Given the object with an array of sub-objs as a prop, is there a way to get a lens on a prop in the sub obj?
{ fruit: [
    { id: 1, name: "apple" },
    { id: 2, name: "cherry" },
  ]
}
i.e., is there a way to get a lens that will operate on all 'names'? when the parent object is passed to vew/set/over?
something like R.lensPath(['fruit', *, 'name']);
Kurt Milam
@kurtmilam
Sep 25 2017 17:00
@joeyfigaro REPL
o( groupBy( nth( 5 ) ) )
 ( map( split( ' ' ) ) )
 ( data )
Casey Link
@Ramblurr
Sep 25 2017 17:08
Ah the REPL, good idea... here's a repl of my question
Joey Figaro
@joeyfigaro
Sep 25 2017 17:16
@kurtmilam thanks Kurt - what if I wanted to strip the arrays that get attached to each key so that they only include the endpoint, date, and method?
Kurt Milam
@kurtmilam
Sep 25 2017 17:28
@joeyfigaro there may be a more concise way, but this should work.
Wait, that doesn't quite work because it removes the status code prior to trying to groupBy.
this should do the trick, but it leaves the status code in each of the grouped arrays.
Kurt Milam
@kurtmilam
Sep 25 2017 17:47
@Ramblurr I'm not sure that's possible with Ramda's lenses in a straightforward way, but it's easy with partial.lenses. See here.
Joey Figaro
@joeyfigaro
Sep 25 2017 17:50
@kurtmilam That is some voodoo you’ve got there - o makes my head spin a bit. Many thanks, bud. :)
Casey Link
@Ramblurr
Sep 25 2017 17:51
@kurtmilam oh interesting, i haven't encountered partial.lenses before
Kurt Milam
@kurtmilam
Sep 25 2017 17:52
@joeyfigaro o is similar to compose, but it only accepts 2 functions and the resulting function isn't curried. It's also pretty new. Works more like compose usually works in most 'real' functional languages.
@Ramblurr It's awesome. You can ask questions about partial.lenses on the Calmm-js Gitter.
Casey Link
@Ramblurr
Sep 25 2017 17:54
do you replace ramda with it?
or rather, would you use both ramda and partial.lenses in one project?
Kurt Milam
@kurtmilam
Sep 25 2017 18:27
I use both together. They complement each other well.
Florian Schrödl
@floscr
Sep 25 2017 18:29
I'm baffled, should this console.log output be ('c')?
const test = curry(
  (a, b, c) => pipe(
    args => { console.log(args) }
  )(a, b)
)
const testComposed = test('a', 'b')

testComposed('c')
Right now the output is 'a'
But should be the passed in arg be the last one applied to the pipe?
Kurt Milam
@kurtmilam
Sep 25 2017 18:34
Whether or not you curry, the first argument will be passed to pipe first.
Florian Schrödl
@floscr
Sep 25 2017 18:35
ah ok, I just read that, is there any pipe-like method that takes the last argument?
Anyway, I did not know that, the last argument just seemed a lot more logical considering how map, filter, reduce etc do it
Kurt Milam
@kurtmilam
Sep 25 2017 18:37
What would you expect to happen to the first arguments?
Florian Schrödl
@floscr
Sep 25 2017 18:40
they would be in scope for the pipe
const test = curry(
  (a, b, c) => pipe(
    letter => { console.log(a + b + letter) }
  )(a, b)
)
const testComposed = test('a', 'b')

testComposed('c') // -> wanted result -> 'abc'
Kurt Milam
@kurtmilam
Sep 25 2017 18:42
I usually use a replacement for pipe, apply ( pipe ), which is called first with an array of functions, then with the data.
I just read your example. Just change the fn definition to this, and everything will be in scope:
const test = curry( (a, b, c) => pipe( letter => { console.log(a + b + letter) } )(c) )
Kurt Milam
@kurtmilam
Sep 25 2017 18:48
Sorry, on a mobile. Now c will be passed into pipe, buta and b will both be in scope due to the closure.
Florian Schrödl
@floscr
Sep 25 2017 18:50
Aaah, yes, thanks, thats what I've been missing :)
Kurt Milam
@kurtmilam
Sep 25 2017 18:50
:+1:
Konstantin Kostiuk
@SET001
Sep 25 2017 19:31
what is the ramda way for something like this return foo(args[0])(args[1])(args[2])?
Kurt Milam
@kurtmilam
Sep 25 2017 19:34
@SET001 not sure I follow.
Maybe you could give a more complete example of what you're trying to accomplish.
Konstantin Kostiuk
@SET001
Sep 25 2017 19:37
@kurtmilam I want a function which will call constructor with variable number of parameters
I'm using R.reduce here, but now I'm wondering, can I shorten const blah = (a, b) => a = a(b) with some ramda function?
Kurt Milam
@kurtmilam
Sep 25 2017 19:42
Well, you should be able to shorten blah to const blah = (a, b) => a(b).
Which I'd do so you're not mutating.
So, you can replace your blah with Ramda's call.
Kurt Milam
@kurtmilam
Sep 25 2017 19:47
Since call essentially equals curry((a, b) => a(b))
Konstantin Kostiuk
@SET001
Sep 25 2017 19:48
cool, so I end up with something like this https://tinyurl.com/ycjygneq
Kurt Milam
@kurtmilam
Sep 25 2017 19:51
Yep. I can't think of a replacement for reduce there, though. I usually use my own pipe, which I define like this, which is essentially the same thing:
export const pipe =
  fns => data => fns.reduce( R.call, data )
Kurt Milam
@kurtmilam
Sep 25 2017 19:57
Actually, that's slightly different, but I've done something similar to what you're trying, and I also used reduce.
Konstantin Kostiuk
@SET001
Sep 25 2017 19:58
yeah, seems like reduce is the best choice here
Kurt Milam
@kurtmilam
Sep 25 2017 20:16
I was actually wrong about my pipe. This is correct:
const pipeReducer = ( acc, fn ) => fn( acc )
export const pipe =
  fns => data =>
    fns.reduce( pipeReducer, data )
Denis Stoyanov
@xgrommx
Sep 25 2017 20:42
unapply(foo)?
@SET001 ^
Denis Stoyanov
@xgrommx
Sep 25 2017 20:53
more better @SET001
const creator_ = name => (...args) => curryN(args.length, construct(name))(...args)

creator_(Blah)('bob', 12, 'male')
Alex G Rice
@guidorice
Sep 25 2017 21:57
Hi all, I was debugging one of my unit tests, and it looks like innerJoin() might work differently in nodejs than in browser? Has anyone ever heard of that? I did a quick search of the github issues, but didn't see anything.