Module std.operator

Functional forms of Lua operators.

Functions

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


Functions

Methods
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})
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"})
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})
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})
eq (a, b)
Return the equality of the arguments.

Parameters:

  • a an argument
  • b another argument

Returns:

    true if a is b, otherwise false
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})
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
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
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})
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}
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})
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})
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})
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})
generated by LDoc 1.4.3 Last updated 2018-09-03 17:48:42