fewer-lambdas

1.0.1 • Public • Published

ƒewer-lambdas

ƒ references

This steals heavily from the folowing:

phrogz's fewer lambdas

roadtolarissa's even fewer lambdas

d3-jetpacks's implementation

ƒ usage

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.

ƒ Examples

Identity function

Given an array

[1,2,3,4,...].map(function(d){ return d})

becomes

[1,2,3,4,...].map(ƒ())

Object properties

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'))

Function composition

The following

data.map(function(d){ return parseInt(d.value)})

becomes

data.map(ƒ('value',parseInt))

Fat arrow

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))

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    1
  • 1.0.0
    1
  • 0.0.1
    1
  • 0.0.0
    1

Package Sidebar

Install

npm i fewer-lambdas

Weekly Downloads

4

Version

1.0.1

License

MIT

Last publish

Collaborators

  • blacki