These are chat archives for ramda/ramda

3rd
May 2016
Drew
@dtipson
May 03 2016 02:10
@dypsilon I think it's in the works, or at least being looked into
to me, compose makes more sense now because thanks to FP in general, I think of the argument coming in from the right to left, once all the functions are squashed down together and it's called as one function
David Langford
@That-David-Guy
May 03 2016 02:29
@dypsilon , @dtipson , I'm still new to it. But I found compose easier to get my head around than pipe because right to left is how the data flows through the arguments as well (in my mind). When I think of map(fn, data), I think 'The data is passed into the fn (though one at a time), then another array is spat out`, which is right to left. So compose I find just follows that at a higher level.
Though if its multiple lines of code like the example above, I could see pipe being better. So compose for 1 line, pipe for multi. But that could just be silly
Drew
@dtipson
May 03 2016 02:49
no, I think that's pretty close to how to envision it, including finding pipe easier to think about for longer sequences, especially asynchronous ones. Honestly, my mental model of what is happening probably often colors what feels right :)
David Langford
@That-David-Guy
May 03 2016 03:11
I know that feeling! @dtipson
David Langford
@That-David-Guy
May 03 2016 06:41
I'm a bit stuck on trying to improve this code. Its working, but its not point-free and I don't think it's very clear what is going on. Any ideas?
@ram-bot
const data = [1, 5, 10, 25]
const toAdd = 5

const maxSort = R.sort(R.gt)
const getNewArray = R.compose(maxSort, R.concat(R.of(toAdd)), R.init)
const shouldNotAdd = x => R.find(R.equals(x), data)
const handleArray = 
  R.ifElse(shouldNotAdd, ()=>data, ()=>getNewArray(data))

handleArray(toAdd)


// Second arugment has to always be included in array
// ([1, 5, 10, 25], 36)         => [1, 5, 10, 36]
// ([1, 5, 10, 25], 11)         => [1, 5, 10, 11]
// ([1, 5, 10, 25],  3)         => [1, 3,  5, 10]
// Below are the scenarios when I don't want it to be included
// ([1, 5, 10, 25],  5)         => [1, 5, 10, 25]
// ([1, 5, 10, 25],  undefined) => [1, 5, 10, 25]
ram-bot
@ram-bot
May 03 2016 06:41
[ 1, 5, 10, 25 ]
David Langford
@That-David-Guy
May 03 2016 07:42
Although in my code, undefined and null doesn't return the correct result (the comments say the wanted result)
Tim Navrotskyy
@dypsilon
May 03 2016 11:24
What do you think about monet.js library? Is it good for using together with Ramda?
Scott Sauyet
@CrossEye
May 03 2016 11:44
I haven't used monet. It looks as though it would be FantasyLand-compatible, so it should work with Ramda functions such as map, ap, and chain.
Tim Navrotskyy
@dypsilon
May 03 2016 12:20
@CrossEye thank you for your input
Could you point me to some tutorials/examples on how to do side effects in functional javascript. I've read the mostly adequate guide, but I still don't have the tools to write functional programs.
Scott Sauyet
@CrossEye
May 03 2016 12:34
Well, generally, avoiding side-effects is a main goal of FP. I would look to other of DrBoolean's work for examples of how to restrict side-effects to the very edges of your system. But I don't have any particular examples at hand.
Brad Compton (he/him)
@Bradcomp
May 03 2016 13:30
@That-David-Guy Here's what I came up with: http://goo.gl/Wo3wKt
Not entirely point free, but you can see it handles all the test cases :-D
Scott Sauyet
@CrossEye
May 03 2016 13:44
A
And this is mine: http://goo.gl/ZogyiX, points-free, but of debatable readability.
Brad Compton (he/him)
@Bradcomp
May 03 2016 13:47

points-free, but of debatable readability.

But lots of fun!

Scott Sauyet
@CrossEye
May 03 2016 13:54
A slighly more readable version: http://goo.gl/qyCkCb
Brad Compton (he/him)
@Bradcomp
May 03 2016 13:55
@ram-bot
R.equals(concat([1,2,3], [4]), concat([1,2,3], 4))
ram-bot
@ram-bot
May 03 2016 13:55
TypeError: [1, 2, 3] does not have a method named "concat"
Brad Compton (he/him)
@Bradcomp
May 03 2016 13:56
@ram-bot
R.equals(R.concat([1,2,3], [4]), R.concat([1,2,3], 4))
ram-bot
@ram-bot
May 03 2016 13:56
TypeError: [1, 2, 3] does not have a method named "concat"
Brad Compton (he/him)
@Bradcomp
May 03 2016 13:56
Huh, that's weird
Scott Sauyet
@CrossEye
May 03 2016 13:56
@Bradcomp : Yours is nice. I always forget about unless.
Brad Compton (he/him)
@Bradcomp
May 03 2016 13:56
Works in the REPL
Scott Sauyet
@CrossEye
May 03 2016 13:57
A few weird things here with the bot. I know there are problems with `is1.
is
Brad Compton (he/him)
@Bradcomp
May 03 2016 13:58
Is it desirable that concat([1,2,3], 4) and concat([1,2,3], [4]) evaluate to the same thing?
Scott Sauyet
@CrossEye
May 03 2016 13:59
Yes, of course. I think it's an artifact of how the bot runs.
Lorenzo Giuliani
@aliem
May 03 2016 14:00

