Skip to content

Instantly share code, notes, and snippets.

@apmckinlay
Last active November 23, 2017 18:37
Show Gist options
  • Save apmckinlay/b82c1fa74b39fdc06dbcac47f92abf79 to your computer and use it in GitHub Desktop.
Save apmckinlay/b82c1fa74b39fdc06dbcac47f92abf79 to your computer and use it in GitHub Desktop.
Suneido Bind function
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