Idris2Doc : Data.MSF.Util

Data.MSF.Util

(source)
Various utility combinators.

A note on arrow operators: Arrow operators in this module are
of the form `i>o`, where `i` is either `>`, `^`, `!`, or `?`.
and `o` is either `>`, `^`, `!`, or `-`. Each of these symbols
describe a different type of arrow-like function at the
corresponding end of the operator:

The following table lists the meaning of symbols

| Symbol      | Meaning                  | Example                    |
|-------------|--------------------------|----------------------------|
| `>`         | An MSF                   | arr (*2) >>> arrM printLn  |
| `^`         | a pure function          | (*2) ^>> printLn           |
| `!`         | an effectful computation | arr (*2) >>! printLn       |

In addition, symbol `?` corresponds to an event stream input, and
symbol `-` describes fanning out to a list of sinks:

```idris example
when (> 10) ?>- [ arrM printLn, put ]
```

Definitions

(>>^) : MSFmio-> (o->o2) ->MSFmio2
  Sequencing of an MSF and a pure function

Visibility: export
Fixity Declaration: infixr operator, level 1
(^>>) : (i->i2) ->MSFmi2o->MSFmio
  Sequencing of a pure function and an MSF

Visibility: export
Fixity Declaration: infixr operator, level 1
(>>!) : MSFmio-> (o->mo2) ->MSFmio2
  Sequencing of an MSF and an effectful computation

Visibility: export
Fixity Declaration: infixr operator, level 1
(!>>) : (i->mi2) ->MSFmi2o->MSFmio
  Sequencing of an effectful computation and an MSF

Visibility: export
Fixity Declaration: infixr operator, level 1
fan_ : FanListmios->MSFmi ()
  Like `fan` but discards the results.
This is mainly useful for broadcasting to data sinks
(streaming functions that do not produce any interesting
output).

TODO: Should we require a proof here that `os` is a list
of `Unit`?

Visibility: export
(>>-) : MSFmix->FanListmxos->MSFmi ()
  Broadcasting an MSF to a list of sinks

Visibility: export
Fixity Declaration: infixr operator, level 1
(^>-) : (i->x) ->FanListmxos->MSFmi ()
  Broadcasting a pure function to a list of sinks

Visibility: export
Fixity Declaration: infixr operator, level 1
(!>-) : (i->mx) ->FanListmxos->MSFmi ()
  Broadcasting an effectful computation to a list of sinks

Visibility: export
Fixity Declaration: infixr operator, level 1
firstArg : MSFm (HList [x, i]) o->x->MSFmio
  Extract the first argument from an MSF taking a pair
of input values.

Visibility: export
secondArg : MSFm (HList [i, x]) o->x->MSFmio
  Extract the second argument from an MSF taking a pair
of input values.

Visibility: export
hd : MSFm (HList (i::t)) i
  Extract the first value of an n-ary product

Visibility: export
tl : MSFm (HList (i::t)) (HListt)
  Extract the tail of an n-ary product

Visibility: export
snd : MSFm (HList (i:: (i2::t))) i2
  Extract the second value of an n-ary product

Visibility: export
swap : MSFm (HList [a, b]) (HList [b, a])
  Swaps a pair of input values

Visibility: export
either : MSFm (Eitheri1i2) (HSum [i1, i2])
  Convert an `Either` input to a binary sum, which
can then be sequenced with a call to `choice` or `collect`.

Visibility: export
ifLeft : Monoido=>MSFmio->MSFm (Eitheria) o
  Run the given MSF only if the input is a `Left`.

Visibility: export
ifRight : Monoido=>MSFmio->MSFm (Eitherai) o
  Run the given MSF only if the input is a `Right`.

Visibility: export
maybe : MSFm (Maybei) (HSum [i, ()])
  Convert an `Maybe` input to a binary sum, which
can then be sequenced with a call to `choice` or `collect`.

Visibility: export
ifJust : Monoido=>MSFmio->MSFm (Maybei) o
  Run the given MSF only if the input is a `Just`.

Visibility: export
ifNothing : Monoido=>MSFm () o->MSFm (Maybei) o
  Run the given MSF only if the input is a `Nothing`.

Visibility: export
bool : (i->Bool) ->MSFmi (HSum [i, i])
  Convert an input to a binary sum, depending on whether
the given predicate returns `True` or `False`. The result
can then be sequenced with a call to `choice` or `collect`.

Visibility: export
ifTrue : Monoido=> (i->Bool) ->MSFmio->MSFmio
  Run the given MSF only if the predicate holds for the input.

Visibility: export
ifFalse : Monoido=> (i->Bool) ->MSFmio->MSFmio
  Run the given MSF only if the predicate does not hold for the input.

Visibility: export
ifIs : Eqi=>Monoido=>i->MSFmio->MSFmio
  Run the given MSF only if the input equlas the given value

Visibility: export
ifIsNot : Eqi=>Monoido=>i->MSFmio->MSFmio
  Run the given MSF only if the input does not equal the given value

Visibility: export
feedback_ : s->MSFm (HList [s, i]) s->MSFmi ()
  Uses the given value as a seed for feeding back output
of the MSF back to its input.

Visibility: export
iPre : o->MSFmoo
  Delay a stream by one sample.

Visibility: export
accumulateWith : (i->o->o) ->o->MSFmio
  Applies a function to the input and an accumulator,
outputting the updated accumulator.

Visibility: export
count : Numn=>MSFmin
  Counts the number of scans of the signal function.

Visibility: export
appendFrom : Semigroupv=>v->MSFmvv
  Accumulate the inputs, starting from an initial value.

Visibility: export
append : Monoidn=>MSFmnn
  Accumulate the inputs, starting from `neutral`

Visibility: export
mealy : (i->s->HList [s, o]) ->s->MSFmio
  Applies a transfer function to the input and an accumulator,
returning the updated accumulator and output.

Visibility: export
unfold : (s->HList [s, o]) ->s->MSFmio
  Unfolds a function over an initial state
value.

Visibility: export
repeatedly : (o->o) ->o->MSFmio
  Generates output using a step-wise generation function and an initial
value. Version of 'unfold' in which the output and the new accumulator
are the same.

Visibility: export
cycle : (vs : Listo) -> {auto0_ : NonEmptyvs} ->MSFmio
  Cycles through the given non-empty list of values.

Visibility: export
observeWith : MSFmi () ->MSFmii
  Observe input values through the given sink.

Visibility: export
withEffect : (i->m ()) ->MSFmii
  Run the given effectful computation on each input.

Visibility: export
runEffect : m () ->MSFmii
  Run the given monadic action on each input.

Visibility: export
never : MSFmi (Evento)
  The empty event stream that never fires an event

Visibility: export
hold : o->MSFm (Evento) o
  Convert an event stream to a streaming function
holding the value of the last event fired starting
from the given initial value.

Visibility: export
ntimes : Nat->o->MSFmi (Evento)
  Fire the given event `n` times.

Visibility: export
once : o->MSFmi (Evento)
  Fire the given event exactly once on the first
evaluation step.

Visibility: export
when : (i->Bool) ->MSFmi (Eventi)
  Fire an event whenever the given predicate holds.

Visibility: export
when_ : (i->Bool) ->MSFmi (Event ())
  Like `when` but discard the input.

Visibility: export
is : Eqi=>i->MSFmi (Eventi)
  Fire an event whenever the input equals the given value.

Visibility: export
isNot : Eqi=>i->MSFmi (Eventi)
  Fire an event whenever the input does not equal the given value.

Visibility: export
whenLeft : MSFm (Eitherab) (Eventa)
  Fire an event if the input is a `Left`.

Visibility: export
whenRight : MSFm (Eitherab) (Eventb)
  Fire an event if the input is a `Right`.

Visibility: export
whenJust : MSFm (Maybea) (Eventa)
  Fire an event if the input is a `Just`.

Visibility: export
whenNothing : MSFm (Maybea) (Event ())
  Fire an event if the input is a `Nothing`.

Visibility: export
event : MSFm (Eventi) (HSum [i, ()])
  Convert an `Event` input to a binary sum, which
can then be sequenced with a call to `choice` or `collect`.

Visibility: export
ifEvent : Monoido=>MSFmio->MSFm (Eventi) o
  Run the given MSF only if the input fired an event.

