Gabriella439 / Gabriella439/Haskell-MVC-Library
Sequencing Controllers
- Dominant language
- Haskell
- Stars
- 64
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
I wanted to sequence 2 controllers so that the second ran after the first was completely drained (to be able to send finalizer signals down the shute etc). I found myself digging into the core library to do it, by tweaking the Input <|>
```
sequenced :: Controller a -> Controller a -> Controller a
sequenced (AsInput c0) (AsInput c1) = AsInput (Input $ do
r0 <- recv c0
case r0 of
Nothing -> recv c1
Just a -> return (Just a))
```
And this worked pretty well with applicative style:
```
test1 = runMVC () (asPipe cat)
((,) <$>
pure (contramap show MVC.stdoutLines) <*>
(sequenced <$>
MVC.producer Single (each ['a'..'d']) <*>
MVC.producer Single (each ['1'..'4'])))
```
Is there any other way to sequence Controllers? Or, alternatively, is there a way to lift the hood of the library a little whilst still preventing Controllers from being consumed elsewhere (which I fully appreciate and support)?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.