[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Better Syntax?
- From: Miroslav Janíček <mira.janicek@...>
- Date: Tue, 4 Oct 2016 14:37:04 +0200
> On 4 Oct 2016, at 0:04, Sean Conner <sean@conman.org> wrote:
>
> It was thus said that the Great Mike Jones once stated:
>> Hi,
>>
>> I am working on a project where I have basically an event style
>> framework, and I would like some way to "chain together" functions.
>
> I dug through my archives and I found the following bit of code (cleaned
> up---I was starting to learn Lua):
>
> function fappend(f1,f2)
> return function(...)
> return f2(f1(...))
> end
> end
It might be a good idea to handle cases in which f1 or f2 are undefined:
function fappend(f1, f2)
if f1 ~= nil and f2 ~= nil then return function(...) return f2(f1(...)) end
elseif f1 ~= nil then return f1
else return f2
end
end
(And maybe also calling the function “compose” would be more indicative of its intent.)
M.