Purescript-ChocoPie
A Cycle.js-like utility for working with Purescript-Behaviors Events. Aptly named for a circular Korean snack food.
Usage
program = runChocoPie main' drivers
where
main' ::
{ a :: Event Int
, b :: Unit
} ->
{ a :: Event Unit
, b :: Event Int
}
main' sources =
{ a: mempty
, b: sources.a
}
drivers ::
{ a :: Event Unit -> Eff _ (Event Int)
, b :: Event Int -> Eff _ Unit
}
drivers =
{ a: const $ pure (pure 1)
, b: \events -> subscribe events logShow
}
With appropriate context and individual annotations, the type signature annotations are no longer needed.
Usage Exmples
I rewrote some code in my simple-rpc-telegram-bot repo, where I have drivers for running a child process, receiving and sending messages from Telegram, and a timer that ticks for every hour.
type Main
= { torscraper :: Event Result
, bot :: Event Request
, timer :: Event Request
}
-> { torscraper :: Event Request
, bot :: Event Result
, timer :: Event Unit
}
main' :: Main
main' sources =
{ torscraper: sources.timer <|> sources.bot
, bot: sources.torscraper
, timer: mempty
}
type Drivers e1 e2 e3 =
{ torscraper :: Event Request -> Eff e1 (Event Result)
, bot :: Event Result -> Eff e2 (Event Request)
, timer :: Event Unit -> Eff e3 (Event Request)
}
drivers :: -- ...
drivers
{ token
, torscraperPath
, master
} =
{ torscraper
, bot
, timer
}
where
torscraper requests = -- ...
bot results = -- ...
timer _
| tick <- pure 0 <|> interval (60 * 60 * 1000)
, reqs <- { origin: FromTimer, id: master } <$ tick
= pure reqs
-- runChocoPie main' (drivers config)