These are chat archives for ramda/ramda

1st
Oct 2015
Hardy Jones
@joneshf
Oct 01 2015 04:40
The problem with that notation is that it's ambiguous without assigning some precedence to each operator.
do you mean (a, b) -> c or do you mean (a, b -> c)?
James Forbes
@JAForbes
Oct 01 2015 04:56
hey guys, is there an equivalent to _.indexBy ?
John-David Dalton
@jdalton
Oct 01 2015 06:41
@JAForbes What do you think of the name keyBy instead of indexBy?
Raine Virta
@raine
Oct 01 2015 07:04
cond so much nicer than switch statement
@davidchambers https://github.com/ramda/ramda/wiki/Cookbook#get-an-objects-method-names is this function different from R.functions?
David Chambers
@davidchambers
Oct 01 2015 07:08
@raine, see ramda/ramda#1350.
Raine Virta
@raine
Oct 01 2015 07:09
I see
Raine Virta
@raine
Oct 01 2015 07:49
bummer that you can't do this anymore
> both = require('ramda/src/both');
[Function]
> both(complement(isNil), propSatisfies(pipe(type, equals('Function')), 'then'))(null)
TypeError: Cannot read property 'then' of null
Niloy Mondal
@niloy
Oct 01 2015 10:47
Hey, can anyone tell me why and doesn't accept array?
Raine Virta
@raine
Oct 01 2015 10:48
@niloy probably because it wasn't designed to do that
Niloy Mondal
@niloy
Oct 01 2015 10:49
How am I suppose to reduce an array of truthy/falsy values to a single boolean value?
Raine Virta
@raine
Oct 01 2015 10:51
something like
R.reduce(R.and, true, [true, undefined, false])
Raine Virta
@raine
Oct 01 2015 10:57
or
// :: [*] -> Boolean
R.pipe(R.reduce(R.and, true), R.complement(R.not))
Niloy Mondal
@niloy
Oct 01 2015 11:10
@raine But R.reduce does not short-circuit
and and or can be short-circuited
In Haskell, both and and or have type signature [Bool] -> Bool
I would really love to see that in Ramda
Raine Virta
@raine
Oct 01 2015 11:14

But R.reduce does not short-circuit

why is it a problem?

Niloy Mondal
@niloy
Oct 01 2015 11:14
Performance?
Raine Virta
@raine
Oct 01 2015 11:17
how big are your lists?
Niloy Mondal
@niloy
Oct 01 2015 11:18
Small. But then how difficult is it to implement such a things, its really trivial.
Hardy Jones
@joneshf
Oct 01 2015 11:23
@niloy
R.all(R.identity, xs)
Raine Virta
@raine
Oct 01 2015 11:24
nice one
Niloy Mondal
@niloy
Oct 01 2015 11:24
@joneshf I agree there are ways of achieving the result. I am just suggesting, that having and accept array has superior readability. And also, Haskell does it.
Hardy Jones
@joneshf
Oct 01 2015 11:29
Haskell also treats operators as first class, so it doesn't need a library to provide an and function.
JavaScript doesn't have that luxury, thus ramda gives and.
Mark Perry
@mperry
Oct 01 2015 11:45
Hmmm, I would describe Haskell as having no operators, just functions...
Hardy Jones
@joneshf
Oct 01 2015 11:50
six of one ;)
Scott Sauyet
@CrossEye
Oct 01 2015 12:06
Haskell has a construct that removes the need for the distinction between functions and operators. This is one of those places where I always ends up with Haskell-envy.
Niloy Mondal
@niloy
Oct 01 2015 12:56
Feature request: and and or function which accepts array and is short-circuited
Scott Sauyet
@CrossEye
Oct 01 2015 12:59
This is FP (ok, FP-ish) wherein order of evaluation is left to the runtime/compiler. What does short-circuiting mean in that case?
Also note that this is JS
So arguments are fully evaluated before being passed.
Mark Perry
@mperry
Oct 01 2015 13:01
True, but lazy data structures can be created in eager languages.
Scott Sauyet
@CrossEye
Oct 01 2015 13:02
There is a case to be made for sort-circuiting in both, but a very recent change has just removed that, as it didn't seem major.
Raine Virta
@raine
Oct 01 2015 13:03
you can work around that with allPass
Scott Sauyet
@CrossEye
Oct 01 2015 13:03
But and evaluates the arguments; it doesn't vak functions.
Vak? Call
Love my phone. Really.
Christoph Neuroth
@c089
Oct 01 2015 15:34
Hey, I'm trying to build a "dynamic" intersperse. So instead of interspersing a fixed thing, I want to build that dynamically. I have a solution, but don't like it a lot / am sure it can be done easier:
var names = ['foo', 'bar', 'baz']
var separators = R.map(function(i) {return 'separator' + i;}, R.range(1, names.length+1));
R.dropLast(1, R.flatten(R.zip(names, separators)))
Output being ["foo", "separator1", "bar", "separator2", "baz"]
Raine Virta
@raine
Oct 01 2015 16:27
@c089 fwiw, dropLast(1) is init
Tobias Pflug
@gilligan
Oct 01 2015 19:06
@c089 dybamic intersperse sounds related to zipWith for me
dynamic- thank you iPad
i wonder if there are any opinions about possibly moving this channel to slack? the fpchat slack is quite popular and gitter is kind of meh (imho) while of course easier to reach slack which requires registration
Tobias Pflug
@gilligan
Oct 01 2015 19:11
just a thought
Raine Virta
@raine
Oct 01 2015 19:24
I don't like slack taking over OSS
I'd prefer IRC but its biggest issue is lack of history if you don't set up a client that is online at all times
mac10688
@mac10688
Oct 01 2015 19:28
I feel the same way
that and it's easier to share gifs
;)
John-David Dalton
@jdalton
Oct 01 2015 19:31
Ravi Mehra
@ravishivt
Oct 01 2015 20:22
I'm trying to take an array of objects and set a property on each of them. This is what I have so far but no luck:
R.forEach(R.set(R.lensProp('isEnabled'), false))([{x: 1, y: 2}, {x: 3, y: 4}]);
Raine Virta
@raine
Oct 01 2015 20:23
R.map(R.assoc('isEnabled', false))(objs)
Tobias Pflug
@gilligan
Oct 01 2015 20:23
@raine yeah well dunno how to feel about slack taking over. Like I said gitter.im is useful because it is so discoverable and easy to get in touch. i just find the app/web ui somewhat crappy .. maybe its just me.
Ravi Mehra
@ravishivt
Oct 01 2015 20:24
easy enough. thanks @raine !
Raine Virta
@raine
Oct 01 2015 20:25
@ravishivt generally forEach is only for side-effects, not for manipulating data
Ravi Mehra
@ravishivt
Oct 01 2015 20:29
OK, understood. Using .map instead of forEach fixes my original attempt. Would the following be more performant since it doesn't use assoc?
R.map(R.set(R.lensProp('isEnabled'), false))([{"x": 1, "y": 2}, {"x": 3, "y": 4}]);
Scott Sauyet
@CrossEye
Oct 01 2015 20:33
I definitely think Gitter still needs work on its UI, but its easy obtain with GitHub is fantastic and it seems a nice replacement for IRC without some of the headaches. I haven't used Slack, so have no basis for comparison, but free is always a selling point.
Its easy access with Github.
Ravi Mehra
@ravishivt
Oct 01 2015 20:55
Potentially stupid question. What if I wan't ramda to do an in-place operation of an array with .map() as in I don't want a copy of the array?
Scott Sauyet
@CrossEye
Oct 01 2015 20:58
Not a stupid question, but you might not like the answer: use a different library. One of the core principles of Ramda is to never mutate input data.
Ravi Mehra
@ravishivt
Oct 01 2015 20:59
Interesting, thanks. Also, is this the right place to ask small questions or should I revert to Stack Overflow?
Scott Sauyet
@CrossEye
Oct 01 2015 21:02
Either is fine. Probably will get faster answers here.
Although there's never any guarantee that anyone in particular will be online.
Raine Virta
@raine
Oct 01 2015 21:10

