These are chat archives for ramda/ramda

3rd
Mar 2017
Brad Compton (he/him)
@Bradcomp
Mar 03 2017 00:01
@ram-bot
converge(unapply(identity), [add(1), add(2), add(3)])(1)
ram-bot
@ram-bot
Mar 03 2017 00:01
[ 2, 3, 4 ]
Sean Cannon
@SeanCannon
Mar 03 2017 00:01
i just used those prop functions as examples. I had to make an Equifax parser once that transformed and padded every supported field and juxt made that really clean
Johnny Hauser
@m59peacemaker
Mar 03 2017 00:04
I'm quite happy with this
var x = {
  foo: [1, 2],
  bar: [3],
  baz: ['a']
}
const concatAll = R.reduce(R.concat, [])
converge(
  R.set(lensProp('foo')), 
  [R.compose(concatAll, R.props(['foo', 'bar'])), identity]
)(x)
there's just one bit of complexity in my real world use. bar is nested
var x = {
  foo: [1, 2],
  nest: {bar: [3]},
  baz: ['a']
}
Johnny Hauser
@m59peacemaker
Mar 03 2017 00:20
Almost point-free
const pathOrProp = R.ifElse(R.isArrayLike, R.path, R.prop)
const propsOrPaths = (items) => R.juxt(R.map(pathOrProp, items))
Johnny Hauser
@m59peacemaker
Mar 03 2017 01:43
I gave it a go making a Ramda, point free version of this https://github.com/TehShrike/one-to-many-array-zip
That's a very tough one!
Markus Pfundstein
@MarkusPfundstein
Mar 03 2017 10:50
on the one-to-many array
cool cat has coolness 7
shouldnt it have 4 childs then?
oh, bobby and billy are already allocated to cool dad, nvmd.
Adam Szaraniec
@mimol91
Mar 03 2017 12:50
Hey folks
I need somehow group by object props
https://goo.gl/FNqbna
Any tips how to get such results?
Gabe Johnson
@gabejohnson
Mar 03 2017 12:56
groupBy
Adam Szaraniec
@mimol91
Mar 03 2017 12:56
groupBy operate on array :(
Gabe Johnson
@gabejohnson
Mar 03 2017 13:07
I'm guessing the results must be ordered
Adam Szaraniec
@mimol91
Mar 03 2017 13:07
yes

And It can happens that I will have

  "shareholders-0.address": "addr1",
    "shareholders-0.firstName": "fisrt1",
    "shareholders-2.address": "addr2",
    "shareholders-2.firstName": "first2",

so it can be incontinous

James Forbes
@JAForbes
Mar 03 2017 13:14
1st attempt:

pipe(
  // so we can transform the key
  toPairs 

  // so we can group by the prefix before discarding it
  ,groupBy( compose(head,split('.'), head) )

  // remove the prefix
  ,map(map(over( lensIndex(0), compose(last, split('.')) )))

  // turn the pairs into objects
  ,map(fromPairs)

  // turn the obj (from groupBy) back into a list
  ,values
)(fieldValues)
Adam Szaraniec
@mimol91
Mar 03 2017 13:15
its look pretty nice :smile:
You do not want to see what I did =0
James Forbes
@JAForbes
Mar 03 2017 13:16
@mimol91 I think someone else can do better :D
its a tough problem!
be nice to not have to change data formats so often for each step
Is this better than the map map map?


  ,map(
    pipe(
       // remove the prefix
      map( over( lensIndex(0), compose(last, split('.')) ))
       // turn the pairs into objects
      ,fromPairs
    )
  )
Adam Szaraniec
@mimol91
Mar 03 2017 13:18
Ye its the case which look 'easy for humans' but hard to translate to 'PC' language
ye I like this
James Forbes
@JAForbes
Mar 03 2017 13:19
yeah, its interesting - where is the data coming from?
its an interesting format
Adam Szaraniec
@mimol91
Mar 03 2017 13:19
its mine =) Basically I m using redux + some dynamic form input
It can be adjusted shareholders-0 so i can change it to shareholders[0] if its more convinient
But its still treated as key so it does not work as I wish xD
Bernhard Wang
@zwc
Mar 03 2017 13:22
I have a bunch of filter's, path's and finally a find in the end. The code works just as I want it, but if the property is missing, it totally spazzes out. I tried with defaultTo(), but for some reason, that doesn't help it.
Denis Stoyanov
@xgrommx
Mar 03 2017 13:23
@ram-bot
var fieldValues =  {
    "shareholders-0.address": "addr1",
    "shareholders-0.firstName": "fisrt1",
    "shareholders-1.address": "addr2",
    "shareholders-1.firstName": "first2",
}

R.compose(
  R.map(R.compose(R.fromPairs, R.map(R.adjust(R.compose(R.last, R.split('.')), 0)))), 
  R.groupWith(R.useWith(R.eqBy(R.compose(R.head, R.match(/\d/))), [R.head, R.head])), 
  R.toPairs
)(fieldValues)
ram-bot
@ram-bot
Mar 03 2017 13:23
[ { address: 'addr1', firstName: 'fisrt1' },
  { address: 'addr2', firstName: 'first2' } ]
