This steals heavily from the folowing:
roadtolarissa's even fewer lambdas
var ƒ = require('fewer-lambdas')
Note the function name ƒ
is a legal JavaScript identifier. This character is easy to type in OSX by using option + f
.
ƒ
takes a string|number and returns a function that takes an object and returns whatever property the string is named.
This lets you replace function(d){ return ... }
ECMAScript 5 lambda function syntax with the shorter easy to use ƒ(...)
function.
Given an array
[1,2,3,4,...].map(function(d){ return d})
becomes
[1,2,3,4,...].map(ƒ())
Given an array of objects
var data = [
{
key:'0',
value:0.00
},
{
key:'1',
value:1.11
},
{
key:'2',
value:2.22
},
...
]
The following
data.map(function(d){ return d.value})
becomes
data.map(ƒ('value'))
The following
data.map(function(d){ return parseInt(d.value)})
becomes
data.map(ƒ('value',parseInt))
Combine this with Es6 fat arrow functions and things get even shorter
data.map(ƒ('value', JSON.stringify, d => d.split('.'), d => d.join(''), d => +d))