polysemy-1.8.0.0: Higher-order, low-boilerplate free monads.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Polysemy.Output

Synopsis

Effect

data Output o m a where Source #

An effect capable of sending messages. Useful for streaming output and for logging.

Constructors

Output :: o -> Output o m () 

Actions

output :: forall o r. Member (Output o) r => o -> Sem r () Source #

Interpretations

runOutputList :: forall o r a. Sem (Output o ': r) a -> Sem r ([o], a) Source #

Run an Output effect by transforming it into a list of its values.

Since: 1.0.0.0

runLazyOutputList :: forall o r a. Sem (Output o ': r) a -> Sem r ([o], a) Source #

Run an Output effect by transforming it into a list of its values, lazily.

Warning: This inherits the nasty space leak issue of WriterT! Don't use this if you don't have to.

Since: 1.3.0.0

runOutputMonoid :: forall o m r a. Monoid m => (o -> m) -> Sem (Output o ': r) a -> Sem r (m, a) Source #

Run an Output effect by transforming it into a monoid.

Since: 1.0.0.0

runLazyOutputMonoid :: forall o m r a. Monoid m => (o -> m) -> Sem (Output o ': r) a -> Sem r (m, a) Source #

Run an Output effect by transforming it into a monoid, and accumulate it lazily.

Warning: This inherits the nasty space leak issue of WriterT! Don't use this if you don't have to.

Since: 1.3.0.0

runOutputMonoidAssocR :: forall o m r a. Monoid m => (o -> m) -> Sem (Output o ': r) a -> Sem r (m, a) Source #

Like runOutputMonoid, but right-associates uses of <>.

This asymptotically improves performance if the time complexity of <> for the Monoid depends only on the size of the first argument.

You should always use this instead of runOutputMonoid if the monoid is a list, such as String.

Since: 1.1.0.0

runLazyOutputMonoidAssocR :: forall o m r a. Monoid m => (o -> m) -> Sem (Output o ': r) a -> Sem r (m, a) Source #

Like runLazyOutputMonoid, but right-associates uses of <>.

This asymptotically improves performance if the time complexity of <> for the Monoid depends only on the size of the first argument.

You should always use this instead of runLazyOutputMonoid if the monoid is a list, such as String.

Warning: This inherits the nasty space leak issue of WriterT! Don't use this if you don't have to.

Since: 1.3.0.0

runOutputMonoidIORef :: forall o m r a. (Monoid m, Member (Embed IO) r) => IORef m -> (o -> m) -> Sem (Output o ': r) a -> Sem r a Source #

Run an Output effect by transforming it into atomic operations over an IORef.

Since: 1.1.0.0

runOutputMonoidTVar :: forall o m r a. (Monoid m, Member (Embed IO) r) => TVar m -> (o -> m) -> Sem (Output o ': r) a -> Sem r a Source #

Run an Output effect by transforming it into atomic operations over a TVar.

Since: 1.1.0.0

outputToIOMonoid :: forall o m r a. (Monoid m, Member (Embed IO) r) => (o -> m) -> Sem (Output o ': r) a -> Sem r (m, a) Source #

Run an Output effect in terms of atomic operations in IO.

Internally, this simply creates a new IORef, passes it to runOutputMonoidIORef, and then returns the result and the final value of the IORef.

Beware: As this uses an IORef internally, all other effects will have local state semantics in regards to Output effects interpreted this way. For example, throw and catch will never revert outputs, even if runError is used after outputToIOMonoid.

Since: 1.2.0.0

outputToIOMonoidAssocR :: forall o m r a. (Monoid m, Member (Embed IO) r) => (o -> m) -> Sem (Output o ': r) a -> Sem r (m, a) Source #

Like outputToIOMonoid, but right-associates uses of <>.

This asymptotically improves performance if the time complexity of <> for the Monoid depends only on the size of the first argument.

You should always use this instead of outputToIOMonoid if the monoid is a list, such as String.

Beware: As this uses an IORef internally, all other effects will have local state semantics in regards to Output effects interpreted this way. For example, throw and catch will never revert outputs, even if runError is used after outputToIOMonoidAssocR.

Since: 1.2.0.0

ignoreOutput :: Sem (Output o ': r) a -> Sem r a Source #

Run an Output effect by ignoring it.

Since: 1.0.0.0

runOutputBatched :: forall o r a. Member (Output [o]) r => Int -> Sem (Output o ': r) a -> Sem r a Source #

Accumulate outputs so they are delayed until they reach at least size size.

If size is 0, this interpretation will not emit anything in the resulting Output effect.

Since: 1.0.0.0

runOutputSem :: (o -> Sem r ()) -> Sem (Output o ': r) a -> Sem r a Source #

Runs an Output effect by running a monadic action for each of its values.