fops
v0.1.0
Published
Functional Operators
Downloads
5
Readme
fops
Functional Operators
When taking the functional approach in JavaScript, and especially when using libraries like Ramda that strongly encourage currying, having functional, curried versions of the langauge operators can be quite convenient.
For operators taking two arguments, and where it makes sense (i.e. not for +
or -
) there are "flipped" versions which take arguments in the opposite of the expected order. These are have the same names as the unflipped counterparts, preceded by "f" (fin()
for the flipped version of the in operator). This library also includes some "impure" functions (f.delete
for instance) that should be used very carefully in functional programming.
Two operators have been excluded because they don't make sense as functions in JavaScript, since arguments are evaluated at call time: void
and ,
.
Arithmetic Operators
+
(add
)-
(subtract
)*
(multiply
)/
(divide
)%
(mod
)++
(inc
)--
(dec
)**
(exp
)
Bitwise Operators
&
(band
)|
(bor
)^
(bxor
)~
(bnot
)<<
(bls
)>>
(bsprs
)>>>
(bzfrs
)
Logical Operators
&&
(and
)fand
||
(or
)ffor
!
(not
)
Unary Operators
delete
var obj = {a: 1, b: 2};
f.delete(o)("a");
obj; // {b: 2}
fdelete
var obj = {a: 1, b: 2};
f.delete("a")(o);
obj; // {b: 2}
typeof
f.typeof("") // "string"
Relational Operators
in
f.in("length")([]) // true
fin
f.fin([])("length") // true
instanceof
f.instanceof([])(Object) // true
finstanceof
f.instanceof(Object)([]) // true