javascript - Understanding Ramda.js -


question 1:

   var _curry1 = function _curry1(fn) {         return function f1(a) {             if (arguments.length === 0) {                 return f1;             } else if (a != null && a['@@functional/placeholder'] === true) {                 return f1;             } else {                 return fn.apply(this, arguments);             }         };     }; 

what purpose of checking a['@@functional/placeholder'] === true ?

question 2:

http://ramdajs.com/0.18.0/docs/#reduce

how read notation?

(a,b -> a) -> -> [b] -> a

this first time seeing such notation, come from?

question 1:

there no "notation". __.js should clear up:

module.exports = {'@@functional/placeholder': true}; 

so @@functional/placeholder no different foo in

a = { foo: true } a.foo a["foo"] 

(obviously, can't write a.@@functional/placeholder because of odd symbols there.)

the intent seen in file:

/**  * special placeholder value used specify "gaps" within curried functions,  * allowing partial application of combination of arguments,  * regardless of positions.  *  * if `g` curried ternary function , `_` `r.__`, following equivalent:  *  *   - `g(1, 2, 3)`  *   - `g(_, 2, 3)(1)`  *   - `g(_, _, 3)(1)(2)`  *   - `g(_, _, 3)(1, 2)`  *   - `g(_, 2, _)(1, 3)`  *   - `g(_, 2)(1)(3)`  *   - `g(_, 2)(1, 3)`  *   - `g(_, 2)(_, 3)(1)`  ... 

so intent able "skip" places when currying. test decides whether argument real argument or __.js placeholder, , behaves accordingly. why @@functional/placeholder - presumably precisely because hoped weird, , not collide anyone's legitimate data.

question 2:

the notation standard in type theory, , popularised haskell. a , b types. (...) tuple of types, [a] list elements a. a -> b function takes argument of type a , yields return of type b, , right-associative. example in question reads:

it function takes argument function takes 2 arguments (of types a , b respectively) , returns value of type a; , yields function takes argument of type a , returns function takes argument list of elements of type b, returning value of type a.

this reads confusingly, uncurried description bit easier: function takes 3 arguments: first 1 being function (as described above), second 1 being value of a, third 1 being list of b elements, , returns value of a.

specifically, r.reduce such function: in

r.reduce(add, 10, numbers); 

add function takes 2 integers (both a , b being same, integer), , returns integer ((a, b) -> a); 10 of type integer (a); numbers list of integers ([b]); , return value integer (a).

note mixes curried , uncurried syntax; if curried, add a -> b -> a, not (a, b) -> a.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -