0.4.0 • Published 11 years ago

op-lift v0.4.0

Weekly downloads
2
License
-
Repository
github
Last release
11 years ago

op-lift

Turn js operators into delicious first-class functions.

Example

var lift = require('op-lift')

;[1, 2, 3, 4].reduce(lift.infix('+')) //= 10

Install & Test

install via npm: npm install op-lift test: cd node_modules/op-lift && npm test

API

lift.infix(String) -> Function

lift takes a string, representing an infix operator, and returns a function that performs the same job.

var lift = require('op-lift')

;[1, 2, 3, 4].reduce(lift.infix('*')) //= 24

Supported operators:

The supported operators are: * / % + - << >> >>> < > <= >= instanceof in == != === !== & ^ | || && . ,

lift.prefix(String) -> Function

Identical to lift.infix, except it returns functions taking a single argument:

var neg = lift.prefix('!')

;[true, false, true].map(neg) //= [ false, true, false ]
var instantiate = lift.prefix('new'),
    type        = lift.prefix('typeof')

;[Object, Array, Function].map(instantiate).map(type) //= [ 'object', 'object', 'function' ]

Supported opertors:

The supported operators are: void typeof ++ -- + - ~ ! new

lift.postfix(String) -> Function

Just for the sake of completeness, the postfix operators are included; neither of which do anything useful, since the 'magic' they do is sandboxed:

var i       = 0,
    postInc = lift.postfix('++')
    
postInc(i) //= 0
i          //= 0

Supported operators:

The supported operators are: ++ --

Tastes great with..

Since the primary difference between operators and functions is that functions are first class, op-lift works very well with libraries heavy on the higher-order functions, including:

  • tap - allows functions to be injected into the method chain
  • underscore - uses functional iterators, and has standard functional partial application & composition.
0.4.0

11 years ago

0.3.0

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago