-
-
Save apmckinlay/b82c1fa74b39fdc06dbcac47f92abf79 to your computer and use it in GitHub Desktop.
Suneido Bind function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class | |
{ | |
CallClass(@args) | |
{ | |
ai = 0 | |
fi = 1 | |
mixed = args[1..].Map({ it is Bind ? 'a' $ ai++ : '.f' $ fi++ }).Join(',') | |
c = (.binder)(mixed) | |
return c(@args.Remove(Bind)) | |
} | |
binder: Memoize | |
{ | |
Func(mixed) | |
{ | |
m = mixed.Split(',') | |
fixed = '.f0,' $ m.Filter({ it.Prefix?('.f') }).Join(',') | |
params = m.Filter({ it.Prefix?('a') }).Join(',') | |
src = "class | |
{ | |
New(' $ fixed $ ') | |
{ } | |
Call(' $ params $ ') | |
{ return (.f0)(' $ mixed $ ') } | |
}" | |
return src.Compile() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment