hughfdjackson / const

the constant function.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

const

The constant function from functional programming: it takes a value and returns a function that will return that value:

var constant = require('const')
var alwaysA = constant('a');

alwaysA() //= 'a'

Useful to lifting a value into the world of functions, e.g. when using promises:

getUserDetails()
	.then(getMessageFromUser, constant('User not found'))

Other names it's gone by in the past:

  • K combinator
  • lift
  • always

About

the constant function.


Languages

Language:JavaScript 100.0%