These are chat archives for ramda/ramda

8th
Jun 2016
Tom
@tarossi
Jun 08 2016 01:45
hey guys! is there any way of composing lenses with ramda?
Tom
@tarossi
Jun 08 2016 01:52
nevermind... just found out you can use compose
James Forbes
@JAForbes
Jun 08 2016 03:20

@paldepind I wasn't aware, but I think you're right.
I think it would be a minor change to internal/dispatchable to

https://github.com/ramda/ramda/blob/master/src/internal/_dispatchable.js

//dispatch to fl.map if on the obj, otherwise obj.map
var f = obj[fl[methodname]] || obj[methodname]

But in practice ramda supports libraries that support fantasy land because they all expose map, of, ap etc. I think it is more likely lodash would dispatch to obj[fl.map] than obj.map due to concerns of suprising dispatches.

James Forbes
@JAForbes
Jun 08 2016 04:08
Can anyone Ramda contributors correct me?
Simon Friis Vindum
@paldepind
Jun 08 2016 06:03

But in practice ramda supports libraries that support fantasy land because they all expose map, of, ap etc.

Yes. But only because most libraries haven't been updated to the latest fantasy land spec either. Sadly, I don't think the fantasy land spec ever realized it's potential. I've seen a bunch of libraries that implement the spec but very little that actually use the abstractions.

Chet Harrison
@ChetHarrison
Jun 08 2016 06:06
@paldepind I am trying to lead a few people down the FL path what do you recommend?
Simon Friis Vindum
@paldepind
Jun 08 2016 06:15
@ChetHarrison As in why they should implement FL, use it, or care about it in general?
Baqer Mamouri
@bmamouri
Jun 08 2016 06:46

Hey guys,

With R.path is it possible to target all nodes in the array? I can do R.path([‘schools’, ‘0’, ‘id’]) to get the id of the first school. What I like to do is to get all ids. Something like this: R.path([‘schools’, ‘*’, ‘id’]). Is this possible?

