switch -package:flatparse
Builder for a boolean flag.
Note: Because this parser will never fail, it can not be used
with combinators such as
some or
many, as these
combinators continue until a failure occurs. See
flag'.
switch = flag False True
Swap the order of functors in a sum of functors.
>>> S.toList $ S.print $ separate $ maps S.switch $ maps (S.distinguish (=='a')) $ S.each "banana"
'a'
'a'
'a'
"bnn" :> ()
>>> S.toList $ S.print $ separate $ maps (S.distinguish (=='a')) $ S.each "banana"
'b'
'n'
'n'
"aaa" :> ()
This parser returns
True if the given flag is set and
False if the flag is absent
Create an
Event that will occur whenever the currently-selected
input
Event occurs
Basic switch.
By default, the first signal function is applied. Whenever the second
value in the pair actually is an event, the value carried by the event
is used to obtain a new signal function to be applied *at that time
and at future times*. Until that happens, the first value in the pair
is produced in the output signal.
Important note: at the time of switching, the second signal function
is applied immediately. If that second SF can also switch at time
zero, then a double (nested) switch might take place. If the second SF
refers to the first one, the switch might take place infinitely many
times and never be resolved.
Remember: The continuation is evaluated strictly at the time of
switching!
A
Var and a
Rec can combine if their rows line up
properly. Given a Variant along with a Record of functions from each
possible value of the variant to a single output type, apply the
correct function to the value in the variant.
Combinator for the <switch> element.
A simple boolean
flag
Note: this parser never fails.
switch p a b uses the memo table a whenever p gives true and
the memo table b whenever p gives false.
Intrinsic switch: Start with the given wire. As soon as its event
occurs, switch to the wire in the event's value.
- Inhibits: like argument wire until switch, then like the new
wire.
- Switch: once, now, restart state.
Run the first
Automaton until the second value in the output
tuple is
Just c, then start the second automaton, discarding
the current output
b.
This is analogous to Yampa's
switch, with
Maybe
instead of
Event.
Run first MSF until the second value in the output tuple is
Just
c (for some
c), then start the second MSF.
Analog to Yampa's
switch, with
Maybe instead of
Event.
Try to parse a switch, activate the given value when succesful
You'll also need to add at least one
long or
short.
Multiple
switchs override eachother.