module Control.Monad.Combinators.NonEmpty
( some,
endBy1,
someTill,
sepBy1,
sepEndBy1,
)
where
import Control.Monad
import qualified Control.Monad.Combinators as C
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NE
some :: MonadPlus m => m a -> m (NonEmpty a)
some :: m a -> m (NonEmpty a)
some m a
p = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
NE.fromList ([a] -> NonEmpty a) -> m [a] -> m (NonEmpty a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a -> m [a]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
C.some m a
p
{-# INLINE some #-}
endBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a)
endBy1 :: m a -> m sep -> m (NonEmpty a)
endBy1 m a
p m sep
sep = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
NE.fromList ([a] -> NonEmpty a) -> m [a] -> m (NonEmpty a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a -> m sep -> m [a]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
C.endBy1 m a
p m sep
sep
{-# INLINE endBy1 #-}
someTill :: MonadPlus m => m a -> m end -> m (NonEmpty a)
someTill :: m a -> m end -> m (NonEmpty a)
someTill m a
p m end
end = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
NE.fromList ([a] -> NonEmpty a) -> m [a] -> m (NonEmpty a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a -> m end -> m [a]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
C.someTill m a
p m end
end
{-# INLINE someTill #-}
sepBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a)
sepBy1 :: m a -> m sep -> m (NonEmpty a)
sepBy1 m a
p m sep
sep = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
NE.fromList ([a] -> NonEmpty a) -> m [a] -> m (NonEmpty a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a -> m sep -> m [a]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
C.sepBy1 m a
p m sep
sep
{-# INLINE sepBy1 #-}
sepEndBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a)
sepEndBy1 :: m a -> m sep -> m (NonEmpty a)
sepEndBy1 m a
p m sep
sep = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
NE.fromList ([a] -> NonEmpty a) -> m [a] -> m (NonEmpty a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a -> m sep -> m [a]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
C.sepEndBy1 m a
p m sep
sep
{-# INLINE sepEndBy1 #-}