These are chat archives for ramda/ramda

21st
Dec 2016
Dave Keen
@ccapndave
Dec 21 2016 08:11
Hey everyone
Is there a neat Ramda function I can use to go sequentially through a list splitting it on a condition (specifically if the next number is less than the previous). e.g. [1, 2, 3, 4, 2, 3, 6, 7, 0, 1, 4, 2, 3] => [[1, 2, 3, 4], [2, 3, 6, 7], [0, 1, 4], [2, 3]]
Dave Keen
@ccapndave
Dec 21 2016 08:18
Ah, actually I thought of another way to sort out my problem so it doesn't matter after all :)
Anton Strömkvist
@ahstro
Dec 21 2016 08:36
I'm reading Mostly Adequate Guide to FP and it said "I recommend using functor instances from folktale, ramda or fantasy-land"; it also said "A Functor is a type that implements map and obeys some laws". Does ramda have functor instances? Am I just confused about what those are?
Dave Keen
@ccapndave
Dec 21 2016 08:43
Because Javascript isn't typed in the same way as languages like Haskell there is no explicit functor, but you can treat stuff as a functor
Basically anything you can map over is (probably) a functor
In JS that mostly means an array
Anton Strömkvist
@ahstro
Dec 21 2016 08:44
Well yeah, but folktale and fantasy-land, from what I understand, implement functors like Maybe, Either and IO
Aldwin Vlasblom
@Avaq
Dec 21 2016 08:45

@ahstro Ramda contains no Functors or similar (algebraic structures) of its own. It does however:

  • Provide utility functions for any FantasyLand 1.0 compatible Functor, Apply, Applicative and Chain; and
  • Allows those functions to be used on plain JS values that could be Functors etc, for example map works on Objects.

There is Ramda Fantasy which contains several algebraic structures. There's also plenty of other libraries which contain FantasyLand (2.0) compatible algebraic structures, such as Folktale, Sanctuary (Maybe and Either), Fluture (Future), Most (Stream) and of course, FantasyLand

Anton Strömkvist
@ahstro
Dec 21 2016 08:47
Thanks @Avaq :) Any idea if Ramda is going to support FantasyLand 2.0?
BasH
@bas080
Dec 21 2016 08:48
@ccapndave, I would write a reduce to split your list.
Dave Keen
@ccapndave
Dec 21 2016 08:48
@bas080 Yeah, I started doing that then realised that actually I didn't need to do this at all. I thought there might be some kind of group/partition/scan that would do it already though.
partitionWhen or something
Anton Strömkvist
@ahstro
Dec 21 2016 08:50
@ccapndave There's a splitWhen that does part of what you want, but from what I understood, it only wplit an array once, so you'd still have to do some extra magic
Dave Keen
@ccapndave
Dec 21 2016 08:50
Thanks very much :)
Simon Hampton
@simonh1000
Dec 21 2016 16:59
I'm a newbie. I was trying to do the following
> obj = {1: [3,2], 2: [4,1]}
{ '1': [ 3, 2 ], '2': [ 4, 1 ] }
> R.map( R.sortBy((a,b) => a - b), obj)
{ '1': [ 3, 2 ], '2': [ 4, 1 ] }
> R.map( R.sortBy((a,b) => b-a), obj)
{ '1': [ 3, 2 ], '2': [ 4, 1 ] }
I was not expecting the result to be the same in the two cases
I thought I would be mapping the sort function over the array in each value of the object
Brad Compton (he/him)
@Bradcomp
Dec 21 2016 17:01
R.sortBy
Brad Compton (he/him)
@Bradcomp
Dec 21 2016 17:02
The sorting function taken by sortBy is unary - it takes a single parameter.
R.sort
Brad Compton (he/him)
@Bradcomp
Dec 21 2016 17:02
sort works in the way you would expect, taking a comparator function for two items
@ram-bot
var obj = {1: [3,2], 2: [4,1]}
R.map( R.sort((a,b) => a - b), obj)
ram-bot
@ram-bot
Dec 21 2016 17:03
{ '1': [ 2, 3 ], '2': [ 1, 4 ] }
Simon Hampton
@simonh1000
Dec 21 2016 17:03
aha, thanks
Ryan Zeigler
@rzeigler
Dec 21 2016 19:16
so, i've been diving into haskell for the learnings, and I think the most amazing feature ever is that hoogle can search by type signature
i was wondering how the ramda docs are generated and if it would be something feasible to hack in
Erik Sutherland
@MrRacoon
Dec 21 2016 19:29
zomg please make this happen.
Kliment Mamykin
@kmamykin
Dec 21 2016 19:46
I am wondering if there is Ramda idiomatic way to compose functions with the result being a binary function useful in R.sort, R.groupWith etc. E.g.
const list = [
  {p: 1},
  {p: 4},
  {p: 3},
  {p: 6},
  {p: 2},
]
const byP = R.compose(
  ???
)
R.sort(byP, list)
I know R.sortBy will do the trick, but want to know about the composition of binary funcs
Brad Compton (he/him)
@Bradcomp
Dec 21 2016 19:53

I usually use useWith and converge as an analog for composition on binary functions.

For stuff like this, I often use a helper function on which is defined as:

const on = (g, f) => useWith(g, [f, f])

Then you could do, e.g.

sort(on(gt, prop('p')), list)
Kliment Mamykin
@kmamykin
Dec 21 2016 20:01
@Bradcomp awesome! Thanks
Denis Stoyanov
@xgrommx
Dec 21 2016 20:17
Psi combinator =)