module JSONIncrementalDecoder.Prelude
(
module Exports,
concatMany,
eventually,
eventuallyLifting,
scanl,
manyWithIndex,
shouldFail,
skipSepBy,
skipSepBy1,
skipMany,
skipMany1,
)
where
import BasePrelude as Exports hiding (Alt, scanl)
import Control.Monad.IO.Class as Exports
import Control.Monad.Trans.Class as Exports
import Control.Monad.Trans.Except as Exports hiding (liftCallCC, liftCatch, liftListen, liftPass)
import Control.Monad.Trans.Reader as Exports hiding (liftCallCC, liftCatch, liftListen, liftPass)
import Control.Monad.Trans.State.Strict as Exports hiding (liftCallCC, liftCatch, liftListen, liftPass)
import Control.Monad.Trans.Writer.Strict as Exports
import Supplemented as Exports
import Unsequential as Exports
import Interspersed as Exports
import Matcher as Exports hiding (run)
import Success.Pure as Exports (Success)
import Data.Hashable as Exports (Hashable)
import Data.HashMap.Strict as Exports (HashMap)
import Data.ByteString as Exports (ByteString)
import Data.Text as Exports (Text)
import Data.Scientific as Exports (Scientific)
concatMany :: (Alternative m, Monoid a) => m a -> m a
concatMany consume =
step <|> end
where
step =
mappend <$> consume <*> concatMany consume
end =
pure mempty
eventually :: Alternative f => f () -> f a -> f a
eventually skip consume =
fix $ \loop -> consume <|> (skip *> loop)
eventuallyLifting :: (Alternative g, Applicative f) => (forall b. f b -> g b) -> f a -> g a
eventuallyLifting lift fx =
eventually (lift (pure ())) (lift fx)
scanl :: MonadPlus m => (a -> b -> a) -> a -> m b -> m a
scanl snoc init parser =
loop init
where
loop acc =
mplus (parser >>= loop . snoc acc) (return acc)
manyWithIndex :: Alternative f => (Int -> f ()) -> f ()
manyWithIndex indexHandler =
loop 0
where
loop index =
indexHandler index *> loop (succ index) <|> pure ()
shouldFail :: MonadPlus m => m a -> m ()
shouldFail p =
join (mplus (p >> return mzero) (return (return ())))
skipSepBy :: Alternative m => m () -> m () -> m ()
skipSepBy one sep =
skipSepBy1 one sep <|> pure ()
skipSepBy1 :: Alternative m => m () -> m () -> m ()
skipSepBy1 one sep =
one *> remainders
where
remainders =
(sep *> one *> remainders) <|> pure ()
skipMany :: Alternative f => f a -> f ()
skipMany fx =
loop
where
loop =
(fx *> loop) <|> pure ()
skipMany1 :: Alternative f => f a -> f ()
skipMany1 fx =
fx *> skipMany fx