Skip to main content

Treatments

Treatments are at the basis of Mélodium; they describes the flow of operations that apply to the data. They are analogous to maps whose paths connect starting points to destinations, traveling through various places for various reasons.

Treatments can themselves contain other treatments, in the same way that functions can call others. However, within a treatment, the order of declaration has no importance, the treatments are carried out when data is available for processing. All treatments can be considered to run simultaneously.

A treatment has inputs and outputs, which can be linked using connections.

treatment main(url: string, file: string, log: string)
{
startup()
get(url=url)
write(path=file)

startup.trigger -> get.trigger

log: writeText(path=log)
stream<string>()

get.data ---------------------------> write.data
get.failure -> stream.block,stream ---> log.text
}

Treatment graph

Inputs and outputs

The inputs and outputs are the means available to the treatment to interact with the outside world. The inputs and outputs of a treatment are accessible by the host treatment.

treatment my_treatment()
// `data` input accepting a stream of bytes
input data: Stream<byte>
// `text` output sending a stream of strings
output text: Stream<string>
{
/*

*/
}

Sub-treatments

Sub-treatments are treatments instantiated by a host treatment, like functions calling others. It is possible to name the sub-treatments, and to have any number of them.

treatment foo()
input raw: Stream<byte>
output text: Stream<string>
{
// A sub-treatment named `bar` of type `my_treatment` is instantiated.
bar: my_treatment()
// Another sub-treatment named `baz` of type `my_treatment` is instantiated.
baz: my_treatment()

/* … */
}

treatment my_treatment()
input data: Stream<byte>
output stuff: Stream<string>
{
/*

*/
}

Connections

Connections allow you to link treatments inputs and outputs together. It is possible to link a sub-treatment output to as many input inputs as necessary. However, an entry can only receive from one origin at a time.

A connection can only link points carrying the same type of data.

The Self keyword refers to the host treatment and provides access to its inputs and outputs.

treatment foo()
input raw: Stream<byte>
output text: Stream<string>
{
bar: my_treatment()

// The `raw` input of this `foo` treatment is connected to the `data` input of the
// treatment `bar`, whose output `stuff` is itself retransmitted to `text`.
Self.raw -> bar.data,stuff -> Self.text
}

treatment my_treatment()
input data: Stream<byte>
output stuff: Stream<string>
{
/* … */
}