Visibility: export
(?>-) : MSFmi (Eventx) ->FanListmxos->MSFmi ()
  Broadcast an event to a list of sinks.

Visibility: export
Fixity Declaration: infixr operator, level 1
(?>>) : Monoido=>MSFmi (Eventx) ->MSFmxo->MSFmio
  Run the given MSF if the input stream fires and event.

Visibility: export
Fixity Declaration: infixr operator, level 1
ifNoEvent : Monoido=>MSFm () o->MSFm (Eventi) o
  Run the given MSF only if the input fired no event.

Visibility: export
onChange : Eqi=>MSFmi (Eventi)
  Fire an event whenever the input value changed.
Always fires on first input.

Visibility: export
onEvent : MSFm (HList [a, Evente]) (Eventa)
  Fires the first input as an event whenever the
second input fires.

Visibility: export
onEventWith : (a->e->b) ->MSFm (HList [a, Evente]) (Eventb)
  Combines the first input with the event fired by the
second input.

Visibility: export
leftOnEvent : MSFm (HList [Eitherab, Evente]) (Eventa)
  Combines an input event stream with a stream function
holding an `Either` trying to extract a `Left` whenever
an event is fired.

Visibility: export
rightOnEvent : MSFm (HList [Eitherab, Evente]) (Eventb)
  Combines an input event stream with a stream function
holding an `Either` trying to extract a `Right` whenever
an event is fired.

Visibility: export
justOnEvent : MSFm (HList [Maybea, Evente]) (Eventa)
  Combines an input event stream with a stream function
holding a `Maybe` trying to extract the value from a `Just` whenever
an event is fired.

Visibility: export
unionWith : (o->o->o) ->MSFmi (Evento) ->MSFmi (Evento) ->MSFmi (Evento)
  Fires an event whenever one of the two given
event streams fire. Uses the given function
to combine simultaneously occuring events.

Visibility: export
unionL : MSFmi (Evento) ->MSFmi (Evento) ->MSFmi (Evento)
  Left-biased union of event streams.
In case of simultaneously occuring events, the
event from the first event stream is fired.

This is the same behavior as `(<|>)` from
the MSFs `Alternative` implementation

Visibility: export
unionR : MSFmi (Evento) ->MSFmi (Evento) ->MSFmi (Evento)
  Right-biased union of event streams.
In case of simultaneously occuring events, the
event from the second event stream is fired.

Visibility: export
union : Semigroupo=>MSFmi (Evento) ->MSFmi (Evento) ->MSFmi (Evento)
  Union of event streams using a `Semigroup` to
merge values in case of simultaneously occuring events.

This is an alias for `(<+>)`.

Visibility: export
(<|>) : Alternativef=>MSFmi (fo) ->MSFmi (fo) ->MSFmi (fo)
Visibility: export
Fixity Declaration: infixr operator, level 2
filter : (o->Bool) ->MSFm (Evento) (Evento)
  Filters an event stream, letting pass only values,
fow which the given predicate holds.

Visibility: export
mapMaybe : (i->Maybeo) ->MSFm (Eventi) (Evento)
  Filters an event stream, letting pass only values,
fow which the given function returns a `Just`.

Visibility: export
proj : (0t : k) ->Elemtks=>MSFm (Anyfks) (Event (ft))
  Sum projection: Fires an event if a value of the given type can
be extracted from the input sum.

Visibility: export
observeEvent : MSFmi () ->MSFm (Eventi) (Eventi)
  Observe an event throught the given sink.

Visibility: export
accumulateWithE : (i->o->o) ->o->MSFm (Eventi) (Evento)
  Applies a function to the input and an accumulator,
outputting the updated accumulator whenever an
event is fire.

Visibility: export
countE : MSFm (Eventi) (EventNat)
  Count the number of occurences of an event

Visibility: export
0Fun : ListType->Type->Type
  N-ary function type calculated from a list of n types.

Visibility: public export
uncurryNP : Funiso->HListis->o
  Converts an n-ary function to one taking an n-ary
product as input.

Visibility: export
np : Funiso->MSFm (HListis) o
  Alias for `arr . uncurryNP`.

Visibility: export