These are chat archives for ramda/ramda

9th
Apr 2017
Tushar Mathur
@tusharmath
Apr 09 2017 11:11
Are there any alternatives to ramda-fantasy?
roshan
@roshansachan
Apr 09 2017 11:47
how to split an array into n parts with each part having a fixed number of elements var arr=['a','b','c','d','e','f','g','h']; to { 0:['a','b'], 1:['c','d'], 2:['e','f'], 3:['g','h'], }
Denis Stoyanov
@xgrommx
Apr 09 2017 11:53
spl
Splitevery
And smth else
roshan
@roshansachan
Apr 09 2017 11:57
thanks @xgrommx that's exactly what I needed.
Gabe Johnson
@gabejohnson
Apr 09 2017 13:16
@tusharmath what types do you need?
Matthew Willhite
@miwillhite
Apr 09 2017 13:26
@tusharmath Look around in the fantasy-land organization repos
Galileo Sanchez
@galileopy
Apr 09 2017 14:12
how do I force evaluation of a curried function without any parameters?
const m = R.ifElse(
  R.isNil,
  R.always({ actual: true }),
  R.objOf('station')
)
I would like to call m() and have it behave like it did get the null parameter
right now it ignores me
Matthew Willhite
@miwillhite
Apr 09 2017 14:23
@galileopy What is isNil operating on if you have no argument?
It wouldn’t be a null parameter, it would be 0 parameters
I would say…without having any context…make sure that m always receives an argument, with one of the possible values being null or undefined
Galileo Sanchez
@galileopy
Apr 09 2017 14:33
 (f1) =>(...rest)=> (res.length === 0) ?f1(null): f1(...rest)
Matthew Willhite
@miwillhite
Apr 09 2017 14:37
I think it comes down to personal taste, I tend to shy away from variadic functions :sweat_smile:
Michael Rosata
@mrosata
Apr 09 2017 14:39
@galileopy You can make a nullary function with nAry http://ramdajs.com/docs/#nAry
I believe (I have not tried it) so I should say "I think you can make a nullary function with nAry"
Matthew Willhite
@miwillhite
Apr 09 2017 14:40
m wouldn’t work as a nullary function…because isNil is not nullary
I think the variadic wrapper would probably be the most appropriate, that way m can remain simple
without having more context…
Galileo Sanchez
@galileopy
Apr 09 2017 14:43
nAry did not work , but the wrapper did
Tushar Mathur
@tusharmath
Apr 09 2017 14:47
@gabejohnson Particularly interested in the IO type.
@miwillhite I did, the lack clear documentation got me confused.
What do people generally do for handling side effects ?
Michael Rosata
@mrosata
Apr 09 2017 14:51
@galileopy What about
const m = R.unapply(R.ifElse(
  R.isNil,
  R.always({ actual: true }),
  R.objOf('station')
));
Galileo Sanchez
@galileopy
Apr 09 2017 14:55
that's a bit more obscure, because isNil should now be isEmpty
but it works too
Michael Rosata
@mrosata
Apr 09 2017 14:58
true
Michael Rosata
@mrosata
Apr 09 2017 15:04
The wrap might be simplified to (f1) => (args=null) => f1(args)
Galileo Sanchez
@galileopy
Apr 09 2017 15:10
thanks that's very cool
Michael Rosata
@mrosata
Apr 09 2017 15:10
:smile:
Mick Dekkers
@mickdekkers
Apr 09 2017 19:24
Is there a way to add a property to an object derived from another property on that object, but only if that property is present?
I'm using applySpec right now but I don't see a way to not add a property if one of the 'dependencies' is missing
Michael Rosata
@mrosata
Apr 09 2017 19:25
but I think it would require a side-effect to achieve with evolve
Mick Dekkers
@mickdekkers
Apr 09 2017 19:26
I'm not sure how it would be different with evolve
I don't see how not to add a property if it's missing on the original object :p
Michael Rosata
@mrosata
Apr 09 2017 19:29
well applySpec passes your arguments to every property on the spec object, evolve ignores properties that don't exist on the transform/spec object
Mick Dekkers
@mickdekkers
Apr 09 2017 19:32

This is how I'm using applySpec

With e.g. this object:

const obj = {
  maybeMissing: 2,
  alwaysThere: 1
}

with applySpec I could then do:

R.applySpec({
  result: R.converge(
    R.add,
    [
       R.prop('maybeMissing'),
       R.prop('alwaysThere')
    ]
  )
})(obj)
which results in
{
  result: 3
}
but in this example I would like to output an empty object (one without the result property) if maybeMissing is missing on the original object
I'm wondering if that's possible somehow (perhaps using something other than applySpec)
Casey Link
@Ramblurr
Apr 09 2017 19:56
Herm, is my understanding of how R.maxBy should work wrong?
R.reduce(R.maxBy(R.length), 0, ["one", "two", "three", "longeststring"]);
// expected -> longeststring
// actual -> 0
Michael Rosata
@mrosata
Apr 09 2017 19:59
@SoullessWaffle this does what you want but I think it could be better than this:
const sumFromObj = R.converge(R.add,[R.prop('maybeMissing'), R.prop('alwaysThere')])
const doIt = R.ifElse(
  R.has('maybeMissing'),
  o => R.assoc('maybeMissing', sumFromObj(o), o),
  R.identity
)
// with
doIt({maybeMissing: 200, alwaysThere: 777})
// without
doIt({alwaysThere: 4949})
@Ramblurr R.reduce(R.maxBy(R.length), '', ["one", "two", "three", "longeststring"])
Mick Dekkers
@mickdekkers
Apr 09 2017 20:01
Thanks @mrosata, that's a good start! :D
Michael Rosata
@mrosata
Apr 09 2017 20:02
@Ramblurr because R.length(0) is undefined
no problem @SoullessWaffle. I know there must be a Ramda function that would be shorter in the place of that lambda, but I can't find one
Casey Link
@Ramblurr
Apr 09 2017 20:03
Ah of course :\ Thanks :clap:
Brad Compton (he/him)
@Bradcomp
Apr 09 2017 20:16
@SoullessWaffle @mrosata R.ifElse(pred, f, identity) is the same as:
R.when
Michael Rosata
@mrosata
Apr 09 2017 20:17
@Bradcomp thanks!
updated:
const doIt = R.when(
  R.has('maybeMissing'),
  R.converge(R.add,[R.prop('maybeMissing'), R.prop('alwaysThere')]),
  R.identity
)
Johnny Hauser
@m59peacemaker
Apr 09 2017 22:13
You don't need the identity :)
ifElse(ifThisThing, doThis, othewiseDoThis)
ifElse(ifThisThing, doThis, identity) // otherwise don't do anything
when(ifThisThing, doThis) // same thing (don't do anything if the predicate returned false... i.e. just return `identity`)
Nate Martin
@NateTheGreatt
Apr 09 2017 23:34
hello all
does anyone have experience creating a directory walk function with ramda?
Matthew Willhite
@miwillhite
Apr 09 2017 23:57
I've walked XML, do you have a specific question?