These are chat archives for ramda/ramda

26th
Jul 2015
David Chambers
@davidchambers
Jul 26 2015 05:03
Is there a way to transform [Just(1), Just(2), Nothing(), Just(4)] into [1, 2, 4]? R.filter(R.is(S.Just)) followed by R.map(S.fromMaybe(null)) feels hacky.
Scott Christopher
@scott-christopher
Jul 26 2015 05:16
If your Maybe implementation has a toList method, you could also R.compose(R.reduce(R.concat, []), R.map(a => a.toList()))
David Chambers
@davidchambers
Jul 26 2015 05:17
That’s a good idea!
Seems like something that should be added to Sanctuary. :)
I’m working on a Ramda/Sanctuary REPL. It’s going to be pretty sweet!
Scott Christopher
@scott-christopher
Jul 26 2015 05:18
Nice.
David Chambers
@davidchambers
Jul 26 2015 05:20
Just about have this working:
S :t R.inc
  Number -> Number

S :t S.head
  [a] -> Maybe a
I’m just pulling the types from the source code, which could be viewed as cheating (since :t 'foo' will not work). I see it as more closely resembling the way ipython will print a function’s docstring than the way Haskell’s REPL actually knows about types.
By the way, I’ve been using R.adjust quite a bit lately. Very useful function, @scott-christopher!
Scott Christopher
@scott-christopher
Jul 26 2015 05:23
Glad to hear :D
I’ve been wondering whether Ramda could benefit from some Flow type annotations.
I’ve never used Flow myself to know how useful it would be
Or whether it would just end up as visual clutter.
David Chambers
@davidchambers
Jul 26 2015 05:25
I’ve never used it either, but it’s certainly worth considering.
It could hardly be more clutter than JSDoc already adds. ;)
Scott Christopher
@scott-christopher
Jul 26 2015 05:26
I dunno, it looks pretty intrusive: http://flowtype.org/blog/2015/02/20/Flow-Comments.html
David Chambers
@davidchambers
Jul 26 2015 05:27
The tricky part might be preserving all these comments in the build script.
Scott Christopher
@scott-christopher
Jul 26 2015 05:27
Which is partly due to the comment syntax so it maintains compatible existing javascript
Ludwig Magnusson
@TheLudd
Jul 26 2015 10:09
@davidchambers With the reduce method added by @scott-christopher in ramda/ramda-fantasy#58 you can do
R.reduce(function(acc, item) {
 return item.reduce(R.flip(R.append), acc);
}, [], inputArray);
Scott Christopher
@scott-christopher
Jul 26 2015 11:09
Which I think should be able to be reduced further if you're so inclined:
R.reduce(R.reduce(R.flip(R.append)), [], inputArray);
or ...
concatMaybe = R.reduce(R.reduce(R.flip(R.append)), []);
Ludwig Magnusson
@TheLudd
Jul 26 2015 13:01
@scott-christopher Looks like one argument is missing there. You have two reduce calls but only one initial value. Correct?
Scott Christopher
@scott-christopher
Jul 26 2015 13:40
The initial value for the inner reduce should be supplied by the outer reduce (I haven't actually tested this, but I believe the types line up)