These are chat archives for ramda/ramda

1st
Apr 2017
Kurt Milam
@kurtmilam
Apr 01 2017 00:06
@agstrauss you may also want to take a look at applySpec
Jonah
@jonahx
Apr 01 2017 02:10

i’m reading over the daggy source code, and i can’t figure out what is happening with the 0, part in this line:

// this way we avoid named function
  const typeRep = (0, (...args) => makeValue(fields, proto, args))

for context: https://github.com/fantasyland/daggy/blob/master/src/daggy.js#L18

Gabe Johnson
@gabejohnson
Apr 01 2017 02:14
@jonahx some JS engines can infer a function name from the LHS of an assignment expression.
But in this case the RHS is a parenthesized expression that evaluates to a function.
The trick works in V8 in my browser, but the inference algorithm could become more sophisticated in the future
Jonah
@jonahx
Apr 01 2017 02:19
@gabejohnson not sure i follow, but i found this link http://stackoverflow.com/questions/5161502/indirect-function-call-in-javascript which suggests it forces this within the function to be global
still not sure why it needs to happen in this case though...
Gabe Johnson
@gabejohnson
Apr 01 2017 02:35
@jonahx while what is described in the the SO answer is true, in this case I'm fairly certain it's being done to avoid having proto.constructor being polluted with the name typeRep
Jonah
@jonahx
Apr 01 2017 02:38
@gabejohnson so it’s an anonymous arrow function to begin with — what is the name it would have that we’re trying to avoid if we omitted the 0, part?
Gabe Johnson
@gabejohnson
Apr 01 2017 02:41
typeRep
Jonah
@jonahx
Apr 01 2017 02:42
@gabejohnson ah now i understand your comment "some JS engines can infer a function name from the LHS of an assignment expression."
makes sense, ty
Gabe Johnson
@gabejohnson
Apr 01 2017 02:43
:thumbsup:
Jonah
@jonahx
Apr 01 2017 02:43
that is very unexpected behavior btw
Gabe Johnson
@gabejohnson
Apr 01 2017 02:43
Yes. Very...clever
Jonah
@jonahx
Apr 01 2017 02:43
though i could see how it would it help with debugging
Gabe Johnson
@gabejohnson
Apr 01 2017 02:44
I'm glad you asked the question. I didn't know that trick
Could have used it a few weeks ago
Jonah
@jonahx
Apr 01 2017 02:46
so basically they’re playing cat and mouse with an giant “framework” (v8 in this case) which is being aggressively “helpful” in ways you can’t control. so… like programming in ruby on rails.
Gabe Johnson
@gabejohnson
Apr 01 2017 02:54
I've never had the pleasure
Robert Mennell
@skatcat31
Apr 01 2017 03:34
I've never seen anyone actually use the comma separator...
Stefano Vozza
@svozza
Apr 01 2017 11:58
it's handy for keeping the function passed to reduce as a one-liner:
reduce(z, x => (z.push(x+ 1), z), [], [1,2,3]);
Denis Stoyanov
@xgrommx
Apr 01 2017 11:59
ugly idea with push
Stefano Vozza
@svozza
Apr 01 2017 12:00
why? for a large list, it is impractical not to mutate the accumulator
Denis Stoyanov
@xgrommx
Apr 01 2017 12:00
reduce((z, x) => z.concat(x+1), [], [1,2,3])
Stefano Vozza
@svozza
Apr 01 2017 12:00
try using that on a list with a few hundred thousand items
Denis Stoyanov
@xgrommx
Apr 01 2017 12:00
@svozza and this is map
Stefano Vozza
@svozza
Apr 01 2017 12:00
i know
Denis Stoyanov
@xgrommx
Apr 01 2017 12:01
@svozza map(add(1), [1,2,3])
Stefano Vozza
@svozza
Apr 01 2017 12:01
it's a very simple example
Denis Stoyanov
@xgrommx
Apr 01 2017 12:01
I avoid mutation
this isn't predictable
Stefano Vozza
@svozza
Apr 01 2017 12:01
so do i, when i can
i think it's fine to mutate a variable for performance reasons if you are in control of it and it never leaks to the outside world
Denis Stoyanov
@xgrommx
Apr 01 2017 12:07
I think u can also use ES generators
Stefano Vozza
@svozza
Apr 01 2017 12:17
That's cool