生产者

Producer 是一些 monadic 动作,可以为下游消费提供价值:

type Producer b = Proxy X () () b
yield::Monad m => a -> Producer a m ()

例如:

naturals::Monad m => Producer Int m ()
naturals = each [1..] -- each is a utility function exported by Pipes

我们当然也可以使用其他值的函数:

naturalsUntil::Monad m => Int -> Producer Int m ()
naturalsUntil n = each [1..n]