Hi! Can I use R.__ is any way in this situation? I tryed to replace Key with the placeholder but it didn't really work (the filter function is already evaluated and expect two parameters instead of one)

const getClientInstance = (key, instances) => R.compose( R.pick(['id', 'key']), R.filter(R.propEq('key', key)) )(instances);

R.compose(R.pick(['prop1', 'prop2']), R.filter(R.propEq('key', R.__))
Brad Compton (he/him)
@Bradcomp
May 03 2016 14:03

Yes, of course. I think it's an artifact of how the bot runs.

Maybe I just need more time in FP land... I thought concat was for two arrays (or semigroups) and append would stick a value onto an array...

I didn't expect concat([1,2,3], 4) to work
Raine Virta
@raine
May 03 2016 14:04
it works because that's how Array#concat works
Brad Compton (he/him)
@Bradcomp
May 03 2016 14:07
Thanks @raine
Scott Sauyet
@CrossEye
May 03 2016 14:07
sorry , I was missing the point.
Brad Compton (he/him)
@Bradcomp
May 03 2016 14:09
No prob, I probably just worded the question ambiguously
Scott Sauyet
@CrossEye
May 03 2016 14:09
@aliem: a placeholder as the last-supplied parameter doesn't really do anything.
Lorenzo Giuliani
@aliem
May 03 2016 14:09
R.propEq takes 3 arguments
Scott Sauyet
@CrossEye
May 03 2016 14:11
Right, but when you call fn(param1, R.__, param3) the system can make sense of it. When you call fn(param1, R.__) it doesn't really know what you mean.
Lorenzo Giuliani
@aliem
May 03 2016 14:11
I'm just thinking on how to make it a bit nicer instead of wrapping it in a function
Raine Virta
@raine
May 03 2016 14:13
R.pipe(R.useWith(R.filter, [ R.propEq('key'), identity ]), R.pick(['id', 'key'])) // untested
Scott Sauyet
@CrossEye
May 03 2016 14:13
understood, and unfortunately I have to go now, but I will look at it when I get back online. It doesn't look bad to me like that. Even with what I just did above, I don't think points-free should be much of a goal on its own.
or just pay attention to raine. :smile:
Lorenzo Giuliani
@aliem
May 03 2016 14:14
thank you!
Chet Harrison
@ChetHarrison
May 03 2016 16:52
@Bradcomp I learned last week that if something works in the REPL and doesn't somewhere else they may be running different versions of the lib
Brad Compton (he/him)
@Bradcomp
May 03 2016 16:53
@ChetHarrison Good point!
@ram-bot
[1,2,3].concat(4)
ram-bot
@ram-bot
May 03 2016 16:53
[ 1, 2, 3, 4 ]
Brad Compton (he/him)
@Bradcomp
May 03 2016 16:53
Well that works!
Chet Harrison
@ChetHarrison
May 03 2016 16:53
might as well benefit from my lost day of brain damage
:sparkles:
Brad Compton (he/him)
@Bradcomp
May 03 2016 16:54
@ram-bot
R.concat([1,2,3], 4)
ram-bot
@ram-bot
May 03 2016 16:54
TypeError: [1, 2, 3] does not have a method named "concat"
Brad Compton (he/him)
@Bradcomp
May 03 2016 16:55
It's the error itself that weirds me out though. [1,2,3] certainly does have a method named concat. Maybe older versions didn't check the prototype?
David Chambers
@davidchambers
May 03 2016 16:56
See #1670 for details, @Bradcomp. I've been saying for some time that we need to remove all the instanceof checks from Ramda. If you agree, please comment on the issue. ;)
Brad Compton (he/him)
@Bradcomp
May 03 2016 17:00
@ram-bot
R.join("-", ["foo", "bar", "baz"])
Well that didn't do anything. Now I see what the issue is though. Thanks @davidchambers!
David Chambers
@davidchambers
May 03 2016 17:02
Yep. As a rule, it's best to avoid instanceof.
Lewis
@6ewis
May 03 2016 20:00
@Bradcomp funny enough, i had this error in my code today (the downside of ramda is definitely debugging IMO)
@ram-bot
R.concat([1,2,3],[4])
Brad Compton (he/him)
@Bradcomp
May 03 2016 20:02
@ram-bot
2 + 2
ram-bot
@ram-bot
May 03 2016 20:02
4
Brad Compton (he/him)
@Bradcomp
May 03 2016 20:02
huh
Lewis
@6ewis
May 03 2016 20:03
@Bradcomp concat expect arrays as args
David Chambers
@davidchambers
May 03 2016 20:06
That's true, @6ewis, though R.concat doesn't complain if misused:
R.concat([1, 2, 3], 4);
// => [1, 2, 3, 4]
S.concat (available on master but yet to be included in a release) does complain if misused:
S.concat([1, 2, 3], 4);
// ! TypeError: Type-class constraint violation
//
//   concat :: Semigroup a => a -> a -> a
//             ^^^^^^^^^^^         ^
//                                 1
//
//   1)  4 :: Number, FiniteNumber, NonZeroFiniteNumber, Integer, ValidNumber
//
//   ‘concat’ requires ‘a’ to satisfy the Semigroup type-class constraint; the value at position 1 does not.
Brad Compton (he/him)
@Bradcomp
May 03 2016 20:09
Exactly. Concat should accept two arguments of the same type. The Javascript Array method will accept a different type for the second argument. My question above was whether that was desirable behavior for R.concat and I think the answer is "not desired, but it's fine."
@davidchambers That's pretty cool! I like that Sanctuary has those guarantees.

https://github.com/fantasyland/fantasy-land#semigroup

If b is not the same semigroup, behaviour of concat is unspecified.

Lewis
@6ewis
May 03 2016 21:32
can we use sanctuary in production
@Bradcomp how did you get [1, 2, 3] does not have a method named "concat that error
David Chambers
@davidchambers
May 03 2016 21:34

can we use sanctuary in production

Someone posed this question in the Sanctuary room earlier today, @6ewis. I suggest reading my response there.

@ram-bot
R.concat([1, 2, 3], [4])
ram-bot
@ram-bot
May 03 2016 21:35
TypeError: [1, 2, 3] does not have a method named "concat"
David Chambers
@davidchambers
May 03 2016 21:36
See #1670 if you're interested in understanding this error, @6ewis.
Lewis
@6ewis
May 03 2016 21:38
so it does complain if misused @davidchambers
David Chambers
@davidchambers
May 03 2016 21:39
R.concat does, do you mean?
Lewis
@6ewis
May 03 2016 21:39
yes
David Chambers
@davidchambers
May 03 2016 21:40
In fact, R.concat([1, 2, 3], [4]) is a valid expression which should evaluate to [1, 2, 3, 4].
Lewis
@6ewis
May 03 2016 21:40
sorry I got confused
I meant R.concat([1,2,3], 4)
@ram-bot
R.concat([1,2,3], [4])
ram-bot
@ram-bot
May 03 2016 21:41
TypeError: [1, 2, 3] does not have a method named "concat"
Lewis
@6ewis
May 03 2016 21:41
@ram-bot
R.concat([1,2,3],4)
ram-bot
@ram-bot
May 03 2016 21:41
TypeError: [1, 2, 3] does not have a method named "concat"
Lewis
@6ewis
May 03 2016 21:42
@davidchambers it does complain about both, the latter is right but not the former
David Chambers
@davidchambers
May 03 2016 21:42
What you're seeing there is the result of the bug I mentioned earlier (#1670).
So R.concat is currently incompatible with @ram-bot, unfortunately.
Brad Compton (he/him)
@Bradcomp
May 03 2016 21:43
R.concat
Lewis
@6ewis
May 03 2016 21:43
I got this error in my code just today, i couldn't use R.concat, spent 20min debugging
David Chambers
@davidchambers
May 03 2016 21:43
But, we can test the behaviour locally in a REPL:
> R.concat([1, 2, 3], [4])
[1, 2, 3, 4]

> R.concat([1, 2, 3], 4)
[1, 2, 3, 4]
Michael Hurley
@buzzdecafe
May 03 2016 21:44
ya that seems bad
David Chambers
@davidchambers
May 03 2016 21:44
What does, @buzzdecafe?
Michael Hurley
@buzzdecafe
May 03 2016 21:45
the second example
R.concat([1, 2, 3], [4]) :+1:
R.concat([1, 2, 3], 4) :-1:
that should be an error
David Chambers
@davidchambers
May 03 2016 21:45
Yes, but it's in keeping with Ramda's philosophy of letting type errors propagate silently. :P
Michael Hurley
@buzzdecafe
May 03 2016 21:46
now don't get snooty
David Chambers
@davidchambers
May 03 2016 21:46
I'd love to add type checking of some sort to Ramda.
Michael Hurley
@buzzdecafe
May 03 2016 21:47
i would rather it fail
i know; and i see the value
i just don't find run-time type-checking to be an interesting problem
David Chambers
@davidchambers
May 03 2016 21:48
You've described type checking as hand-holding in the past. Are your thoughts on the matter changing or is type checking more important for R.concat than for other functions due to its connection to Fantasy Land?
Michael Hurley
@buzzdecafe
May 03 2016 21:48
i'm probably changing my POV a bit.
Brad Compton (he/him)
@Bradcomp
May 03 2016 21:48
Looking at the implementation, all concatdoes is just (a, b) => a.concat(b) so it is stuck with accepting the semantics of whatever object is passed as the first parameter, unless it performs some sort of type checking.
Michael Hurley
@buzzdecafe
May 03 2016 21:49
we could exclude array in there though. that would solve it. we do that for map e.g.
Brad Compton (he/him)
@Bradcomp
May 03 2016 21:50
Array#concat doesn't meet the FL spec, as [1].concat(2).concat(3) !== [1].concat(2.concat(3))
Michael Hurley
@buzzdecafe
May 03 2016 21:50
This message was deleted
@Bradcomp good point. current impl looks like a bug to me
Brad Compton (he/him)
@Bradcomp
May 03 2016 21:51
I would probably be okay with special casing arrays
Not that my opinion should really matter too much ;-P
Michael Hurley
@buzzdecafe
May 03 2016 21:52
on the contrary
Brad Compton (he/him)
@Bradcomp
May 03 2016 21:52
Should I open an issue?
Michael Hurley
@buzzdecafe
May 03 2016 21:52
@Bradcomp please do
@davidchambers at the time ramda started i was tinkering with erlang a lot.
erlang's philosophy is "let it fail" and i liked that a lot
that's what i have meant by "hand-holding" in the past. i am not interested in guaranteeing that you gave me correct input.
something like the problem with R.concat is different, because its API is .... just not right
it won't fail if you give it weird input
David Chambers
@davidchambers
May 03 2016 21:55
Exactly!
Michael Hurley
@buzzdecafe
May 03 2016 21:56
i'm always pleased when we find common ground :-)
David Chambers
@davidchambers
May 03 2016 21:57
In many cases we have "let is succeed with an erroneous result" rather than "let it fail". I'm very much in favour of letting things fail. In JavaScript, though, we actually have to do quite a bit of work to ensure that things fail.
I enjoy finding common ground too!
Brad Compton (he/him)
@Bradcomp
May 03 2016 22:01
R.invoker
David Langford
@That-David-Guy
May 03 2016 23:08
@Bradcomp , @CrossEye Thanks! I'll have a look at it today. I'm in Brisbane Australia, so I think our timezones are bit off.