{-# LANGUAGE AllowAmbiguousTypes #-}
-- | Convenience functions for the 'Labeled' 'Output' effect.
--
-- @since 2.7.0.0
module Effectful.Labeled.Output
  ( -- * Effect
    Output(..)

    -- ** Handlers
  , runOutputAction
  , runOutputLocalArray
  , runOutputLocalList
  , runOutputSharedArray
  , runOutputSharedList

    -- ** Operations
  , output

    -- * Re-exports
  , Labeled(..)
  , Array
  ) where

import Data.Primitive.Array

import Effectful
import Effectful.Dispatch.Dynamic
import Effectful.Labeled
import Effectful.Output.Dynamic (Output(..))
import Effectful.Output.Dynamic qualified as O

----------------------------------------
-- Handlers

-- | Run the 'Output' effect with the given action for receiving values.
runOutputAction
  :: forall label o es a
   . HasCallStack
  => (HasCallStack => o -> Eff es ())
  -- ^ The action for output generation.
  -> Eff (Labeled label (Output o) : es) a
  -> Eff es a
runOutputAction :: forall {k} (label :: k) o (es :: [Effect]) a.
HasCallStack =>
(HasCallStack => o -> Eff es ())
-> Eff (Labeled label (Output o) : es) a -> Eff es a
runOutputAction = forall (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
forall {k} (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
runLabeled @label ((Eff (Output o : es) a -> Eff es a)
 -> Eff (Labeled label (Output o) : es) a -> Eff es a)
-> ((o -> Eff es ()) -> Eff (Output o : es) a -> Eff es a)
-> (o -> Eff es ())
-> Eff (Labeled label (Output o) : es) a
-> Eff es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (o -> Eff es ()) -> Eff (Output o : es) a -> Eff es a
(HasCallStack => o -> Eff es ())
-> Eff (Output o : es) a -> Eff es a
forall o (es :: [Effect]) a.
HasCallStack =>
(HasCallStack => o -> Eff es ())
-> Eff (Output o : es) a -> Eff es a
O.runOutputAction

-- | Run the 'Output' effect and return the final value along with the
-- accumulated array (via "Effectful.Output.Static.Local.Array").
runOutputLocalArray
  :: forall label o es a
   . HasCallStack
  => Eff (Labeled label (Output o) : es) a
  -> Eff es (a, Array o)
runOutputLocalArray :: forall {k} (label :: k) o (es :: [Effect]) a.
HasCallStack =>
Eff (Labeled label (Output o) : es) a -> Eff es (a, Array o)
runOutputLocalArray = forall (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
forall {k} (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
runLabeled @label Eff (Output o : es) a -> Eff es (a, Array o)
forall o (es :: [Effect]) a.
HasCallStack =>
Eff (Output o : es) a -> Eff es (a, Array o)
O.runOutputLocalArray

-- | Run the 'Output' effect and return the final value along with the
-- accumulated list (via "Effectful.Output.Static.Local.List").
runOutputLocalList
  :: forall label o es a
   . HasCallStack
  => Eff (Labeled label (Output o) : es) a
  -> Eff es (a, [o])
runOutputLocalList :: forall {k} (label :: k) o (es :: [Effect]) a.
HasCallStack =>
Eff (Labeled label (Output o) : es) a -> Eff es (a, [o])
runOutputLocalList = forall (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
forall {k} (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
runLabeled @label Eff (Output o : es) a -> Eff es (a, [o])
forall o (es :: [Effect]) a.
HasCallStack =>
Eff (Output o : es) a -> Eff es (a, [o])
O.runOutputLocalList

-- | Run the 'Output' effect and return the final value along with the
-- accumulated array (via "Effectful.Output.Static.Shared.Array").
runOutputSharedArray
  :: forall label o es a
   . HasCallStack
  => Eff (Labeled label (Output o) : es) a
  -> Eff es (a, Array o)
runOutputSharedArray :: forall {k} (label :: k) o (es :: [Effect]) a.
HasCallStack =>
Eff (Labeled label (Output o) : es) a -> Eff es (a, Array o)
runOutputSharedArray = forall (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
forall {k} (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
runLabeled @label Eff (Output o : es) a -> Eff es (a, Array o)
forall o (es :: [Effect]) a.
HasCallStack =>
Eff (Output o : es) a -> Eff es (a, Array o)
O.runOutputSharedArray

-- | Run the 'Output' effect and return the final value along with the
-- accumulated list (via "Effectful.Output.Static.Shared.List").
runOutputSharedList
  :: forall label o es a
    . HasCallStack
  => Eff (Labeled label (Output o) : es) a
  -> Eff es (a, [o])
runOutputSharedList :: forall {k} (label :: k) o (es :: [Effect]) a.
HasCallStack =>
Eff (Labeled label (Output o) : es) a -> Eff es (a, [o])
runOutputSharedList = forall (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
forall {k} (label :: k) (e :: Effect) (es :: [Effect]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
runLabeled @label Eff (Output o : es) a -> Eff es (a, [o])
forall o (es :: [Effect]) a.
HasCallStack =>
Eff (Output o : es) a -> Eff es (a, [o])
O.runOutputSharedList

----------------------------------------
-- Operations

-- | Feed the value to the underlying handler.
output
  :: forall label o es
   . (HasCallStack, Labeled label (Output o) :> es)
  => o
  -> Eff es ()
output :: forall {k} (label :: k) o (es :: [Effect]).
(HasCallStack, Labeled label (Output o) :> es) =>
o -> Eff es ()
output = Labeled label (Output o) (Eff es) () -> Eff es ()
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (Labeled label (Output o) (Eff es) () -> Eff es ())
-> (o -> Labeled label (Output o) (Eff es) ()) -> o -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (label :: k) (e :: Effect) (a :: Type -> Type) b.
e a b -> Labeled label e a b
forall {k} (label :: k) (e :: Effect) (a :: Type -> Type) b.
e a b -> Labeled label e a b
Labeled @label (Output o (Eff es) () -> Labeled label (Output o) (Eff es) ())
-> (o -> Output o (Eff es) ())
-> o
-> Labeled label (Output o) (Eff es) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. o -> Output o (Eff es) ()
forall o (a :: Type -> Type). o -> Output o a ()
Output