These are chat archives for ramda/ramda

5th
Mar 2015
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:11
can I reduce over a map?
I mean, reduce an object?
Or do I have to turn an object into pairs and then reduce that?
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:20
I was looking to use reduceIndexed for an object, but does that not work? I ended up using this instead:
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:29
var reduceObject = R.curry(function (reduceFn, obj) {
  return R.reduce(function (acc, [key, value]) {
    return reduceFn(acc, value, key)
  }, {}, R.toPairs(obj));
});
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:35
You know what would be a great JS operator?
obj = someFunction(obj);
// Equivalent to an operator that applies the left-hand var to the function
obj @= someCurriedFunction();
Hardy Jones
@joneshf
Mar 05 2015 17:38
what?
I don't think I undestand what you want with that operator
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:40
So it gets tiresome when you have to write something like so:
bigNestedArray[3].bigNestedObject.anotherObject = reduceObj(fn, bigNestedArray[3].bigNestedObject.anotherObject);
// vs.
bigNestedArray[3].bigNestedObject.anotherObject @= reduceObj(fn);
Also just makes the code longer.
Hardy Jones
@joneshf
Mar 05 2015 17:41
oh, you want to mutate it in place?
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:42
Hah. Yeah, that's a much better way of explaining it.
Ok, so now that you said that, the solution seems simple.
R.mutate(bigNestedArray[3].bigNestedObject.anotherObject, reduceObject(reducer));
IS there a ramda function that already does this?
David Chambers
@davidchambers
Mar 05 2015 17:45
Ramda functions do not mutate their arguments. You'll need to perform the mutation yourself (as in your earlier example).
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:45
It would be terrific to have a subsection of Ramda functions for side-effects, so that it could be done in a functional style.
David Chambers
@davidchambers
Mar 05 2015 17:46
What do you mean by "functional style"?
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:46
Using functions instead of assignment.
So at the end of an R.pipe, I could use a R.mutate.
Or R.assign
Hardy Jones
@joneshf
Mar 05 2015 17:47
that sort of defeats the purpose
once you introduce mutability in a non-robust way, you lose all reasoning ability
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:48
I don't know enough about Haskell, but isn't the idea that side-effects are dealt with via specific features of the language?
Monads?
David Chambers
@davidchambers
Mar 05 2015 17:49
There's https://github.com/ramda/ramda/tree/v0.10.0/ext/impure, but we're going to remove that soon. If you want to define your own functions which perform mutation you're free to do so, but a key feature of Ramda is that all (but ramda/ramda#834) of its functions are referentially transparent.
Hardy Jones
@joneshf
Mar 05 2015 17:49
no
side effects are dealt with by specific data types
If those data types happen to be monadic, then that's a thing, but the two aren't one and the same.
Nate Wildermuth
@wildermuthn
Mar 05 2015 17:52
It would be hard to implement this anyway, since you'd have to pass an object as a param.
Michael Hurley
@buzzdecafe
Mar 05 2015 18:34
ya impure extension withered on the vine, because, well, eeeew
Danny Fritz
@dannyfritz
Mar 05 2015 21:20
does someone think they can solve this without enumerating over all combinations? http://www.freecodecamp.com/bonfires/no-repeats-please
Nathan
@terakilobyte
Mar 05 2015 21:21
@dannyfritz I’d be very interested in a solution to that as well
Danny Fritz
@dannyfritz
Mar 05 2015 21:21
haha @terakilobyte
you would
this is as far as i've gotten. However, my algorithm double counts and overshoots the number of combinations with consecutive letters: http://jsbin.com/lunoditila/6/edit
Nathan
@terakilobyte
Mar 05 2015 21:22
If anyone wants to school us, Ramda is available in that execution environment so no need to copy/paste it to a fiddle
Danny Fritz
@dannyfritz
Mar 05 2015 21:23
and this is the recursive version you can test against: http://jsbin.com/salasobico/1/edit?js,console
Hardy Jones
@joneshf
Mar 05 2015 22:06
seems like combinatorics
number of possible - number of repeated
also, one of those tests is bunk
expect(permAlone('aab')).to.be.a.number passes even if you just return the string passed in
Danny Fritz
@dannyfritz
Mar 05 2015 22:10
@joneshf well yeah. but how do you make sure you don't double count the repeated cases?
oh, no, I see from the example that's not the question.
odd though that it counts aba and aba as different permutations
migh help
Danny Fritz
@dannyfritz
Mar 05 2015 22:45
@joneshf the 2 a's should be seen as 2 unique symbols with the same value
and yes, that link is very nice. :)