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

#apObject



7
8
9
# File 'lib/kansuu/func.rb', line 7

def ap
  -> f, x { f[x] } % 2
end

#ap_allObject



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_argObject



65
66
67
68
69
# File 'lib/kansuu/func.rb', line 65

def ap_arg
  -> n, f, g {
    Kansuu::Func.args >> Kansuu::Func.ap_at[n, f] >> Kansuu::Func.app[g]
  } % 3
end

#ap_atObject



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_findObject



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_headObject



31
32
33
# File 'lib/kansuu/func.rb', line 31

def ap_head
  Kansuu::Func.ap_at[0]
end

#ap_lastObject



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_selectObject



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_zipObject



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

#appObject



11
12
13
# File 'lib/kansuu/func.rb', line 11

def app
  -> f, xs { f[*xs] } % 2
end

#argObject



61
62
63
# File 'lib/kansuu/func.rb', line 61

def arg
  -> n, *xs { xs[n] } % 2
end

#argsObject



57
58
59
# File 'lib/kansuu/func.rb', line 57

def args
  -> *xs { xs }
end

#distObject



41
42
43
# File 'lib/kansuu/func.rb', line 41

def dist
  Kansuu::Func.ap_all.flip 2
end

#withlObject



45
46
47
48
49
# File 'lib/kansuu/func.rb', line 45

def withl
  -> f, x {
    [f[x], x]
  } % 2
end

#withrObject



51
52
53
54
55
# File 'lib/kansuu/func.rb', line 51

def withr
  -> f, x {
    [x, f[x]]
  } % 2
end