These are chat archives for ramda/ramda

14th
Sep 2016
Keith Alexander
@kwijibo
Sep 14 2016 06:29
sounds cool
Tushar Mathur
@tusharmath
Sep 14 2016 10:43
how can i make the memoize function only cache the last value
?
something like distinctUntilChanged in Rx
I can obviously implement one but is there a clever way?

export default function (func) {
  let lastArgs
  let lastResult
  return function () {
    const args = R.toString(arguments)
    if (lastArgs === args) {
      return lastResult
    }
    lastArgs = args
    lastResult = func.apply(this, arguments)
    return lastResult
  }
}
this is what I am using
Nick Luparev
@SuperManEver
Sep 14 2016 12:06
@Bradcomp thank you :)
Nick Luparev
@SuperManEver
Sep 14 2016 12:14
Hello. I try to traverse list of objects where each of them also has nested object. I want to select data that I need from them using R.prop('title') for example and I would like to make it on one pass without going twice on same list. My current implementation looks like this https://gist.github.com/SuperManEver/361cb12c99388e82312c0a7c634f789b
But I believe that there is a better way which I hope you will tell me about :)
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:17
What's your desired output @SuperManEver? It'd be easier if you used the REPL so we can tinker http://ramdajs.com/repl/
Nick Luparev
@SuperManEver
Sep 14 2016 12:18
My goal is to get back [ [ 'Debbie Downer', 'Everything Sucks' ], [ 'Caspar Milquetoast', 'If You Please' ] ]
which is name of author and title
name of author from nested object and title from level above
I posted to REPL my solution
I just think there is a better way to do this
Nick Luparev
@SuperManEver
Sep 14 2016 12:24
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:24
@SuperManEver https://goo.gl/tiI2f7
So I've got 2 functions there, titles and authorNames. There should be a way to compose the 2
Nick Luparev
@SuperManEver
Sep 14 2016 12:26
ok, I see what you're doing. It make sense :)
but it looks like you essentially traverse articles twice. On first pass you retrieve titles and second author's name
and then combine results
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:27
Yeah I'm about to use the composition rule to fix that
Nick Luparev
@SuperManEver
Sep 14 2016 12:28
hm, looking forward to see your next step
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:29
yeah my next step is to make them both maps: https://goo.gl/2psdAs
pluck effectively does the map anyway
Nick Luparev
@SuperManEver
Sep 14 2016 12:30
yes
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:30
but in order to compose the 2 functions, I think I need to make them both maps
this one is a bit different in that getTitle doesn't return the rest of the object that getAuthorName needs
so I think we'll need something a bit different
Nick Luparev
@SuperManEver
Sep 14 2016 12:31
again what you did is calling map twice, you essentially traverse list twice. What I've tried to accomplish is to make only one traverse, but each step involves more complex retrieving recipe
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:31
I do think that zip is the right approach
Nick Luparev
@SuperManEver
Sep 14 2016 12:31
ok
The first step is to map twice and then refactor
to compose the two functions together so we can map once
but this case is a bit different, as I said above
Nick Luparev
@SuperManEver
Sep 14 2016 12:33
haha, funny I in the process of reading this book too, but I on ch2
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:33
getTitle would need to return the rest of the object so that getAuthorName could read it, which doesn't make sense
Nick Luparev
@SuperManEver
Sep 14 2016 12:33
agree
take a look here again please https://goo.gl/6QUHdA
my solution works, but it's not so elegant
and I don't know how to improve it
there is think called lens
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:35
The answer is probably converge
It always seems to be :D
Nick Luparev
@SuperManEver
Sep 14 2016 12:35
hm, never heard
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:35
Yes, that's the first thing I thought of
but you're not setting any values here
Nick Luparev
@SuperManEver
Sep 14 2016 12:36
where ?
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:36
lenses are really useful when you need a hook to read a value and update it too
Nick Luparev
@SuperManEver
Sep 14 2016 12:36
oh, I see
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:36
you're only reading values in your function
Denis Stoyanov
@xgrommx
Sep 14 2016 12:37
@aaronmcadam but what about performance? JS isn't haskell
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:37
haha
Hey @xgrommx
Where did I say anything about ignoring perf? :smile:
Denis Stoyanov
@xgrommx
Sep 14 2016 12:38
@aaronmcadam in js lenses isn't good approach
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:38
I didn't recommend them
I actually said not to use them above
Syaiful Bahri
@syaiful6
Sep 14 2016 12:39
maybe like this @SuperManEver https://goo.gl/cJVDoY
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:39
but anyway, do you have any thoughts on how to solve this problem?
Nick Luparev
@SuperManEver
Sep 14 2016 12:39
I wonder, in your previous solution you've used prop and path, but you need to traverse list once for each of them. I wonder is there any way to combine prop and path into more complex recipe for retrieving things ??
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:40
Nice, I didn't know about juxt @syaiful6, but doesn't that map twice?
Nick Luparev
@SuperManEver
Sep 14 2016 12:40
@syaiful6 well, if you look carefull enough you will see that you essentially do almost the same as Aaron did but used different words
Syaiful Bahri
@syaiful6
Sep 14 2016 12:41
ah, you just need to move the map to juxt
that way, you only traverse it once
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:41
nice
Nick Luparev
@SuperManEver
Sep 14 2016 12:41
hmm, this is nice
:)
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:41
thanks :)
Nick Luparev
@SuperManEver
Sep 14 2016 12:41
thanks :)
Denis Stoyanov
@xgrommx
Sep 14 2016 12:42
@syaiful6 const juxt = fns => converge(unapply(identity), fns)
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:42
it is in a different order though, so flip around the functions @SuperManEver
Nick Luparev
@SuperManEver
Sep 14 2016 12:42
during this 15 mins talking with you guys I've learned so much. Now I go do more reading docs and do some experiments :smile:
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:42
Ah I knew converge was the answer, it always is @xgrommx :D
Nick Luparev
@SuperManEver
Sep 14 2016 12:43
:)
Denis Stoyanov
@xgrommx
Sep 14 2016 12:43
@aaronmcadam no, converge = (resultSelector, fns) => lift(resultSelector)(...fns) :smile:
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:43
ha, I did actually think of lift first of all
Denis Stoyanov
@xgrommx
Sep 14 2016 12:44
lift = map + ap
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:44
but I'm still not 100% on when to use that
or when to use ap instead of apply
Nick Luparev
@SuperManEver
Sep 14 2016 12:44
any good resources/links to read about converge/lift/juxt ??
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:45
it gets a bit lost in some places but overall it's a good overview
Denis Stoyanov
@xgrommx
Sep 14 2016 12:46
more better converge = (resultSelector, fns) => liftN(fns.length, resultSelector)(...fns)
Nick Luparev
@SuperManEver
Sep 14 2016 12:46
@aaronmcadam thank you :)
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:46
Also, try this set of exercises. The first ones are easy but try them http://reactivex.io/learnrx/
Denis Stoyanov
@xgrommx
Sep 14 2016 12:47
@SuperManEver you need know about ap, map and lift =) lift > converge > juxt
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:48
Can you recommend any good resources around lifting and stuff @xgrommx ?
Nick Luparev
@SuperManEver
Sep 14 2016 12:48
:) I already made a list of this things that I need to learn :)
Denis Stoyanov
@xgrommx
Sep 14 2016 12:48
@aaronmcadam yes) haskell
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:48
There needs to be an awesome github repo for FP
I was just about to say "not haskell" :D
:smile:
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:49
Ha!
Thanks, this looks awesomeeeee
Denis Stoyanov
@xgrommx
Sep 14 2016 12:51
converge powerful operator. But I think we need decrease size of ramda and use only lift and liftN
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:51
Ramda is pretty massive, is there any sign of a 1.0?
Denis Stoyanov
@xgrommx
Sep 14 2016 12:51
converge = curry((resultSelector, fns) => liftN(fns.length, resultSelector)(...fns))
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:52
22 minor versions is a quite a lot :D
Denis Stoyanov
@xgrommx
Sep 14 2016 12:53
juxt = fns => liftN(fns.length, unapply(identity))(...fns)
Nick Luparev
@SuperManEver
Sep 14 2016 12:55
@xgrommx awesome-func-prog list is really awesome. So much great stuff there :) Thank you
Denis Stoyanov
@xgrommx
Sep 14 2016 12:55
also interesting sequence + reduce
Aaron Mc Adam
@aaronmcadam
Sep 14 2016 12:56
@SuperManEver Maybe you should list your learning resources somewhere
Nick Luparev
@SuperManEver
Sep 14 2016 12:57
@aaronmcadam I just use ramda documentation and this book. Also I have some experience with Haskell, not much, but I got something from it
I just do step by step learning. For example I stumble on concept of curry and partially applied function and did some research what they are and what they used for.
Denis Stoyanov
@xgrommx
Sep 14 2016 12:59
@SuperManEver oh! that all what you need map(sequence(always, [prop('title'), path(['author', 'name'])]))(articles)
Nick Luparev
@SuperManEver
Sep 14 2016 12:59
holy shit, one more week of research :)
Denis Stoyanov
@xgrommx
Sep 14 2016 13:00
It's traversing
when you have m t a -> t m a
just swap containers
Nick Luparev
@SuperManEver
Sep 14 2016 13:01
can't say that I got it :) Where this idea came from ? Haskell ? May be you have some links where I can read more about it ??
@SuperManEver also this book http://learnyouahaskell.com/chapters
Nick Luparev
@SuperManEver
Sep 14 2016 13:03
thank you :)
oh, I'm reading this book. At what chapter is it ?
Denis Stoyanov
@xgrommx
Sep 14 2016 13:04
@SuperManEver Applicative, Monoids...
Nick Luparev
@SuperManEver
Sep 14 2016 13:04
ok, haven't reached yet
ok, I going to do some study :) See you
Syaiful Bahri
@syaiful6
Sep 14 2016 13:06
that nice, @xgrommx
Rick Medina
@rickmed
Sep 14 2016 15:05
why are lenses poor performers in js? what is the alternative?
Ryan Zeigler
@rzeigler
Sep 14 2016 15:28
I wasn't aware they were. It's likely just the level of function calls involved
I think you get at least 2 since there is a functor involved against the entire object. Even for views.
Jethro Larson
@jethrolarson
Sep 14 2016 16:07
Rather than composeK, what about composeChain?