-
Notifications
You must be signed in to change notification settings - Fork 44
/
Store.purs
30 lines (23 loc) · 914 Bytes
/
Store.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- | This module defines the `Store` comonad.
module Control.Comonad.Store
( Store
, runStore
, store
, module Control.Comonad.Store.Class
, module Control.Comonad.Store.Trans
) where
import Prelude
import Control.Comonad.Store.Class (class ComonadStore, experiment, peek, peeks, pos, seek, seeks)
import Control.Comonad.Store.Trans (StoreT(..), runStoreT)
import Data.Identity (Identity(..))
import Data.Newtype (unwrap)
import Data.Tuple (Tuple(..), swap)
-- | The `Store` comonad is a synonym for the `StoreT` comonad transformer, applied
-- | to the `Identity` monad.
type Store s = StoreT s Identity
-- | Unwrap a value in the `Store` comonad.
runStore :: forall s a. Store s a -> Tuple (s -> a) s
runStore (StoreT s) = swap (unwrap <$> swap s)
-- | Create a value in context in the `Store` comonad.
store :: forall s a. (s -> a) -> s -> Store s a
store f x = StoreT $ Tuple (Identity f) x