-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuc.coffee
29 lines (28 loc) · 1.43 KB
/
fuc.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Fuc = U = module.exports =
curry: curry = (f) -> (a, b...) -> if b.length then f a, b... \
else (b...) -> f a, b...
flip: flip = (f) -> curry (a, b, c...) -> f b, a, c...
ap: ap = curry (f, args...) -> f args...
isO: isO = (v) -> Object.prototype.toString.call(v) == '[object Object]'
isA: isA = Array.isArray
pp: (o) -> ((isO o) or (isA o)) and JSON.stringify(o, null, 4 if isO o) or o+''
pa: flip ap
dnib: curry (o, f) -> f.bind o
uni: curry (objs...) -> o = {}; ((o[k] = v) for k, v of obj for obj in objs); o
#__: (args...) -> console.log (args.map U.pp)...; args[0]
__: (args...) -> console.log args...; args[0]
___: curry (prefix, args...) -> U.__ prefix, args...; args[0]
maf: curry (f, arr) -> arr.map(f).filter (i) -> i not in [undefined, null]
flat: ([arr...]) -> arr
flap: curry (arg, f, args...) -> f arg, args...
zop: (arr) -> o={}; (o[k] = v for [k, v] in arr); o
fup: (cls, meth) -> cls.prototype['_'+meth] = U[meth]
_it_all: (glo = (do -> this)['window'] || (do -> this)['global']) ->
for k of Fuc when k != '_it_all' then glo[k] = Fuc[k]
for cls, meths of {
Function: ['curry', 'flip', 'ap']
Object: ['isO', 'isA', 'pp', 'uni', 'pa', 'dnib', 'uni', '__', '___']
Array: ['maf', 'zop'] } then for k in meths
key = if k[0] == '_' then k else "_#{k}"
glo[cls].prototype[key] = (args...) -> Fuc[k] this, args...
null