Appearance
| 1 | namespace Syntax.Process is | |
| 2 | // Which terminal pipe consumer a call names, if any. | |
| 3 | // | |
| 4 | // `role` is the combinator's fusion role, looked up from the call's | |
| 5 | // resolved target symbol rather than read off a rendered name — a | |
| 6 | // rename in the runtime library changes what fuses only through the | |
| 7 | // role list the innate lookup resolves from. | |
| 8 | // | |
| 9 | // The returned kind is what `FUSED_CONSUMER` switches on, and is | |
| 10 | // not always the role - `collect_list` fuses as `collect`. | |
| 11 | class PIPE_CONSUMER_KIND is | |
| 12 | of(name: string?, argument_count: int) -> string? static is | |
| 13 | if !name? then | |
| 14 | return null | |
| 15 | fi | |
| 16 | ||
| 17 | if name =~ "count" /\ argument_count == 0 then | |
| 18 | return "count" | |
| 19 | elif name =~ "any" /\ argument_count == 1 then | |
| 20 | return "any" | |
| 21 | elif name =~ "all" /\ argument_count == 1 then | |
| 22 | return "all" | |
| 23 | elif name =~ "each" /\ argument_count == 1 then | |
| 24 | return "each" | |
| 25 | elif name =~ "reduce" /\ argument_count == 2 then | |
| 26 | return "reduce" | |
| 27 | elif name =~ "find" /\ argument_count == 1 then | |
| 28 | return "find" | |
| 29 | elif name =~ "first" /\ argument_count == 0 then | |
| 30 | return "first" | |
| 31 | elif name =~ "collect_list" /\ argument_count == 0 then | |
| 32 | return "collect" | |
| 33 | fi | |
| 34 | ||
| 35 | return null | |
| 36 | si | |
| 37 | ||
| 38 | // A consumer that takes a function argument, and so needs the | |
| 39 | // fused loop to invoke it per element. | |
| 40 | takes_function(consumer_kind: string?) -> bool static => | |
| 41 | consumer_kind =~ "any" \/ consumer_kind =~ "all" \/ | |
| 42 | consumer_kind =~ "each" \/ consumer_kind =~ "find" | |
| 43 | ||
| 44 | // A consumer that produces no value. | |
| 45 | is_void(consumer_kind: string?) -> bool static => | |
| 46 | consumer_kind =~ "each" | |
| 47 | si | |
| 48 | si |