These are chat archives for ramda/ramda

11th
Dec 2018
Макс Грязнов
@lkdnvc
Dec 11 2018 09:13
Hi!
Screenshot 2018-12-11 at 12.13.29.png
this is normal code? o use Ramda better?
Alexander Lichter
@manniL
Dec 11 2018 09:14
o => o.selected could be R.prop('selected') I guess.
and I'd suggest using R.pipe or R.compose instead of data => ...(data)
Макс Грязнов
@lkdnvc
Dec 11 2018 09:18
Thank you very much :)
Alexander Lichter
@manniL
Dec 11 2018 09:18
No problem :relaxed:
Alexander Lichter
@manniL
Dec 11 2018 11:19

@manniL I'm not sure if it's better (it's probably not as easy to grok) but I had a go at your earlier question:

const isShiftAction = propEq('shift', true);
const isNotShiftAction = complement(isShiftAction);

const appendTo = flip(append)

const willBeUsedAsReduceFunction = shifts =>
  ifElse(
    both(
      compose(isShiftAction, head),
      compose(isNotShiftAction, last)
    ),
    compose(appendTo(shifts), head),
    always(shifts)
  )

willBeUsedAsReduceFunction([])([{ shift: true }, {}])

@ben-eb Just tried out your proposal :relaxed:

But the arity of the reduceFunction doesn't fit (it seems)
console.log(reduce(willBeUsedAsReduceFunction, [], [{shift: true}, {}])) returns a function
Макс Грязнов
@lkdnvc
Dec 11 2018 11:40
Screenshot 2018-12-11 at 14.36.14.png
I can return the value property?
Alexander Lichter
@manniL
Dec 11 2018 11:41
is getActive(types) an object?
(with the value prop)
Rakesh Pai
@rakeshpai
Dec 11 2018 11:45
const get = pipe(find(prop('selected')), prop('value'));

this.setState({
  types: get(types),
  addresses: get(addresses),
  ...
})
Of course, get is a terrible function name, so change that to suit your app. Also, there's no error handling, in case the results of find is undefined.
Макс Грязнов
@lkdnvc
Dec 11 2018 11:51
🤠 EEEha!
Rakesh Pai
@rakeshpai
Dec 11 2018 11:54
With Advent of Code, I'm increasingly going pure JS without ramda, just for the perf benefits. Ramda is slooow! For example, over here, code with ramda took over a minute and a half, while the pure JS version took about 2 seconds to execute.
I think the culprit is all the .reduce calls that happen behind the scenes with every composed (pipe/compose) function's invocation.
Rakesh Pai
@rakeshpai
Dec 11 2018 12:07
I wonder if there's any way, maybe using a build tool, to figure out what the code is supposed to do, and rewrite it to be more optimised. After all, with Ramda or FP in general, we're declaring intent and flows, not actually writing imperative code, so it should be possible to have tooling to understand that intent, and then optimize for performance/size.
Alexander Lichter
@manniL
Dec 11 2018 12:10
That's hard with JS I guess
Rakesh Pai
@rakeshpai
Dec 11 2018 12:15
Facebook has been working on a thing called Prepack https://prepack.io/ which seems closest to what I'm talking about. But I'm not sure how far along it is. My guess is, it should really help code written in Ramda, or functional code in general.
Alexander Lichter
@manniL
Dec 11 2018 13:40
Well, it'll "just" pre-compile stuff. So it'll still take the same time
Scott Sauyet
@CrossEye
Dec 11 2018 13:54
@rakeshpai: I've been using a mix of Ramda and vanilla JS all along. But a linked list like that is inherently stateful, and Ramda is certain to be non-optimized in an extremely stateful system.
Rocky Madden
@rockymadden
Dec 11 2018 14:18
Have you guys seen (unsure if it fits this use case, but worth mentioning): https://github.com/funkia/list
Scott Sauyet
@CrossEye
Dec 11 2018 14:54
I'm not sure what use-case you're talking about, but list is great. It was created by @paldepind, a Ramda core team member and contributor to FantasyLand, as well as the creator of Flyd.
I've been using it a bit in my own projects, although I haven't yet introduced it at work.
Rakesh Pai
@rakeshpai
Dec 11 2018 15:11
Thanks, @manniL and @CrossEye. It doesn't look like Prepack is doing what I thought it does. I'd have expected this entire program to be 'down-converted' into one console.log line.
(That code is from a talk I'm giving soon at a local meetup here. The talk is a live-coding thing, giving the audience a gentle introduction to Functors and Monads. Any feedback about the code is welcome!)
Ben Briggs
@ben-eb
Dec 11 2018 15:31
@manniL You can use uncurryN to remove the manual currying there - so uncurryN(2, willBeUsedAsReduce)
Alexander Lichter
@manniL
Dec 11 2018 15:35
@ben-eb Oh, nice! Thank you :relaxed:
Ben Briggs
@ben-eb
Dec 11 2018 15:35
:+1:
Scott Sauyet
@CrossEye
Dec 11 2018 18:13

@rakeshpai: Note that in that code, your Maybe is not entirely fantasy-land compatible.

1.i No parts of a should be checked

-- Applicative's of method.

This is because it wants to allow Just(null) as a legitimate value.