module R.R ( RM
           , nextU
           , runM
           , module R
           ) where

import           Control.Monad.State.Strict (State, gets, runState)
import           Data.Bifunctor             (second)
import           Data.Functor               (($>))
import qualified Data.Text                  as T
import           Lens.Micro.Mtl             (modifying)
import           Nm
import           R
import           U

type RM = State Rs

nextU :: T.Text -> a -> RM (Nm a)
nextU :: forall a. Text -> a -> RM (Nm a)
nextU Text
n a
l = do {i <- (Rs -> Int) -> StateT Rs Identity Int
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets Rs -> Int
max_; modifying maxLens (+1) $> Nm n (U$i+1) l }

runM :: Int -> RM a -> (a, Int)
runM :: forall a. Int -> RM a -> (a, Int)
runM Int
i = (Rs -> Int) -> (a, Rs) -> (a, Int)
forall b c a. (b -> c) -> (a, b) -> (a, c)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second Rs -> Int
max_ ((a, Rs) -> (a, Int)) -> (RM a -> (a, Rs)) -> RM a -> (a, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RM a -> Rs -> (a, Rs)) -> Rs -> RM a -> (a, Rs)
forall a b c. (a -> b -> c) -> b -> a -> c
flip RM a -> Rs -> (a, Rs)
forall s a. State s a -> s -> (a, s)
runState (Int -> IntMap Int -> Rs
Rs Int
i IntMap Int
forall a. Monoid a => a
mempty)