Module: StdLib
- Included in:
- F
- Defined in:
- lib/fubby/std_lib.rb
Instance Method Summary collapse
-
#add ⇒ Object
- add
-
Int -> Int -> Int.
-
#any ⇒ Object
- any
-
(a -> Bool) -> Bool.
-
#downcase ⇒ Object
- TODO implement this without ‘downcase` downcase
-
String -> String.
-
#f_all ⇒ Object
- any
-
(a -> Bool) -> Bool.
-
#head ⇒ Object
- head
- a
-
-> a.
-
#length ⇒ Object
- length
- a
-
-> Number.
-
#map ⇒ Object
- map
-
(a -> b) -> [a] -> [b].
-
#reject ⇒ Object
- reject
-
(a -> Bool) -> [a] -> [a].
-
#reverse ⇒ Object
- reverse
- a
-
-> [a].
-
#select ⇒ Object
- select
-
(a -> Bool) -> [a] -> [a].
-
#str_head ⇒ Object
TODO: figure out how to handle Strings and Chars.
-
#tail ⇒ Object
- tail
- a
-
-> a.
-
#upcase ⇒ Object
- TODO implement this without ‘capitalize` downcase
-
String -> String.
Instance Method Details
#add ⇒ Object
- add
-
Int -> Int -> Int
72 73 74 |
# File 'lib/fubby/std_lib.rb', line 72 def add ->(x, y) { x + y } end |
#any ⇒ Object
- any
-
(a -> Bool) -> Bool
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fubby/std_lib.rb', line 50 def any C.curry.( ->(f, x) { fx = ->(memo, x) { f.(x) ? true : memo } C.reduce.(fx, x, false) } ) end |
#downcase ⇒ Object
TODO implement this without ‘downcase`
- downcase
-
String -> String
104 105 106 |
# File 'lib/fubby/std_lib.rb', line 104 def downcase ->(x) { x.downcase } end |
#f_all ⇒ Object
- any
-
(a -> Bool) -> Bool
63 64 65 66 67 68 69 |
# File 'lib/fubby/std_lib.rb', line 63 def f_all C.curry.( ->(f, x) { !any.(->(x) { x == false }, map.(f, x)) } ) end |
#head ⇒ Object
- head
- a
-
-> a
77 78 79 |
# File 'lib/fubby/std_lib.rb', line 77 def head ->(x) { x[0] } end |
#length ⇒ Object
- length
- a
-
-> Number
12 13 14 15 16 |
# File 'lib/fubby/std_lib.rb', line 12 def length ->(x) { C.reduce.(0, ->(memo, _) { memo + 1 }, x) } end |
#map ⇒ Object
- map
-
(a -> b) -> [a] -> [b]
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fubby/std_lib.rb', line 19 def map C.curry.( ->(f, x) { fx = ->(memo, x) { A.concat.(memo, [f.(x)]) } C.reduce.([], fx, x) } ) end |
#reject ⇒ Object
- reject
-
(a -> Bool) -> [a] -> [a]
45 46 47 |
# File 'lib/fubby/std_lib.rb', line 45 def reject C.curry.(->(f, x) { x - select.(f, x) }) end |
#reverse ⇒ Object
- reverse
- a
-
-> [a]
82 83 84 85 86 87 88 89 90 |
# File 'lib/fubby/std_lib.rb', line 82 def reverse ->(array) { if array.empty? || length.(array) == 1 array else add.(reverse.(array[1..-1]), array[0]) end } end |
#select ⇒ Object
- select
-
(a -> Bool) -> [a] -> [a]
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fubby/std_lib.rb', line 32 def select C.curry.( ->(f, x) { fx = ->(memo, x) { f.(x) == true ? A.concat.(memo, [x]) : memo } C.reduce.([], fx, x) } ) end |
#str_head ⇒ Object
TODO: figure out how to handle Strings and Chars
98 99 100 |
# File 'lib/fubby/std_lib.rb', line 98 def str_head ->(x) { x[0] } end |
#tail ⇒ Object
- tail
- a
-
-> a
93 94 95 |
# File 'lib/fubby/std_lib.rb', line 93 def tail C.compose.(head, reverse) end |
#upcase ⇒ Object
TODO implement this without ‘capitalize`
- downcase
-
String -> String
110 111 112 |
# File 'lib/fubby/std_lib.rb', line 110 def upcase ->(x) { x.capitalize } end |