Skip to content

Instantly share code, notes, and snippets.

@andrewvmail
Created July 14, 2020 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewvmail/42ed2a958b073a185826cf17b4764b19 to your computer and use it in GitHub Desktop.
Save andrewvmail/42ed2a958b073a185826cf17b4764b19 to your computer and use it in GitHub Desktop.
print "hi"
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
function operator (err, value, next, complete)
print('operator')
print(err, value, next, complete)
if(err) then next(err)
elseif next == nil then print("complete")
else next(nil, value) end
end
operator(nil, "foo", print)
function pipe (...)
local initialOperators={...}
--&&
return function (err, value, next, complete)
if(err) then next(err)
else
print('hi')
--*************
function runNextOperator (operators, operatorError, operatorValue)
print('op', operators)
local operators = {table.unpack(operators)}
print('unpack',table.unpack(operators))
if(operatorError) then next(operatorError)
elseif (#operators) then
print('next after rem', nextOperator)
function bind(runNextOperator, operators)
print('inbind', runNextOperator, val)
local headOperator = table.remove(operators,1)
if(headOperator == nil) then
return
end
print "wtf"
return function()
return headOperator(nil, operatorValue, bind(runNextOperator,operators), complete)
end
end
bind(runNextOperator,operators)()
else
print('next', next, operatorValue)
next(nil, operatorValue)
end
end
--*************
print('run next next')
runNextOperator(initialOperators, nil, value)
end
end
--&&
end
print("^^^")
local someSequence = pipe(
operator,
operator,
operator
)
someSequence(someSequence(), "foo", print)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment