Skip to content

Instantly share code, notes, and snippets.

@andrewvmail

andrewvmail/opopspec.lua

Last active Jul 14, 2020
Embed
What would you like to do?
print "hi momo"
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