Potentially stupid question. What if I wan't ramda to do an in-place operation of an array with .map() as in I don't want a copy of the array?

@ravishivt curious as to why you want that

Scott Christopher
@scott-christopher
Oct 01 2015 21:12
http://functionalslack.com/ for anyone interested in the FP Slack group.
There is a dedicated JavaScript channel too.
The thing I'm not so fond about Slack is its requirement to create a new account for each new group/team.
And I think they still don't have syntax highlighting for markdown code blocks.
Scott Christopher
@scott-christopher
Oct 01 2015 21:17
Its UI does feel a little more polished than Gitter's though, particularly on mobile.
Ravi Mehra
@ravishivt
Oct 01 2015 21:20
This message was deleted

@ravishivt curious as to why you want that

In the situation where there is a reference to the original array and I want to edit the array in place so the object that references it also receives the updates. My specific example is ui-grid's gridOptions.data. The .data prop contains the reference of the data array that I need to maintain.

Tobias Pflug
@gilligan
Oct 01 2015 21:41
@scott-christopher yeah the main reason for me to bring this up is the ui. i wish we could the ui of slack and the free/quick setup of gitter combined
but its great how you can go from ramda github to chatting here in a few clicks
Martin Algesten
@algesten
Oct 01 2015 21:46
I hate gitter. but i like you
guys hanging here.
David Chambers
@davidchambers
Oct 01 2015 22:09
@raine, R.complement(R.not) can also be pronounced Boolean. :wink2:
Jethro Larson
@jethrolarson
Oct 01 2015 22:24
compose(not, not)
If you tried to map over a set would you expect to get an array or get a new set without a 1 to 1 mapping?
David Chambers
@davidchambers
Oct 01 2015 22:26
I would expect the output to have the same shape as the input.
Jethro Larson
@jethrolarson
Oct 01 2015 22:30
That's what I thought, but I didn't know if it's okay for length to be different between input and output
David Chambers
@davidchambers
Oct 01 2015 22:30
Clojure disagrees with us:
user=> (map count #{"foo" "bar" "baz"})
(3 3 3)
Jethro Larson
@jethrolarson
Oct 01 2015 22:31
Yeah, I suspected they might
that's a list, right?
David Chambers
@davidchambers
Oct 01 2015 22:31
The output is a list, yes.
I'm not sure whether mapping over a set makes sense. Is Set a functor?
Jethro Larson
@jethrolarson
Oct 01 2015 22:32
I don't know. It's a collection, clearly
it's reasonable to want to run a function on each thing
it's iterable
Scott Christopher
@scott-christopher
Oct 01 2015 22:34
what should result from R.map(R.always(1), Set(1, 2, 3))?
Jethro Larson
@jethrolarson
Oct 01 2015 22:34
I guess the clojure philosophy is concerned with with that more than mathematical integrity
Either [1, 1, 1] or Set(1)
I don't know which is least surprising
Scott Christopher
@scott-christopher
Oct 01 2015 22:35
Set(1) is less surprising because it's returning the correct type
Jethro Larson
@jethrolarson
Oct 01 2015 22:35
I know es6 isn't providing a map method
I guess the recommendation is to convert first
R.map(R.always(1), [...(new Set(1, 2, 3))])
Scott Christopher
@scott-christopher
Oct 01 2015 22:38
I'm guessing that you'd find that Set wouldn't satisfy the map(compose(f, g)) == compose(map(f), map(g))
if the map(g) on the right caused the Set to reduce in size, but composing f and g on the left keeps the same size
Jethro Larson
@jethrolarson
Oct 01 2015 22:40
That makes sense
So I guess it can't be a functor then
clojure takes a guess at your intent and converts for you. Typical clojure
:)
Scott Christopher
@scott-christopher
Oct 01 2015 22:47
On the otherhand, if you treat Set only as a function that simply determines whether the value exists in the Set, you could map over that as plain ol' function composition.
... I think
Jethro Larson
@jethrolarson
Oct 01 2015 23:18
Yeah, i think with some hand waving you can treat it like a filter
Er reducer, really