Module

Redox.Utils

Package
purescript-redox
Repository
coot/purescript-redox

#hoistCofree' Source

hoistCofree' :: forall state f. Functor f => (f (Cofree f state) -> f (Cofree f state)) -> Cofree f state -> Cofree f state

A version of hoistCofree, where nat does not need to come from natural transformation. This corresponds to applyMiddleware in the redux library. You can use this function to add effects to your interpreter, like logging, optimistic updates, undo/redo stack, delayed actions... For example a simple logger:

addLogger
  :: forall state f
   . (Functor f)
  => Cofree f state
  -> Cofree f state
addLogger interp = hoistCofree' nat interp
  where
    nat :: f (Cofree f state) -> f (Cofree f state)
    nat fa = g <$> fa

    g :: Cofree f state -> Cofree f state
    g cof = unsafePerformEff do
      -- Control.Comonad.Cofree.head 
      log $ unsafeCoerce (head cof)
      pure cof

#mkIncInterp Source

mkIncInterp :: forall f state. Functor f => Store state -> Cofree f state -> Cofree f state

Make interpreter which updates the store on every step of computation. You have to supply the store and interperter of type Cofree f state. Check out tests how you can use it.