Module luafp.func

luafp functions module

Functions

curry (f) Takes your function arity (number of parameters) and a function, and turns it into a curried function.
negate (func) Takes a predicate function and reverse the value returned.


Functions

curry (f)
Takes your function arity (number of parameters) and a function, and turns it into a curried function. NOTE: We do not handle scope for you. Reference: https://gist.githubusercontent.com/jcmoyer/5571987/raw/3064bc4df0f4c027843e62f3c6581c3ce3cf5217/currying.lua

Parameters:

  • f The function you wish to turn into a curried function.

Returns:

    curriedFunk Your curried function.

Usage:

    local curry = require 'luafp/func'.curry
    function add(a, b) return a + b end
    addCurry = func.curry(add)
    add1 = addCurry(1)
    print(add1(2)) -- 3
negate (func)
Takes a predicate function and reverse the value returned. If the function returns true, it'll now return false. If the function returns false, it'll now return true.

Parameters:

  • func Your predicate function, a function that only returns true or false. Parameter count doesn't matter, we'll unpack and call it for you.

Returns:

    negated Your reversed predicate function.

Usage:

    local func = require 'luafp/func'.negate
    function isCow(o) return o == 'cow' end
    print(isCow('cow')) -- true
    isNotCowLulz = func.negate(isCow)
    print(isNotCowLulz('cow')) -- false
    print(isNotCowLulz('chicken')) -- true
generated by LDoc 1.4.6 Last updated 2018-01-21 13:40:25