diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-03-07 19:29:48 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-03-07 19:29:48 +0100 |
| commit | cbe382f6b3291faf6746b0e006398d19979f8cc5 (patch) | |
| tree | be7b588c095d37a8c250f8b53236f2db89557f5f | |
| parent | do not be strict about signleton fragment groups being contained in an iterable object (diff) | |
| download | join-python-cbe382f6b3291faf6746b0e006398d19979f8cc5.tar.gz join-python-cbe382f6b3291faf6746b0e006398d19979f8cc5.tar.bz2 join-python-cbe382f6b3291faf6746b0e006398d19979f8cc5.tar.xz | |
info: example of ordered and unordered join switches
Signed-off-by: Mattias Andrée <maandree@operamail.com>
| -rw-r--r-- | info/join-python.texinfo | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/info/join-python.texinfo b/info/join-python.texinfo index aef6641..4902787 100644 --- a/info/join-python.texinfo +++ b/info/join-python.texinfo @@ -230,6 +230,43 @@ the returned value is a tuple of the index of the selected join case (fragment group) and what @code{join} returned for that fragment group. +@cartouche +@example +>>> from join import * +>>> +>>> @@fragment +>>> def f1(): +>>> pass +>>> +>>> @@fragment +>>> def f2(): +>>> pass +>>> +>>> @@fragment +>>> def f3(): +>>> pass +>>> +>>> def ordered(): +>>> (case, (_jargs, _jkwargs, _jrc)) = ordered_join((f1,), (f2,), (f3,)) +>>> return case +>>> +>>> def unordered(): +>>> (case, (_jargs, _jkwargs, _jrc)) = unordered_join((f1,), (f2,), (f3,)) +>>> return case +>>> +>>> def switch(f): +>>> f1() +>>> f2() +>>> f3() +>>> return f() +>>> +>>> print([switch(ordered) for _ in range(10)]) +>>> print([switch(unordered) for _ in range(10)]) +[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] +[2, 2, 1, 0, 1, 2, 0, 1, 1, 2] # uniformally random +@end example +@end cartouche + @node GNU Free Documentation License |
