module StdLib

Constants

A
C

Public Instance Methods

add() click to toggle source
add

Int -> Int -> Int

# File lib/fubby/std_lib.rb, line 72
def add
  ->(x, y) { x + y }
end
any() click to toggle source
any

(a -> Bool) -> Bool

# 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() click to toggle source

TODO implement this without `downcase`

downcase

String -> String

# File lib/fubby/std_lib.rb, line 104
def downcase
  ->(x) { x.downcase }
end
f_all() click to toggle source
any

(a -> Bool) -> Bool

# File lib/fubby/std_lib.rb, line 63
def f_all
  C.curry.(
    ->(f, x) {
      !any.(->(x) { x == false }, map.(f, x))
    }
  )
end
head() click to toggle source
head
a

-> a

# File lib/fubby/std_lib.rb, line 77
def head
  ->(x) { x[0] }
end
length() click to toggle source
length
a

-> Number

# File lib/fubby/std_lib.rb, line 12
def length
  ->(x) {
    C.reduce.(0, ->(memo, _) { memo + 1 }, x)
  }
end
map() click to toggle source
map

(a -> b) -> [a] -> [b]

# 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() click to toggle source
reject

(a -> Bool) -> [a] -> [a]

# File lib/fubby/std_lib.rb, line 45
def reject
  C.curry.(->(f, x) { x - select.(f, x) })
end
reverse() click to toggle source
reverse
a

-> [a]

# 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() click to toggle source
select

(a -> Bool) -> [a] -> [a]

# 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() click to toggle source

TODO: figure out how to handle Strings and Chars

# File lib/fubby/std_lib.rb, line 98
def str_head
  ->(x) { x[0] }
end
tail() click to toggle source
tail
a

-> a

# File lib/fubby/std_lib.rb, line 93
def tail
  C.compose.(head, reverse)
end
upcase() click to toggle source

TODO implement this without `capitalize`

downcase

String -> String

# File lib/fubby/std_lib.rb, line 110
def upcase
  ->(x) { x.capitalize }
end