These are chat archives for ramda/ramda

21st
Mar 2016
Risto Stevcev
@Risto-Stevcev
Mar 21 2016 01:07
@GrosSacASac Your code is doing several expensive DOM manipulations. It's not much different than a solution using template strings alone. In Angular or React that would be <20 loc and wouldn't have manual manipulations.
Scott Sauyet
@CrossEye
Mar 21 2016 01:17
@6ewis: You can run those slides by downloading the repo and opening index.html in a browser, or see them online at http://scott.sauyet.com/Javascript/Talk/FunctionalProgramming/. Warning, though: it's a fairly old talk at this point, and I haven't tried to keep it up-to-date.
Walle Cyril
@GrosSacASac
Mar 21 2016 02:03
What do you call expensive DOM manipulation ? At some point, in a chat client you have to use appendChild or similar, you have to use .textContent = or similar, etc. There are 4 reasons it seems to take a lot of code. 1 I simulate 2 conversations comming from the server. 2 There are alot of comments explaining step by steps what we are doing. Notice I didn't use some macros either. 3 In angular and react you have hidden logic in the markup, I used them before. 4 I reuse DOM nodes after 10 messages , instead of creating new ones and removing the oldest ones(could have done that too, there is not only 1 way to do it)
Walle Cyril
@GrosSacASac
Mar 21 2016 02:11
@Risto-Stevcev I don't know if you read the source code, I wrote a comment about me considering generating automatic scope names internally but yeah you are right, it for now requires some manual manipulations. The reason I am still considering it , is because that would reduce the freedom to generate Nodes with template that do share stuff.
I am starting a new project with BabylonJS, does anyone use it on a daily basis in here ?
Walle Cyril
@GrosSacASac
Mar 21 2016 02:17
@Risto-Stevcev Thanks alot for your feedback, I will think about it
Risto Stevcev
@Risto-Stevcev
Mar 21 2016 02:55
@GrosSacASac I could always be wrong. Though I think you should perform some trivial and non-trivial benchmarks with competing libs like Angular or React and post it on your README if your implementation is faster. It would definitely be a selling point if you're lib is faster, requires no virtual dom, and is very simple and easy to learn.
You can also just do this to rotate your array to save space: messageScopes.push(messageScopes.shift())
Risto Stevcev
@Risto-Stevcev
Mar 21 2016 03:01
With a little tweaking it probably could be faster than those. Libs get outdated and outcompeted every few months/years.
Walle Cyril
@GrosSacASac
Mar 21 2016 13:11
What would be a good benchmark ? I never made benchmarks before.
LeonineKing1199
@LeonineKing1199
Mar 21 2016 15:32
At least 100,000+ ops/second
Walle Cyril
@GrosSacASac
Mar 21 2016 16:17
I mean, what would be a good operation to test ?
so what is ops in "100,000+ ops/second" ?
LeonineKing1199
@LeonineKing1199
Mar 21 2016 16:39
Operations
Similar to how people will benchmark in FLOPS
Like, GPUs have some crazy amount of FLOPS
Walle Cyril
@GrosSacASac
Mar 21 2016 16:51
what is a good operation to use in benchmark for UI frameworks ?
Keith Alexander
@kwijibo
Mar 21 2016 17:31
there are lots out there, but you should probably pick/make one derived from the usecase you created it for - web forms? chat apps? svg animations?
Walle Cyril
@GrosSacASac
Mar 21 2016 17:35
it takes too much time to do that
Risto Stevcev
@Risto-Stevcev
Mar 21 2016 17:58
That's how it's done though
Adding to what was said, you could use performance.now along with Mutation Events such as DOMSubtreeModified to check if the rendered subtree has fully rendered.
Then write something most people might use your library for, like your chat example, in competing libs, and compare the speed of your lib rendering the DOM subtree vs theirs
Risto Stevcev
@Risto-Stevcev
Mar 21 2016 18:03
And maybe on the same page, separated by divs such as <div id="dom99">...</div><div id="react">...</div> etc
So you can publish your benchmark in a way that others can run easily and quickly too
Walle Cyril
@GrosSacASac
Mar 21 2016 18:31
I don't have time for that right now
LeonineKing1199
@LeonineKing1199
Mar 21 2016 18:33
Wow...
You're, like, a total bummer, man
Keith Alexander
@kwijibo
Mar 21 2016 18:34
lol
Julien Goux
@jgoux
Mar 21 2016 19:23
Hello
How would you translate the Elm Architecture update :: Model -> Action -> [Model, Effects] using ramda-fantasy's monads ?
If I assume Effects could be synchronous or asynchronous, how would you represent them ?
Future[IO] ?
and there is a chance the update function returns no effects, so it would be a Maybe
Help from FP guru much appreciated :D
Matthias Seemann
@semmel
Mar 21 2016 19:37

Is this the right way to implement a pick which just returns the values?

// {k:v} -> [string] -> [v]
pickValues = R.compose( R.juxt, R.map( R.compose(R.partial(R.prop), R.of) ) );

