These are chat archives for ramda/ramda

24th
Apr 2015
Hardy Jones
@joneshf
Apr 24 2015 00:00
it just so happens that in the merge version of mergeBy, that function is function(x, y) { return y; }.
handling the three cases could be yet another function
Hardy Jones
@joneshf
Apr 24 2015 00:05

as an aside, handling the three cases could be done with one function very robustly with some good type system (or maybe ramda-fantasy :)). If you could express:

data OneOf a b = First a | Second b | Both a b

Then you could have: mergeAllCases :: (OneOf a b -> c) -> {k: a} -> {k: b} -> {k: c}

Scott Sauyet
@CrossEye
Apr 24 2015 00:35
I could buy that. I was trying to imagine a superset of all three of these and failing to find a simple enough API. Splitting it this way is reasonable. In fact I would love it if someone wanted to create a PR for this.
Hardy Jones
@joneshf
Apr 24 2015 00:43
oh, i see
Hardy Jones
@joneshf
Apr 24 2015 00:49
well, i think doing something like that could let you generalize it to that level
mergeBy = R.curry(function(f, xs, ys) {
  return mergeAllCases(R.cond(
    [isFirst, unwrapFirst],
    [isSecond, unwrapSecond],
    [isBoth, applyBoth(f)]
  ), xs, ys);
}
for the appropriate definitions
and of course, it could just be an object
mergeBy = R.curry(function(f, xs, ys) {
  return mergeAllCases(R.cond(
    [R.both(R.has('first'), R.has('second')), function(obj) { return f(obj.first)(obj.second); }],
    [R.has('first'), R.prop('first')],
    [R.has('second'), R.prop('second')]
  ), xs, ys);
}
Or something?
Scott Sauyet
@CrossEye
Apr 24 2015 00:54
Not quite following. What would the unwrap's do? I can't see any way to avoid either passing in three functions or insisting that functions passed can handle (first, second), (first, undefined), and (undefined, second). Neither is appealing.
Hardy Jones
@joneshf
Apr 24 2015 00:54
does that second one make more sense?
Scott Sauyet
@CrossEye
Apr 24 2015 00:56
Seem to have lost all use of xs and ys there? Are they supposed to be tied somehow to first and second?
also, the shortener on tryramda didn't work for that particular program
Scott Sauyet
@CrossEye
Apr 24 2015 01:12
Dunno why. @buzzdecafe put it together fairly quickly, but it's worked so far. It's possibly that we're hitting API usage limits on the shortener...
Scott Sauyet
@CrossEye
Apr 24 2015 01:17
I'm confused, I guess. I may be missing the point of what you're trying to do here. I had thought you were trying to meet my (quite possibly unrealistic) goal of providing an API that allows the user to provide a function that decides what to include when only the first object contains a given key, when only the second object contains the key, and when they both contain it. This looks mostly like a rewrite of your earlier suggestion.
Hardy Jones
@joneshf
Apr 24 2015 02:13
well the idea is that you supply something like that cond thing for each implementatin
so the intersect idea would only apply the function when it had both, but do nothing when it only has one
probably doesn't work like that with that implementation
or maybe it does, somehow...
hmm, that link didnt ork
Scott Sauyet
@CrossEye
Apr 24 2015 02:56
Well, this is still not quite as generic as I was thinking about, but it's probably much better conceived. If nothing else, it's got a fairly simple API.
Hardy Jones
@joneshf
Apr 24 2015 03:43
yeah, I dunno if it's good enough to expose as an actual api, but internally it's not bad
Raine Virta
@raine
Apr 24 2015 08:43
R.map(R.apply(R.__, null), R.repeat(someImpureFn, 5))
R.map(someImpureFn, R.range(0, 5))
any better ideas or preferences?
Simon Friis Vindum
@paldepind
Apr 24 2015 10:01
@raine: What about forEach?
Raine Virta
@raine
Apr 24 2015 10:05
i'm using map because someImpureFn's return value is wanted
Simon Friis Vindum
@paldepind
Apr 24 2015 10:29
@raine: Is it possible to separate the function into a pure and an impure part? Like
var l = R.map(somePureFn, R.range(0, 5))
R.forEach(somImpureFn, l)
Raine Virta
@raine
Apr 24 2015 10:34
well i should've mentioned that i called it impure because it generates random data
so no i dont't think it can be separated
Simon Friis Vindum
@paldepind
Apr 24 2015 10:45
@raine: Then what about R.times(impureRandomFn, 5).
It seems to be the most explicit approach if you don't actually operate on the numbers generated by R.range.
Which I now see is actually clear from your R.repeat example.
Raine Virta
@raine
Apr 24 2015 10:52
exactly what i was looking for
thanks!
Simon Friis Vindum
@paldepind
Apr 24 2015 11:01
You're welcome :)
Raine Virta
@raine
Apr 24 2015 11:27
would R.range('a', 'z'); // => ['a', 'b', 'c', ... ]; make sense in Ramda?
Simon Friis Vindum
@paldepind
Apr 24 2015 11:51
I think lexicographic ordering is too tricky.
If your fine with the defualt unicode ordering you could do this:
var fromCharCode = String.fromCharCode.bind(String);
R.map(fromCharCode, R.range('a'.charCodeAt(), 'z'.charCodeAt()));
Raine Virta
@raine
Apr 24 2015 12:49
yep
Michael Hurley
@buzzdecafe
Apr 24 2015 21:25
@joneshf the bitly links appear to be working for me
btw i added matching inside a list and streaming results to my kanren :-)