Adam Szaraniec
@mimol91
Mar 03 2017 13:25
You are wizards xD
Bernhard Wang
@zwc
Mar 03 2017 13:26
I'd like this to work on any given data, but right now it's just works on data that has a certain structure.
const pricePath = R.path(['pricingPlan', 'pricingTiers']);
const amountExists = R.any(R.has('amounts'));
const hasAmounts = R.compose(amountExists, pricePath);

const getPriceInformation = R.compose(
    R.prop('amounts'),
    R.find(R.has('amounts')),
    R.defaultTo([]),
    pricePath,
    R.head,
    R.filter(hasAmounts),
    R.filter(isProductData)
);

console.log(getPriceInformation([]));
Denis Stoyanov
@xgrommx
Mar 03 2017 13:28
@ram-bot
var fieldValues =  {
    "shareholders-0.address": "addr1",
    "shareholders-0.firstName": "fisrt1",
    "shareholders-1.address": "addr2",
    "shareholders-1.firstName": "first2",
}

R.compose(
  R.map(R.compose(R.fromPairs, R.map(R.adjust(R.compose(R.last, R.split('.')), 0)))),
  R.splitEvery(2), // <- if u know about count of items
  R.toPairs)(fieldValues)
ram-bot
@ram-bot
Mar 03 2017 13:28
[ { address: 'addr1', firstName: 'fisrt1' },
  { address: 'addr2', firstName: 'first2' } ]
Denis Stoyanov
@xgrommx
Mar 03 2017 13:28
:point_up: March 3, 2017 3:28 PM @mimol91
Adam Szaraniec
@mimol91
Mar 03 2017 13:28
Nope, It will be this same amount in every prefix, but its rather dynamic
Bernhard Wang
@zwc
Mar 03 2017 14:00
I fixed it myself by including
R.defaultTo([{ amounts: { } }])
find in combination with has is very sensitive :D
Vincent Orr
@Cmdv
Mar 03 2017 14:28
Is there a better way of checking multiple props than this?
https://goo.gl/RLBYNl
const inputs = [{idA:[1,2,3], idB:'a', idC:'no'},
                  {IdA:[1,2,3], idB:'a', idC:'no'},
                  {IdA:[1,2,3], idB:'a', idC:'yes'}]

const checkPropsEq = (propEq('idA', [1,2,3]),propEq('idB', 'a'),propEq('idC', 'yes'))
const results = map(checkPropsEq, inputs)

