These are chat archives for ramda/ramda

6th
Oct 2016
Daniel Tsui
@sdtsui
Oct 06 2016 03:21

Hark! Gods of the FP.
How would you use Ramda to perform the following transformation?
I’m thinking there’s a map/reduce, and liberal use of R.prop/R.keys to map the right values/keys to three new objects.

{
  xs: [12, 12, 12],
  sm: [4, 4, 4],
  md: [8, 2, 2],
  lg: [9, 2, 1]
}
=>
[
  { xs: 12, sm: 4, md: 8, lg: 9 },
  { xs: 12, sm: 4, md: 2, lg: 2 },
  { xs: 12, sm: 4, md: 2, lg: 1 }
]

Thanks!

Scott Christopher
@scott-christopher
Oct 06 2016 03:34
@sdtsui There's probably a nicer way, but this seems to produce what you're after:
@ram-bot
const data = {
  xs: [12, 12, 12],
  sm: [4, 4, 4],
  md: [8, 2, 2],
  lg: [9, 2, 1]
}

map(zipObj(keys(data)), transpose(values(data)))
ram-bot
@ram-bot
Oct 06 2016 03:34
[ { xs: 12, sm: 4, md: 8, lg: 9 },
  { xs: 12, sm: 4, md: 2, lg: 2 },
  { xs: 12, sm: 4, md: 2, lg: 1 } ]
Scott Christopher
@scott-christopher
Oct 06 2016 03:36
or if you're up for a game of point-free golf:
Daniel Tsui
@sdtsui
Oct 06 2016 03:36
@scott-christopher That’s pretty nice.
Scott Christopher
@scott-christopher
Oct 06 2016 03:36
@ram-bot
const data = {
  xs: [12, 12, 12],
  sm: [4, 4, 4],
  md: [8, 2, 2],
  lg: [9, 2, 1]
}

const fn = converge(map, [compose(zipObj, keys), compose(transpose, values)])
fn(data)
ram-bot
@ram-bot
Oct 06 2016 03:36
[ { xs: 12, sm: 4, md: 8, lg: 9 },
  { xs: 12, sm: 4, md: 2, lg: 2 },
  { xs: 12, sm: 4, md: 2, lg: 1 } ]
Daniel Tsui
@sdtsui
Oct 06 2016 03:37
How would you recommend learning this? I’m still thinking in functional-lite JS. Any books/tutorials? On the other hand, been told I could just learn Haskell and come back to Ramda. :P
(proficiency in the tools this library provides)
Scott Christopher
@scott-christopher
Oct 06 2016 03:38
For something specific to Ramda, this blog series seems quite decent: http://randycoulman.com/blog/categories/thinking-in-ramda/
If you're wanting to go down the route of learning Haskell and (potentially) coming back to JS, this book is highly recommended http://haskellbook.com/
Daniel Tsui
@sdtsui
Oct 06 2016 03:40
Rad. Thank you!
Scott Christopher
@scott-christopher
Oct 06 2016 03:41
:thumbsup:
Scott Sauyet
@CrossEye
Oct 06 2016 03:41
Damn that other Scott! :smile: Not only does he beat me to the punch, but he has a better solution! I think it's time for bed!
Nice job, @scott-christopher!
Scott Christopher
@scott-christopher
Oct 06 2016 03:45
haha, I wish it were time for bed
Vladimir Starkov
@iamstarkov
Oct 06 2016 08:01
i asked yesterday but no reply, can one tell me more about scripts/doc-blob in ramda repo?
David Chambers
@davidchambers
Oct 06 2016 10:13
@iamstarkov, it was added in #709 and hasn't been modified since.
Vladimir Starkov
@iamstarkov
Oct 06 2016 10:15
hmm
even in that pr, i cant see how that file suposed to be used =(
Vladimir Starkov
@iamstarkov
Oct 06 2016 10:30
was thinking about native commonjs entry point for ramda
discussed it previously here
so i made small tiny pr for it ramda/ramda#1928
Markus Pfundstein
@MarkusPfundstein
Oct 06 2016 12:20
Holla, is there a ramda function that is the oppsoite of R.isNil ?
e.g. R.filter(R.exists, mylist) or s.th. like this
Vladimir Starkov
@iamstarkov
Oct 06 2016 13:15
@MarkusPfundstein fast fix: R.complement(R.isNil)
@MarkusPfundstein i dont think there is built-in method for this
Markus Pfundstein
@MarkusPfundstein
Oct 06 2016 13:19
Ah thx
Travis LaDuke
@laduke
Oct 06 2016 18:05
I need to evolve a property that might not exist. What's the pattern for that? I'm just toggling something between true and false. Undefined should toggle to true I guess.
Ryan Zeigler
@rzeigler
Oct 06 2016 18:07
@laduke, I think if you use Boolean as the function it will behave as expected
Brad Compton (he/him)
@Bradcomp
Oct 06 2016 18:08
evolve won't do anything if the field doesn't exist though
Ryan Zeigler
@rzeigler
Oct 06 2016 18:08
right...
merge with your object on the right first
Brad Compton (he/him)
@Bradcomp
Oct 06 2016 18:09
@ram-bot
R.evolve({a: R.T}, {});
ram-bot
@ram-bot
Oct 06 2016 18:09
{}
Ryan Zeigler
@rzeigler
Oct 06 2016 18:09
and the left value should have a bunch of nulls
@ram-bot
R.evolve({a: Boolean}, R.merge({a: null}, {}))
ram-bot
@ram-bot
Oct 06 2016 18:09
{ a: false }
Brad Compton (he/him)
@Bradcomp
Oct 06 2016 18:09
:point_up:
Was gonna say the same thing
Travis LaDuke
@laduke
Oct 06 2016 18:11
:heart: