These are chat archives for ramda/ramda

24th
Feb 2017
Galileo Sanchez
@galileopy
Feb 24 2017 00:00
thanks @syaiful6
:) still confused but I'll keep thinking about this later
Brian McKenna
@puffnfresh
Feb 24 2017 00:20
fold ["a", "b", "c"] = "abc"
fold (Just "Hello") = "Hello"
fold Nothing = ""
Tushar Mathur
@tusharmath
Feb 24 2017 03:22
@dtipson not denying that. I think someone in this group recommend that its a performance killer. I have not benchmarked it though.
hemanth.hm
@hemanth
Feb 24 2017 05:34
lodash.get({}, 'a.b.c',0) simpler equivalent in ramad?
pickAB = R.compose(R.pick(['a']), R.path(['b'])); ?
Brad Compton (he/him)
@Bradcomp
Feb 24 2017 05:39
@ram-bot
path(['a', 'b', 'c'], {a: {b: {c: 123}}});
ram-bot
@ram-bot
Feb 24 2017 05:39
123
Brad Compton (he/him)
@Bradcomp
Feb 24 2017 05:40
@ram-bot
pathOr(0, ['a', 'b', 'c'], {a: {b: {}}});
ram-bot
@ram-bot
Feb 24 2017 05:40
0
hemanth.hm
@hemanth
Feb 24 2017 05:45
@Bradcomp sweet, R.pathOr! sweet, R.pathOr(0, "a.b.c".split('.'), {a : {b: {c: 3}}, d: 4}); in the code I am refactoring with ramda.
Brad Compton (he/him)
@Bradcomp
Feb 24 2017 05:45
:+1:
hemanth.hm
@hemanth
Feb 24 2017 05:46
not sure how I missed R.pathOr
R.pathOr Added in v0.18.0
Vincent Orr
@Cmdv
Feb 24 2017 10:27
trying to make sure that an array always has 4 items in it:
[[1,2,3,4], [1,2]] -> [[1,2,3,4],[1,2,null,null]]
how would I go about approaching this problem
James Forbes
@JAForbes
Feb 24 2017 11:21
@Cmdv you could R.concat( R.__, [null,null,null,null]) and then slice the first 4 R.take(4)
Something like this should work
const always4 =
  pipe(
   concat(__, repeat(null, 4)),
   take(4)
  )
actually...
const always4 =
  pipe(
   concat(repeat(null, 4)),
   takeLast(4)
  )
No placeholder :) @Cmdv
Markus Pfundstein
@MarkusPfundstein
Feb 24 2017 11:29
why would you want this? mixing null with Integers is not a good idea
James Forbes
@JAForbes
Feb 24 2017 11:38
I'm assuming the actual problem space is a lot more complicated, and the core of the question isn't specifically about null
Bravi
@Bravilogy
Feb 24 2017 12:48
Hi guys. I'm practicing with type signatures and I was wondering if this signature is correct?
// :: [Object] -> String -> Object | {}
const fetchByType = curry((target, type) =>
  find(where({
    types: contains(type),
  }))(target)
);
Markus Pfundstein
@MarkusPfundstein
Feb 24 2017 13:02
the return value can just be Object I guess, as {} is an object
Bravi
@Bravilogy
Feb 24 2017 13:07
is the rest ok?
so basically target will be an array of objects, type is a string and the result will be an object
Bravi
@Bravilogy
Feb 24 2017 13:16
and the full fn
// :: Object -> Object
const buildAddressObject = address => {
  const paths = {
    street: ['street_number', 'route'],
    city: ['administrative_area_level_1'],
    state: ['country'],
    zip: ['postal_code'],
  };
  // :: [Object] -> String -> Object | {}
  const findByType = curry((target, type) =>
    find(where({
      types: contains(type),
    }))(target)
  );
  // :: String -> String
  const getAddress = compose(prop('long_name'), findByType(address));
  // :: [String] -> String
  const combineAddresses = compose(join(' '), map(getAddress));
  // :: Object -> String -> Object
  const reducer = curry((prev, current) =>
    merge(prev, combineAddresses(prop(current, paths))));

  return compose(reduce(reducer, {}), keys)(paths);
};
Vincent Orr
@Cmdv
Feb 24 2017 13:59
@JAForbes thank you that is perfect and what I was after!! was stuck as I didn't use pipe
James Forbes
@JAForbes
Feb 24 2017 14:01
anytime, glad to be of use :)
Vincent Orr
@Cmdv
Feb 24 2017 14:14
oh slight issue, wanted the nulls to come after [1,2,null,null] but the other challenge now is I have them nested!!
I came up with this:
const newDraws = draws.map((item, i) => {
      const check = (i) => item[i] ? item[i] : null
      return times(check, 4)
    })
could be a one liner but not many Ramda users here :P
I'm sure it could be a lot cleaner! it is basically making a grid system so every 4 make a new row but if there are some missing make them null. It's inside a react-native app where it uses flex. So if blocks are missing the ones present stretch across
so: [[1,2,3,4],[1,2]] -> [[1,2,3,4],[1,2,null,null]]
Aldwin Vlasblom
@Avaq
Feb 24 2017 14:19
Something like draws.map(draw => draw.concat(repeat(null, 4 - draw.length)))
Vincent Orr
@Cmdv
Feb 24 2017 14:25
@Avaq that's nice :)
Rick Medina
@rickmed
Feb 24 2017 14:25
@Bravilogy I personally use names for "known" objects instead of "Object". eg: customerAddress, [customerAddress], customerFullName, etc...makes it a bit easier to align for me, specially if you are using daggy or something like that.
doesn't find return undefined on the left?
Bravi
@Bravilogy
Feb 24 2017 14:26
good point, need to check
thanks
James Forbes
@JAForbes
Feb 24 2017 14:33
the first example with the concat(__) and the take(4) should work too @Cmdv
Vincent Orr
@Cmdv
Feb 24 2017 14:36
ah cool I never tried it sorry @Avaq
Matthew Willhite
@miwillhite
Feb 24 2017 21:45
@Bravilogy I’ve found I like to describe the objects I’m returning as well, so something like:
-> { street : String, city : String, state : String, zip : String }
Markus Pfundstein
@MarkusPfundstein
Feb 24 2017 21:46
Why not make Type?
Matthew Willhite
@miwillhite
Feb 24 2017 21:47
Well sure that would be ideal :)
Markus Pfundstein
@MarkusPfundstein
Feb 24 2017 21:47
Then you could say, const Address = daggy.tagged(‘Address’, [‘street’, ‘city’, ’state’, zip’])
Matthew Willhite
@miwillhite
Feb 24 2017 21:47
But it looks like daggy isn’t being used, so…at least you can describe your Object types a little better
Markus Pfundstein
@MarkusPfundstein
Feb 24 2017 21:47
and then a -> b -> Address
Matthew Willhite
@miwillhite
Feb 24 2017 21:47
because Object -> Object doesn’t say much
Markus Pfundstein
@MarkusPfundstein
Feb 24 2017 21:47
nope
Matthew Willhite
@miwillhite
Feb 24 2017 21:48
+1 @MarkusPfundstein though, daggy is a fantastic way to give your objects shape
Markus Pfundstein
@MarkusPfundstein
Feb 24 2017 21:48
yepp, it also supports recursive types :thought_balloon:
Markus Pfundstein
@MarkusPfundstein
Feb 24 2017 22:02
var Shape = Type({
Circle: [Number, Point],
Rectangle: [Point, Point]
});
where var Point = Type({Point: {x: Number, y: Number}});
this is even more expressive
Matthew Willhite
@miwillhite
Feb 24 2017 22:04
yep, I’ve used that before as well…also very nice!!