Module: Kansuu::Func
- Extended by:
- Util
- Defined in:
- lib/kansuu/func.rb
Instance Method Summary
collapse
Methods included from Util
__define_func_from_method, __define_funcs_from_method, __module_functionize
Instance Method Details
#ap ⇒ Object
7
8
9
|
# File 'lib/kansuu/func.rb', line 7
def ap
-> f, x { f[x] } % 2
end
|
#ap_all ⇒ Object
15
16
17
|
# File 'lib/kansuu/func.rb', line 15
def ap_all
-> fs, x { p fs, x; fs.map &(Kansuu::Func.ap * x) } % 2
end
|
#ap_at ⇒ Object
19
20
21
22
23
|
# File 'lib/kansuu/func.rb', line 19
def ap_at
-> n, f, xs {
xs[0...n] + [(f[xs[n]])] + xs[(n+1)...xs.length]
} % 3
end
|
#ap_find ⇒ Object
71
72
73
74
75
|
# File 'lib/kansuu/func.rb', line 71
def ap_find
-> f, g, xs {
Kansuu::Func.ap_at[Kansuu::Enum.find_index[f, xs], g, xs]
} % 3
end
|
#ap_head ⇒ Object
31
32
33
|
# File 'lib/kansuu/func.rb', line 31
def ap_head
Kansuu::Func.ap_at[0]
end
|
#ap_last ⇒ Object
35
36
37
38
39
|
# File 'lib/kansuu/func.rb', line 35
def ap_last
-> f, xs {
Kansuu::Func.ap_at[xs.length - 1, f, xs]
} % 2
end
|
#ap_select ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/kansuu/func.rb', line 77
def ap_select
-> f, g, xs {
xs.map &-> x {
f[x] ? g[x] : x
}
} % 3
end
|
#ap_zip ⇒ Object
25
26
27
28
29
|
# File 'lib/kansuu/func.rb', line 25
def ap_zip
-> fs, ys {
fs.zip(ys).map &Kansuu::Func.app[Kansuu::Func.ap]
} % 2
end
|
#app ⇒ Object
11
12
13
|
# File 'lib/kansuu/func.rb', line 11
def app
-> f, xs { f[*xs] } % 2
end
|
#arg ⇒ Object
61
62
63
|
# File 'lib/kansuu/func.rb', line 61
def arg
-> n, *xs { xs[n] } % 2
end
|
#args ⇒ Object
57
58
59
|
# File 'lib/kansuu/func.rb', line 57
def args
-> *xs { xs }
end
|
#dist ⇒ Object
41
42
43
|
# File 'lib/kansuu/func.rb', line 41
def dist
Kansuu::Func.ap_all.flip 2
end
|
#withl ⇒ Object
45
46
47
48
49
|
# File 'lib/kansuu/func.rb', line 45
def withl
-> f, x {
[f[x], x]
} % 2
end
|
#withr ⇒ Object
51
52
53
54
55
|
# File 'lib/kansuu/func.rb', line 51
def withr
-> f, x {
[x, f[x]]
} % 2
end
|