Created
June 13, 2020 10:41
-
-
Save eleses/8a34ef285134c406482f569036e04d7f to your computer and use it in GitHub Desktop.
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
// When you want to Plazy a Pfunc but still want to get resetFunc called | |
// use this instead. See https://bit.ly/37t90WA for more | |
PfuncLazy : Pattern { | |
var <>func; | |
*new { |func| ^super.newCopyArgs(func) } | |
asStream { |inval| | |
var nextFunc, resetFunc; | |
// don't need it for my use(s) to have inval passed to func | |
// but nice to have maybe | |
# nextFunc, resetFunc = func.value(inval); | |
^FuncStream.new(nextFunc, resetFunc) | |
} | |
embedInStream { |inval| | |
// only overridden because Pattern.embedInStream doesn't pass | |
// an inval to asStream, otherwise would not be needed | |
^this.asStream(inval).embedInStream(inval) | |
} | |
storeArgs { ^[func] } | |
} |
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
( | |
p = PfuncLazy { | |
var arrs = [[1, 2], [3, 4]], apos = 0, ipos = -1; | |
[ | |
{ arrs @@ apos @@ (ipos = ipos + 1) }, // nextFunc | |
{ "inca".postln; apos = apos + 1 } // resetFunc | |
] | |
} | |
) | |
r = p.asStream | |
r.next // 1 | |
r.reset | |
r.next // 4; ok, behaves as with mere closure around Pfunc | |
// and behaves like a true Pattern otherwise | |
q = p.asStream // is really a new one | |
q.next // 1; not linked to the other stream | |
r.next // 3; ok | |
q.next // 2; ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment