These are chat archives for ramda/ramda
Some methods have in their documentation a sentence that says “dispatch to the X method of the second argument, if present”. I haven’t been able to find a clear explanation of what that means and what the transformation sequence would look like
How do I know for example that
head has a chain method?
Or here https://ramdajs.com/docs/#take
How do I know that a thing has a take method?
Any help would be greatly appreciated :)
takeas an example. If you have a custom type with a
takemethod, the function will use that instead of the default implementation for arrays. Here is an example of a stack, where
takepops from the end instead of takes from the beginning: https://goo.gl/19ZSF3
chain, it has a default implementation for
Function, which is why it works on
head, that doesn't have to do with dispatching. It will dispatch to custom types too though
Hey @Bradcomp, thanks for this :)
Your code snippet makes sense. Altough I’m not sure I fully understand when you say
As for chain, it has a default implementation for Array and Function, which is why it works on head
What do you mean by that? Does Ramda add a
chain method to both Array and Function prototypes?
chainoperation on Functions and Arrays.
Okay. Do you know what’s the default implementation for functions in
For example I understand why I get this:
R.chain(R.append)([1, 2, 3]); //=> [ [Function: f1], [Function: f1], [Function: f1] ]
But it still doesn’t click how I get this:
R.chain(R.append, R.head)([1, 2, 3]); //=> [ 1, 2, 3, 1 ]
If second argument is a function,
chain(f, g)(x)is equivalent to