any(equals(true))(results) // true one matches in checkPropsEq
feels like it's traversing the inputs 3 times, once for each propEq
Vincent Orr
@Cmdv
Mar 03 2017 14:34
think my main concern is const checkPropsEq = (propEq('idA', [1,2,3]),propEq('idB', 'a'),propEq('idC', 'yes')) just feels wrong
Markus Pfundstein
@MarkusPfundstein
Mar 03 2017 14:40
can’t you use whereEq ?
Vincent Orr
@Cmdv
Mar 03 2017 14:50
Think so unsure how, but I now have another problem the last value I need to check is nested :(
const inputs = [{idA:[1,2,3], idB:'a', data: { idC:'no'}},
                {idA:[1,2,3], idB:'a', data: { idC:'no'}},
                {idA:[1,2,3], idB:'a', data: { idC:'no'}}]
Markus Pfundstein
@MarkusPfundstein
Mar 03 2017 14:51
you can give a test function for each prop, hence you can go deep
Vincent Orr
@Cmdv
Mar 03 2017 14:52
the problem with whereEq is it wont ignore keys, because my input actually has loads more keys and values
Markus Pfundstein
@MarkusPfundstein
Mar 03 2017 14:52
check where then
you can pass R.T for all keys you want to ignore
Vincent Orr
@Cmdv
Mar 03 2017 14:53
ah ok so it wont ignore them off the bat just my object is massive !!
Markus Pfundstein
@MarkusPfundstein
Mar 03 2017 14:53
or you first pick the keys you want to test and test the output but return the original on success
Vincent Orr
@Cmdv
Mar 03 2017 14:54
so make a new object from the original you mean?
then use that as the input, kind of wanted to do it all in one pass if possible :(
I'll try that then
oh looks like pathEq might work http://ramdajs.com/docs/#pathEq
Rick Medina
@rickmed
Mar 03 2017 16:55
overloading functions: :+1: / :-1: ?
Denis Stoyanov
@xgrommx
Mar 03 2017 16:55
ad-hoc polymorphism :smile:
Rick Medina
@rickmed
Mar 03 2017 16:56
@xgrommx :), so :+1: ?
Brad Compton (he/him)
@Bradcomp
Mar 03 2017 16:57
R.pathEq
Brad Compton (he/him)
@Bradcomp
Mar 03 2017 16:58
@Cmdv There's also:
R.pathSatisfies
Travis LaDuke
@laduke
Mar 03 2017 18:22
Is there a general functional javascript chat gitter?
Rick Medina
@rickmed
Mar 03 2017 18:30
@laduke a million :+1: for that
all the :+1:
Travis LaDuke
@laduke
Mar 03 2017 18:31
I guess there'd need to be a repo?
Rick Medina
@rickmed
Mar 03 2017 18:33
I've talked about in the FL room, that we need a community curated list of resources for fp newcommers in js, maybe that one could be
and not newcommers
is there an awesome-fp-js repo?
Robert Mennell
@skatcat31
Mar 03 2017 18:34
why not fun-functional-js ?
Jon Gold
@jongold
Mar 03 2017 18:34
there should be if there isn't
for both
also a tldr of what/when/where to use ramda, flow, immutable, daggy, sanctuary, ramda-fantasy etc etc
Robert Mennell
@skatcat31
Mar 03 2017 18:35
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Brad Compton (he/him)
@Bradcomp
Mar 03 2017 18:35
I think you need a specific github repo in order to create a gitter...
Rick Medina
@rickmed
Mar 03 2017 18:35
I imagine it could have a learning path from the ones interested in fp and then all the resources (including libs, articles, etc)
Brad Compton (he/him)
@Bradcomp
Mar 03 2017 18:35
This is the closest thing I've found to a general JS FP chatroom
Robert Mennell
@skatcat31
Mar 03 2017 18:37
Not gonna lie, that egghead lesson plan springboarded me a ton forward. I wish I had found that sooner. Now I'm in here becasue I can't find any other real FP-JS rooms...
Travis LaDuke
@laduke
Mar 03 2017 18:37
I just wanted to complain about hackerrank giving me input that's too big to not time out when I use a map/reduce solution ;)
haven't seen that^
get the powerset of this 80K item array, then map all those...
Jon Gold
@jongold
Mar 03 2017 18:41
has anyone seen articles about time complexity of JS FP?
Stefano Vozza
@svozza
Mar 03 2017 18:42
@laduke i consider this room a general fp one, i've even asked questions about haskell that people have been glad to answer. it's a really welcoming place.
Brad Compton (he/him)
@Bradcomp
Mar 03 2017 18:46
@jongold Articles - no. I've had some discussions on it though
Space complexity too
Rick Medina
@rickmed
Mar 03 2017 19:01

get the powerset of this 80K item array

what?! isn't that 2^80k?

Brad Compton (he/him)
@Bradcomp
Mar 03 2017 19:04
Seems like a great opportunity for laziness / generators
Travis LaDuke
@laduke
Mar 03 2017 19:11
I was off googling laziness (in vanilla javascript)
Brad Compton (he/him)
@Bradcomp
Mar 03 2017 19:16
Generators are the way in ES6 to get laziness
Markus Pfundstein
@MarkusPfundstein
Mar 03 2017 19:32
@rickmed yepp :P
Robert Mennell
@skatcat31
Mar 03 2017 19:34
Curious what you mean by that?
Brad Compton (he/him)
@Bradcomp
Mar 03 2017 19:36
@skatcat31 Me?
Robert Mennell
@skatcat31
Mar 03 2017 19:36
@Bradcomp yes
Brad Compton (he/him)
@Bradcomp
Mar 03 2017 19:39

here is a really nice way to lazily produce the powerset of a set in python using generators. Now that we have generators in JS, it could be ported over basically verbatim.

Generators are really nice for lazy - forward only iterators. With the right tools you can do lazy maps and whatnot as well.

Robert Mennell
@skatcat31
Mar 03 2017 19:58
I guess that makes sense. I've always thought of generators more as a great way to allow async code to execute in a readable manner using a for..of to just step the damned thing( I use them a lot for DB or cache communications)
Gabe Johnson
@gabejohnson
Mar 03 2017 21:09
@laduke http://fpchat.com/ has a javascript channel
but free Slack orgs lose history
which sucks
Rick Medina
@rickmed
Mar 03 2017 21:17
@gabejohnson is it active? the js channel
Gabe Johnson
@gabejohnson
Mar 03 2017 21:19
@rickmed yeah. there was a long thread about static typing fp in JS today
I think a general fp in JS GitHub repo and Gitter room would be great!
Gabe Johnson
@gabejohnson
Mar 03 2017 21:24
Whoever wants it bad enough will make it. Then you can invite people. I'm sure you'll get a curated set of resources fairly quickly
someone may have already beaten you to it?
yeah...
Rick Medina
@rickmed
Mar 03 2017 21:31

@rickmed yeah. there was a long thread about static typing fp in JS today

@gabejohnson I'm interested in that!

Gabe Johnson
@gabejohnson
Mar 03 2017 21:34
@laduke @rickmed @skatcat31 you should talk to jkup
Robert Mennell
@skatcat31
Mar 03 2017 21:38
just sent off a missive. Here's hoping we hear back
Travis LaDuke
@laduke
Mar 03 2017 23:11
I just didn't want to fill up this room with my non ramda nonsense