lux/pipe

Composable extensions to the piping macro |> that enhance it with various abilities.

Macros

!>

## Loops for pipes.
## Both the testing and calculating steps are pipes and must be given inside tuples.
(|> 1
    (!> [(i.< 10)]
        [i.inc]))

%>

## Monadic pipes.
## Each steps in the monadic computation is a pipe and must be given inside a tuple.
(|> 5
    (%> Id/Monad
        [(i.* 3)]
        [(i.+ 4)]
        [i.inc]))

&>

## Parallel branching for pipes.
## Allows to run multiple pipelines for a value and gives you a tuple of the outputs.
(|> 5
    (&> [(i.* 10)]
        [i.dec (i./ 2)]
        [Int/encode]))

## Will become: [50 2 "5"]

?>

## Branching for pipes.
## Both the tests and the bodies are piped-code, and must be given inside a tuple.
## If a last else-pipe isn't given, the piped-argument will be used instead.
(|> 5
    (?> [i.even?] [(i.* 2)]
        [i.odd?] [(i.* 3)]
        [(_> -1)]))

@>

## Gives a name to the piped-argument, within the given expression.
## If given no name, defaults to '@'.
(|> 5
    (@> X [(i.+ X X)]))

(|> 5
    (@> [(i.+ @ @)]))

_>

## Ignores the piped argument, and begins a new pipe.
(|> 20
    (i.* 3)
    (i.+ 4)
    (_> 0 i.inc))

case>

## Pattern-matching for pipes.
## The bodies of each branch are NOT pipes; just regular values.
(|> 5
    (case> 0 "zero"
           1 "one"
           2 "two"
           3 "three"
           4 "four"
           5 "five"
           6 "six"
           7 "seven"
           8 "eight"
           9 "nine"
           _ "???"))

~>

## Non-updating pipes.
## Will generate piped computations, but their results won't be used in the larger scope.
(|> 5
    (~> [int-to-nat %n log!])
    (i.* 10))