Scott Christopher
@scott-christopher
Jun 08 2016 06:47
@bmamouri Not using path directly.
Baqer Mamouri
@bmamouri
Jun 08 2016 06:48
Should I use R.map to go through the array and then use R.path? @scott-christopher
Scott Christopher
@scott-christopher
Jun 08 2016 06:48
You could however do something like
R.pipe(R.prop('schools'), R.pluck('id'))
Where R.pluck('id') is effectively R.map(R.prop('id'))
Baqer Mamouri
@bmamouri
Jun 08 2016 06:52
Excellent @scott-christopher Thank you very much!
Scott Christopher
@scott-christopher
Jun 08 2016 06:53
You're welcome :)
Slađan Ristić
@sladiri
Jun 08 2016 07:37
Hi, can I get a function from useWith() which does not need parameters, apart from creating a wrapper function which calls it with parameters? I'd like to use functions with side effects, I guess.
R.useWith(Math.pow, [() => 2, () => 3])(null, null);
Scott Christopher
@scott-christopher
Jun 08 2016 09:34
@sladiri If I understand correctly, you could use R.converge.
@ram-bot
const fn = R.converge(Math.pow, [() => 2, () => 3])
fn()
ram-bot
@ram-bot
Jun 08 2016 09:34
8
Slađan Ristić
@sladiri
Jun 08 2016 09:36
@scott-christopher Thank you for the hint, very nice. :)
Denis Stoyanov
@xgrommx
Jun 08 2016 09:41
@ram-bot
const fn = R.converge(Math.pow, [R.always(2), R.always(3)])
fn()
ram-bot
@ram-bot
Jun 08 2016 09:41
8
Denis Stoyanov
@xgrommx
Jun 08 2016 09:42
@ram-bot
const fn = R.converge(Math.pow, R.map(R.always, [2,3]))
fn()
ram-bot
@ram-bot
Jun 08 2016 09:42
8
James Forbes
@JAForbes
Jun 08 2016 10:49
@paldepind do you mean the (given) library code is not making use of Fantasy Land?
Aditya Bhardwaj
@purezen
Jun 08 2016 11:27
Hi, I am making an app in Reactjs and want to call getIn method on Immutable maps with the path supplied dynamically.
How would I achieve this using Ramda? Thanks!
Basically doimmutableMap.getIn(path) with the path supplied dynamically
Baqer Mamouri
@bmamouri
Jun 08 2016 12:09
This message was deleted
Hey guys, in groupBy function, how can I group data based on Index. For example given [a, b, c, d, e, f, g] I would like to get [a, b], [c, d], [e, f], [g]. Is this possible?
James Forbes
@JAForbes
Jun 08 2016 12:13
@bmamouri is something like this what you are after? http://ramdajs.com/docs/#aperture
Raine Virta
@raine
Jun 08 2016 12:13
@bmamouri original question was better
James Forbes
@JAForbes
Jun 08 2016 12:13
ah sorry I missed it
Baqer Mamouri
@bmamouri
Jun 08 2016 12:14
Exactly @JAForbes Thanks a lot. You are right @raine I deleted it because I thought I found the answer, but then I realized I was mistaking.
James Forbes
@JAForbes
Jun 08 2016 12:14
awesome
Baqer Mamouri
@bmamouri
Jun 08 2016 12:44
This message was deleted
Hey @JAForbes and @raine I just realized that aperture won’t solve my problem. It gives you: [[1, 2], [2, 3], [3, 4], [4, 5]] but I am looking for [1, 2], [3, 4], [5]. So just basically a function that split items into equal chunks.
Slađan Ristić
@sladiri
Jun 08 2016 12:47
@xgrommx Thank you for the examples.
Baqer Mamouri
@bmamouri
Jun 08 2016 12:48
I found it @JAForbes and @raine. It called it splitEvery
James Forbes
@JAForbes
Jun 08 2016 12:49
@bmamouri never seen that one! :)
Baqer Mamouri
@bmamouri
Jun 08 2016 12:50
@JAForbes It is a new function and it was in a lot of demand: ramda/ramda#774
Chet Harrison
@ChetHarrison
Jun 08 2016 15:45
@paldepind why they should care in general
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 17:18
what is the easiest way to remove all null properties from an object tree?
LeonineKing1199
@LeonineKing1199
Jun 08 2016 17:35
An object tree? Do you mean an object? A tree-like data structure?
There's also filter which might do what I think you want to do
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 18:13
@LeonineKing1199 nested map
is that clearer? :)
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:13
Would you hate me if I said no? XD
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 18:13
not at all
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:14
Do you have input/output?
That's usually clearer.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 18:14
look, it is a javascript object that might have values that are also js objects, and so on and so on
and i want to remove nulls and undefineds
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:14
Recursively from each object...
I see...
Well, you could just code up a recursive application of filter
But then you'll hit the dreaded STACK OVERFLOW!!!
Does Ramda actually have any object traversal methods? It'd be amazing if there was a Ramda function where you'd pass it an object and a function and it would apply that function recursively to each prop and return the results.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 18:17
:))
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:18
Shoot, I kind of wanna make that myself...
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 18:18
there are no recursive functions in ramda afaik
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:18
Yeah, that's because of implementation details and we should never ever use recursion in a language that still has stack overflows.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 18:18
it works but the API is a mess :D
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:18
We need the iterative solution!
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 18:19
how
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:19
You can make all recursive algorithms iterative.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 18:25
i know that as "trivia"
i mean, i can write it with mutations
and i feel like it is ugly
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:26
Well, iterative object traversal would certainly involve R.keys so you're aware of all the props
Maybe you store two aligned arrays of keys and values, this way you can zip them if need be.
Arrays are great because you can hook them together in any which way.
This is just spit-balling.
Brad Compton (he/him)
@Bradcomp
Jun 08 2016 18:32
@ashnur First attempt http://goo.gl/WoDXg8
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 18:37
oh, that looks neat, is it particularly slow though?
Brad Compton (he/him)
@Bradcomp
Jun 08 2016 18:37
Dunno, haven't profiled it ;)
It would be easy to parameterize the filtering function of course. Not sure if I would use it on massive objects, I haven't looked at the implementation details of map and filter for objects
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:43

Shifting frame pointers is, like, the most expensive thing in all of computing :laughing:

Real talk though, if you look at some of the Cry Engine code, they purposefully eschew separating their code into functions because the devs were scared of the frame pointer boogeyman.

