F1 (2009-11-15)
a 2kb functional programming lib for javascript by dandavis.
link to script file
Provides
- all js1.6/es5 Array methods
- a new method: Array.prototype.clean (hybrid map+filter)
- common functional programming methods *on the global F object)
falls under a creative commons attribution license: "dandavis".
One Global: F . Properties:
Shortcuts to common Globals(F.x):
A: Array
F: Function
S: String
N: Number
R: RegExp
B: Boolean
D: Document
I: parseInt (1 arg wrap)
//ex: F.A("a,b,c")//===["a", "b", "c"]
id: k
comparisons - [].filter(name,[varCompare]):
["min", "max", "equal", "even", "gt", "lt", "match", "not", "odd","same"]
types:
["isInt", "bytypes"]
filters:
[ "If": [1,2,3,4,2,3,4,2,3,5,4,76,5,3].filter(F.If("a>4")), //[5, 76, 5]
"ok": true if arg !== (null||undefined),
"unique" ]
transforms:
["tag", "sum", "times", "extract", "fill", "invoke", "run"]
//ex:[1,2,3].map(F.tag,"dan")
util methods:
F.keys({A:1,b:2})//["A", "b"]
[]. clean methods only:
avg : [3,5,9].clean(F.avg, [0], true)//5.6666
count: [3,5,3,6,3,9,3,2,3].clean(F.count,[0],1)[ 3 ]//==5 (threes)
zip: [1,2].clean(F.zip,[4,5])//==[[1, 4], [2, 5]]