{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module ApplyOver.Example
  (
  ) where

import ApplyOver.Gen (Gen (..))
import ApplyOver.Over (Over (over))
import Control.Monad.Identity (Identity)

newtype L a = L [a]

-- TODO will Applicative be enough here?
-- TODO get rid of Monad in simple cases
instance Monad m => Gen (L a) (m a) where
  next (L (a : as)) = (Just $ pure a, L as)
  next g@(L []) = (Nothing, g)

f :: Int -> Int -> Int
f a b = a + b

toIdentity :: f -> Identity f
toIdentity = pure

l :: L Int
l = L [1, 2]

r :: (Maybe (Identity Int), L Int)
r = over (toIdentity f) l