So no, I doubt it's slow
LeonineKing1199
@LeonineKing1199
Jun 08 2016 18:49
This is defs one of those cases where you'd annotate the codebase with "This could've been one line in Haskell" because they actually have real tail recursion.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 19:00
@LeonineKing1199 where is that code? :)
also, terrible smiley choice for : )
LeonineKing1199
@LeonineKing1199
Jun 08 2016 19:00
You mean the one line of Haskell?
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 19:01
@LeonineKing1199 no, the Cry Engine code
LeonineKing1199
@LeonineKing1199
Jun 08 2016 19:01
Oh, yeah, let me go get dig that up.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 19:01
i have a friend who asked something for which what you said if it is true would be a great answer
The whole codebase is full of dense blocks like that.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 19:46
sigh that is way worse than what i was hoping for
LeonineKing1199
@LeonineKing1199
Jun 08 2016 19:53
The funniest part is, I bet that writing dense codeblocks like that actually impairs the compiler's ability to optimize code.
Write small, composable functions and be amazed at how the compiler can optimize your instructions and choose when to inline them properly.
Also, aliasing rules can be a huge performance benefit which I don't see there.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 19:54
yeah
i am so sick of hearing
"game design is different"
i don't buy any of that. I think they subscribed to something where they actually try to deliver on time, so what they write is shit, because there is no way otherwise to keep deadlines
although I might be wrong about the last part, but so far it seems good code correlates with more flexible time constraints
LeonineKing1199
@LeonineKing1199
Jun 08 2016 19:57
Of course. It actually allows time for profiling.
The biggest boons will always be: no branches, cache coherence
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 19:58
also, it is so fun, you gave me that code @Bradcomp , and instead of null I also had to filter for empty too. and i wasn't even thinking, just either(isNil, isEmpty), and it works
Brad Compton (he/him)
@Bradcomp
Jun 08 2016 19:58
nice!
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 19:59
thanks!
i worked on a lot of frontend edge cases in the past few years @LeonineKing1199 , and I can tell you that there was never ever a performance problem unless it was 1. shit code, most of the time it is just shit code 2. too much data 3. P = NP hard problems
the problem btw with the optimizations is that if your function is not called often enough it will never ever ever be optimized
which is something people tend to forget
like sure, there are some trivial replacements, but not much else
http://mrale.ph/irhydra/2/ I was using this to optimize my bigint experiment :D
you can actually see what is happening, it's so awsome. and mr. aleph is the funniest and nicest v8 contributor I ever talked to
LeonineKing1199
@LeonineKing1199
Jun 08 2016 20:04
That's pretty cool
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 20:05
so I am actually trying to find ramda idioms to stuff like this just to see if I ever run into some performance problems on normal everyday stuff
LeonineKing1199
@LeonineKing1199
Jun 08 2016 20:08
Honestly, I think Node is fast enough that you'll never have to worry.
Node already offloads your filesystem calls to a background threadpool and I think the HTTP stuff doesn't use threads explicitly but it is offloaded to the background so the thread that's running the event loop can usually be kept busy enough with your actual JavaScript.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 20:09
actually, BIGINTS ARE SLOW :(
LeonineKing1199
@LeonineKing1199
Jun 08 2016 20:09
Yeah, 'cause you're doing compute-intensive stuff.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 20:09
like really slow. because we don't have typed structs
LeonineKing1199
@LeonineKing1199
Jun 08 2016 20:09
Might wanna just shift languages.
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 20:10
no, you misunderstand, if I want to write for the web
Brad Compton (he/him)
@Bradcomp
Jun 08 2016 20:10
But if you want bigints in the browser you don't really have a choice :(
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 20:10
it will run in js...
maybe with webassembly :D
or ES8 :(
LeonineKing1199
@LeonineKing1199
Jun 08 2016 20:10
Mozilla is working on SIMD in JS
That'd prolly help your bigint stuff
GÁBOR Áron Zsolt
@ashnur
Jun 08 2016 20:11
and I was hoping that they would ship it in ES6, then ES7, then ES8... it will never happen. but we have a class keyword now...
unless it happens in all browsers
like 99%
There are many ways to achieve it, but the easiest and most straightforward way would be what some of the TC39 committee members were proposing, but then it got delayed and whatnot, https://github.com/dslomov/typed-objects-es7
the API is terrible as always, but I think it is enough
Chet Harrison
@ChetHarrison
Jun 08 2016 20:20
@dypsilon heads up, I got an early release of that book I recommended and in chapter 5 I'm seeing a ton of errors in the code like Maybe is missing a chain method. I think they just released and updated version so they may have cleaned it up.