Example use:

pickXYPlane = pickValues(['x', 'y']);
pickXYPlane({x: 1, y: 2, z: 3})   // ===> [1, 2]

Or is there a simpler way?

Julien Goux
@jgoux
Mar 21 2016 19:38
@semmel R.pipe(R.pickAll, R.values) ?
Brad Compton (he/him)
@Bradcomp
Mar 21 2016 19:39
@ram-bot
R.pick(['x', 'y'])({x: 1, y: 2, z: 3})
ram-bot
@ram-bot
Mar 21 2016 19:39
{ x: 1, y: 2 }
Brad Compton (he/him)
@Bradcomp
Mar 21 2016 19:39
sORRY! MIS READ
Julien Goux
@jgoux
Mar 21 2016 19:40
pick instead of pickAll actually ^^
Matthias Seemann
@semmel
Mar 21 2016 19:40

The docu for R.values says

Note that the order of the output array is not guaranteed across different JS platforms.

I need to have the resulting values in the same order as the keys I specify in the first argument
Denys Mikhalenko
@prontiol
Mar 21 2016 19:42
in array?
Matthias Seemann
@semmel
Mar 21 2016 19:43
Yes of course, the result is an array of values.
Keith Alexander
@kwijibo
Mar 21 2016 19:46
@jgoux I would represent both with future
Julien Goux
@jgoux
Mar 21 2016 19:47
@kwijibo why ?
Keith Alexander
@kwijibo
Mar 21 2016 19:48
Because it's easier to deal with just one type
Julien Goux
@jgoux
Mar 21 2016 19:48
True :clap:
Keith Alexander
@kwijibo
Mar 21 2016 19:48
I'm not a guru though... Challenge my logic :)
Julien Goux
@jgoux
Mar 21 2016 19:49
What I want to achieve is being able to define multiple "update" functions and compose them
I was able to do it using redux-loop which is more or less designed to return a pair of state+effect
But I had to implement my own composition logic
So maybe I can find a right datastructure to do it more naturally
Keith Alexander
@kwijibo
Mar 21 2016 19:55
@jgoux the update functions are reducers, right? you could compose them with the transducers pattern
Julien Goux
@jgoux
Mar 21 2016 19:55
yes they are reducers :D
Denys Mikhalenko
@prontiol
Mar 21 2016 19:57
shouldn't key be x, y and z instead of 0, 1 and 2? anyone?
R.addIndex(R.map)((value,key,collection) => console.log(value,key,collection))({x:1, y:2, z:3})
Julien Goux
@jgoux
Mar 21 2016 19:57
could you give me a link about this transducers pattern ?
@prontiol I think addIndex just add a regular integer index, so it seems good to me
Keith Alexander
@kwijibo
Mar 21 2016 19:59
@jgoux http://phuu.net/2014/08/31/csp-and-transducers.html was what helped me grok it ... it's a long read I'm afraid
Julien Goux
@jgoux
Mar 21 2016 19:59
I don't mind long reads, I enjoy learning :D
thank you !
Keith Alexander
@kwijibo
Mar 21 2016 19:59
well, it's a really good blog post :) hope you enjoy it
Denys Mikhalenko
@prontiol
Mar 21 2016 20:00
i believe it is not correct for objects :-(
who needs integer index as a key for object?
Keith Alexander
@kwijibo
Mar 21 2016 20:00
basically the transducer pattern is, reducers are binary functions, and you can only really compose unary functions
This message was deleted
Matthias Seemann
@semmel
Mar 21 2016 20:09
@prontiol If applied on an object R.map works just on the values, not the keys:
R.map( x => { console.log(x); }, {x:1, y:2, z:3})  // 1 2 3
Denys Mikhalenko
@prontiol
Mar 21 2016 20:11
i was talking about keys added by R.addIndex
as indexes in an object are strings, key should be actually keys and not just autoincrementing integers
because these integer keys have no use actually, if iterating over an object
Keith Alexander
@kwijibo
Mar 21 2016 20:18
@jgoux so you make the reducers unary by making them accept another reducer that they compose with themselves internally
Matthias Seemann
@semmel
Mar 21 2016 20:19
@prontiol I don't know if the implementation of R.addIndex treats objects in the same way as arrays (just what it is supposed to work on) but with keys as indices.
kwijibo @kwijibo finds reactjs/redux#1528 in my open-but-unread tabs
Julien Goux
@jgoux
Mar 21 2016 20:21
@kwijibo ok I read the article, but I don't immediately see how using a tranducer would improve my current implementation (or I don't see how to do it :D)
Matthias Seemann
@semmel
Mar 21 2016 20:25

Without using Ramda the native implementation or my pickValues problem is simply

// [string] -> {k:v} -> [v]
var pickValues = keys => object => keys.map( key => object[key] );
pickValues(['x', 'y'])({x: 1, y: 2, z: 3}) // ===> [1, 2]

Perhaps that is better.

LeonineKing1199
@LeonineKing1199
Mar 21 2016 20:26
Looking at gist makes me wish that JS had namespaces sooooooo badly
Brad Compton (he/him)
@Bradcomp
Mar 21 2016 20:26
@semmel :+1: That's clearly readable
Denys Mikhalenko
@prontiol
Mar 21 2016 20:26
@semmel this seems to be good enough
Kevin Wallace
@kedashoe
Mar 21 2016 20:31
@prontiol i agree addIndex sounds like it might add object keys, maybe the docs should explicitly state that it doesn't
you can use http://ramdajs.com/docs/#mapObjIndexed if you need the object keys :)
Kevin Wallace
@kedashoe
Mar 21 2016 20:38
does anyone think the "See also" annotations are too subtle? I knew ramda had what @semmel was looking for but it still took me a bit to find it even though the first place I looked was pick and there is a "see also" for props there
Matthias Seemann
@semmel
Mar 21 2016 20:38
@kedashoe Yeah, right that is it! Thank you!.
It is sometimes so difficult to discover a Ramda function... pick, pluck, props all similar in behaviour but the naming... I have no clue...
Denys Mikhalenko
@prontiol
Mar 21 2016 20:39
agreed
Kevin Wallace
@kedashoe
Mar 21 2016 20:40
we're working on that, any ideas anyone has in that area welcome :)
@svozza just recently put together this awesome page ramda/ramda#1695
Matthias Seemann
@semmel
Mar 21 2016 20:57

@kedashoe What lead me astray is the inconsistent wording, even in the type signatures. For R.prop the docu speaks about properties (hence it's name), The sig is s → {s: a} → a | Undefined and the text says

returns the indicated property

Where as for R.props the sig is [k] → {k: v} → [v] and the text is about values. It says

Returns ... corresponding values

R.pluck is about keys and values as well.
Perhaps R.prop and R.props should be called R.valuesOf or something like that... But I don't know.

Stefano Vozza
@svozza
Mar 21 2016 22:10
I just realised that addIndex is not on that list of functions I compiled. I'm just about to head to bed so if anyone wants to correct my omission then go ahead:
https://github.com/ramda/ramda/wiki/What-Function-Should-I-Use%3F
LeonineKing1199
@LeonineKing1199
Mar 21 2016 22:26
That list is awesome!
Scott Christopher
@scott-christopher
Mar 21 2016 22:26
I can add addIndex now.
:zap:
Brad Compton (he/him)
@Bradcomp
Mar 21 2016 22:32
Should we add R.props as well?
  • I want to pick an ordered list of values from an object
Lewis
@6ewis
Mar 21 2016 22:33
Should we add R.when as well?
Lewis
@6ewis
Mar 21 2016 22:54
How do you guys read that a → [a] → Number
Scott Christopher
@scott-christopher
Mar 21 2016 22:56
@6ewis: It takes some value of type a, along with a list of values of the same type and returns a number (presumably the index of the element)
Lewis
@6ewis
Mar 21 2016 22:57
where's that notation from?
LeonineKing1199
@LeonineKing1199
Mar 21 2016 22:57
I think from the lands of pure functional programming
Scott Christopher
@scott-christopher
Mar 21 2016 22:58
!type signatures
Denis Stoyanov
@xgrommx
Mar 21 2016 23:20
!map
ram-bot
@ram-bot
Mar 21 2016 23:20
Not a factoid
Scott Christopher
@scott-christopher
Mar 21 2016 23:21
map
¯_(ツ)_/¯
Denis Stoyanov
@xgrommx
Mar 21 2016 23:23
bot was tired :smile:
Scott Christopher
@scott-christopher
Mar 21 2016 23:23
@ram-bot map
ram-bot
@ram-bot
Mar 21 2016 23:23
[Function: f2]
Scott Christopher
@scott-christopher
Mar 21 2016 23:23
Last attempt ...
R.map
Scott Christopher
@scott-christopher
Mar 21 2016 23:23
huzzah
Denis Stoyanov
@xgrommx
Mar 21 2016 23:24
@ram-bot Last attempt ... filter
ram-bot
@ram-bot
Mar 21 2016 23:24
[Function: f2]
Scott Christopher
@scott-christopher
Mar 21 2016 23:25
From what I understand, you can use @ram-bot and then a code snippet to get it to evaluate something.
Denis Stoyanov
@xgrommx
Mar 21 2016 23:25
@ram-bot
Last attempt ...
filter
Scott Christopher
@scott-christopher
Mar 21 2016 23:25
or if you want the type sig, you just need the function name prefixed with R. by itself.
so
R.filter
Denis Stoyanov
@xgrommx
Mar 21 2016 23:25
oh!
R.converge
Denis Stoyanov
@xgrommx
Mar 21 2016 23:26
nice
Brad Compton (he/him)
@Bradcomp
Mar 21 2016 23:27
@ram-bot R.filter(R.gt(R.__, 5), [1,2,3,4,5,6,7,8,9,0])
ram-bot
@ram-bot
Mar 21 2016 23:27
[ 6, 7, 8, 9 ]