These are chat archives for ramda/ramda

6th
Jan 2017
hemanth.hm
@hemanth
Jan 06 2017 03:04
map your tap
Tushar Mathur
@tusharmath
Jan 06 2017 05:15
Yeah, this works except when R.tap only logs functions.
Tushar Mathur
@tusharmath
Jan 06 2017 14:40
what's the simplest way to replace this with ramda —
const thisOrThat = R.curry(<T> (v0: T, v1: T, cond: boolean) => {
  return cond ? v0 : v1
})
Brenton Alker
@tekerson
Jan 06 2017 14:44
R.ifElse ?
Denis Stoyanov
@xgrommx
Jan 06 2017 15:04
ifElse(cond, always(v0), always(v1))
ifElse(cond, ...map(always)([v0, v1])) :smile:
Brandon Booth
@texasrocks23_twitter
Jan 06 2017 16:19
I'm trying to select objects from different levels and can't figure out how to make it work in general. It works if I create separate functions for each path I want (i.e. path(['name','first'], path['state'], etc.) and then applySpec with the list. I'm trying to make it more general so that I can pass a list of paths (i.e. ['name.first', 'state', 'zip'] and get back a subset of the data. Basically, project for different levels. Any suggestions?
Denis Stoyanov
@xgrommx
Jan 06 2017 17:22
@texasrocks23_twitter lenses?
Tushar Mathur
@tusharmath
Jan 06 2017 17:38
@tekerson @xgrommx v0 and v1 have to be arguments to that function.
Denis Stoyanov
@xgrommx
Jan 06 2017 17:42
@tusharmath and cond?
Tushar Mathur
@tusharmath
Jan 06 2017 17:43
that might work, let me try.
 R.cond([
  [R.nthArg(2),   R.nthArg(1)],
  [R.T, R.nthArg(0)]
])
Gabe Johnson
@gabejohnson
Jan 06 2017 18:10
Does anyone use ap for using the same input for multiple side-effects?
ap([sendToServer, displayOnScreen], [stuff])
Is there another way that makes more sense?
Jethro Larson
@jethrolarson
Jan 06 2017 23:41
Why doesn't reduce work on objects?
is there another way to fold them?
Nick Acker
@ackerdev
Jan 06 2017 23:42
reduce only operates on lists, and objects aren't lists
Jethro Larson
@jethrolarson
Jan 06 2017 23:42
I mean strategically
Nick Acker
@ackerdev
Jan 06 2017 23:42
you can create a list like by pulling all keys or values, or creating pairs...
depends on your particular goal, probably
Jethro Larson
@jethrolarson
Jan 06 2017 23:43
I mean from a library design perspective
Nick Acker
@ackerdev
Jan 06 2017 23:43
what behavior do you expect reduce to have
it's not the same as something like map
map can iterate over values as the semantics can imply it's going to keep a identical structure
you can't so much "reduce" values, as it would be identical to mapping
Jethro Larson
@jethrolarson
Jan 06 2017 23:48
(b -> a -> String -> b) -> b -> Object a -> b
Objective is not to get an object back but to fold an object
Nick Acker
@ackerdev
Jan 06 2017 23:50
a -> String what is a and String here?
Jethro Larson
@jethrolarson
Jan 06 2017 23:50
a is anything, string is the key
Nick Acker
@ackerdev
Jan 06 2017 23:51
that would create an inconsistent reducer parameter list
Jethro Larson
@jethrolarson
Jan 06 2017 23:51
nah, it's roughly the sig of Array.prototype.reduce
Nick Acker
@ackerdev
Jan 06 2017 23:52
ramda doesn't provide indexes/keys by default, intentionally
Jethro Larson
@jethrolarson
Jan 06 2017 23:52
I know.
if keys are ommitted from the sig you have:
(b -> a -> b) -> b -> Object a -> b
Which is almost exactly like reduce for lists
Nick Acker
@ackerdev
Jan 06 2017 23:54
You can utilize values for that
reduce(reducer, acc, values(obj))
Jethro Larson
@jethrolarson
Jan 06 2017 23:54
yes, or pairs
I'm not incapable of solving the problem I was just wondering if there was a philosophical reason Ramda is choosing to not reduce Objects