-----------------------------------------------------------------------------
-- |
-- Module      :  Disco.Effects.Input
-- Copyright   :  disco team and contributors
-- Maintainer  :  byorgey@gmail.com
--
-- SPDX-License-Identifier: BSD-3-Clause
--
-- Utility functions for input effect.
--
-----------------------------------------------------------------------------

module Disco.Effects.Input
  ( module Polysemy.Input
  , inputToState
  )
  where

import           Polysemy
import           Polysemy.Input
import           Polysemy.State

-- | Run an input effect in terms of an ambient state effect.
inputToState :: forall s r a. Member (State s) r => Sem (Input s ': r) a -> Sem r a
inputToState :: Sem (Input s : r) a -> Sem r a
inputToState = (forall (rInitial :: EffectRow) x.
 Input s (Sem rInitial) x -> Sem r x)
-> Sem (Input s : r) a -> Sem r a
forall (e :: (* -> *) -> * -> *) (r :: EffectRow) a.
FirstOrder e "interpret" =>
(forall (rInitial :: EffectRow) x. e (Sem rInitial) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
interpret (\case { Input s (Sem rInitial) x
Input -> forall (r :: EffectRow). Member (State s) r => Sem r s
forall s (r :: EffectRow). Member (State s) r => Sem r s
get @s })