Module functional.operator

Functional forms of Lua operators.

Functions

concat (a, b) Stringify and concatenate arguments.
len (x) Equivalent to # operation, but respecting __len even on Lua 5.1.
get (t, k) Dereference a table.
set (t, k, v) Set a table element, honoring metamethods.
sum (a, b) Return the sum of the arguments.
diff (a, b) Return the difference of the arguments.
prod (a, b) Return the product of the arguments.
quot (a, b) Return the quotient of the arguments.
mod (a, b) Return the modulus of the arguments.
pow (a, b) Return the exponent of the arguments.
conj (a, b) Return the logical conjunction of the arguments.
disj (a, b) Return the logical disjunction of the arguments.
neg (a) Return the logical negation of the arguments.
eq (a, b) Return the equality of the arguments.
neq (a, b) Return the inequality of the arguments.
lt (a, b) Return whether the arguments are in ascending order.
lte (a, b) Return whether the arguments are not in descending order.
gt (a, b) Return whether the arguments are in descending order.
gte (a, b) Return whether the arguments are not in ascending order.

Fields

eqv Recursive table equivalence.


Functions

concat (a, b)
Stringify and concatenate arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    concatenation of stringified arguments.

Usage:

     --> "=> 1000010010"
     functional.foldl (concat, "=> ", {10000, 100, 10})
len (x)
Equivalent to # operation, but respecting __len even on Lua 5.1.

Parameters:

Returns:

    int length of list part of t

Usage:

    for i = 1, len (t) do process (t[i]) end
get (t, k)
Dereference a table.

Parameters:

  • t table a table
  • k a key to lookup in t

Returns:

    value stored at t[k] if any, otherwise nil

Usage:

     --> 4
     functional.foldl (get, {1, {{2, 3, 4}, 5}}, {2, 1, 3})
set (t, k, v)
Set a table element, honoring metamethods.

Parameters:

  • t table a table
  • k a key to lookup in t
  • v a value to set for k

Returns:

    table t

Usage:

     -- destructive table merge:
     --> {"one", bar="baz", two=5}
     functional.reduce (set, {"foo", bar="baz"}, {"one", two=5})
sum (a, b)
Return the sum of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    the sum of the a and b

Usage:

     --> 10110
     functional.foldl (sum, {10000, 100, 10})
diff (a, b)
Return the difference of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    the difference between a and b

Usage:

     --> 890
     functional.foldl (diff, {10000, 100, 10})
prod (a, b)
Return the product of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    the product of a and b

Usage:

     --> 10000000
     functional.foldl (prod, {10000, 100, 10})
quot (a, b)
Return the quotient of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    the quotient a and b

Usage:

     --> 1000
     functional.foldr (quot, {10000, 100, 10})
mod (a, b)
Return the modulus of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    the modulus of a and b

Usage:

     --> 3
     functional.foldl (mod, {65536, 100, 11})
pow (a, b)
Return the exponent of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    the a to the power of b

Usage:

     --> 4096
     functional.foldl (pow, {2, 3, 4})
conj (a, b)
Return the logical conjunction of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    logical a and b

Usage:

     --> true
     functional.foldl (conj, {true, 1, "false"})
disj (a, b)
Return the logical disjunction of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    logical a or b

Usage:

     --> true
     functional.foldl (disj, {true, 1, false})
neg (a)
Return the logical negation of the arguments.

Parameters:

  • a an argument

Returns:

    not a

Usage:

     --> {true, false, false, false}
     functional.bind (functional.map, {std.ielems, neg}) {false, true, 1, 0}
eq (a, b)
Return the equality of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    true if a is b, otherwise false
neq (a, b)
Return the inequality of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    false if a is b, otherwise true

Usage:

     --> true
     local f = require "std.functional"
     table.empty (f.filter (f.bind (neq, {6}), std.ielems, {6, 6, 6})
lt (a, b)
Return whether the arguments are in ascending order.

Parameters:

  • a an argument
  • b another argument

Returns:

    true if a is less then b, otherwise false
lte (a, b)
Return whether the arguments are not in descending order.

Parameters:

  • a an argument
  • b another argument

Returns:

    true if a is not greater then b, otherwise false
gt (a, b)
Return whether the arguments are in descending order.

Parameters:

  • a an argument
  • b another argument

Returns:

    true if a is greater then b, otherwise false
gte (a, b)
Return whether the arguments are not in ascending order.

Parameters:

  • a an argument
  • b another argument

Returns:

    true if a is not greater then b, otherwise false

Fields

eqv
Recursive table equivalence.
  • a an argument
  • b another argument
generated by LDoc 1.4.3 Last updated 2016-01-31 18:35:45