{- 
    Copyright 2013-2017 Mario Blazevic

    License: BSD3 (see BSD3-LICENSE.txt file)
-}

-- | This module defines the 'TextualMonoid' class and several of its instances.
-- 

{-# LANGUAGE Haskell2010, FlexibleInstances #-}

module Data.Monoid.Textual (
   TextualMonoid(..)
   )
where

import qualified Data.Foldable as Foldable
import qualified Data.Traversable as Traversable
import Data.Functor -- ((<$>))
import qualified Data.List as List
import qualified Data.Text as Text
import qualified Data.Text.Lazy as LazyText
import Data.Text (Text)
import Data.Monoid -- (Monoid(mappend, mempty))
import qualified Data.Sequence as Sequence
import Data.String (IsString(fromString))
import Data.Int (Int64)

import Data.Semigroup.Cancellative (LeftReductive)
import Data.Monoid.GCD (LeftGCDMonoid)
import Data.Monoid.Factorial (FactorialMonoid)
import qualified Data.Monoid.Factorial as Factorial

import Prelude hiding (all, any, break, concatMap, dropWhile, foldl, foldl1, foldr, foldr1, map,
                       scanl, scanl1, scanr, scanr1, span, takeWhile)

-- | The 'TextualMonoid' class is an extension of 'FactorialMonoid' specialized for monoids that can contain
-- characters. Its methods are generally equivalent to their namesake functions from "Data.List" and "Data.Text", and
-- they satisfy the following laws:
-- 
-- > unfoldr splitCharacterPrefix . fromString == id
-- > splitCharacterPrefix . primePrefix == fmap (\(c, t)-> (c, mempty)) . splitCharacterPrefix
-- >
-- > map f . fromString == fromString . List.map f
-- > concatMap (fromString . f) . fromString == fromString . List.concatMap f
-- >
-- > foldl  ft fc a . fromString == List.foldl  fc a
-- > foldr  ft fc a . fromString == List.foldr  fc a
-- > foldl' ft fc a . fromString == List.foldl' fc a
-- >
-- > scanl f c . fromString == fromString . List.scanl f c
-- > scanr f c . fromString == fromString . List.scanr f c
-- > mapAccumL f a . fromString == fmap fromString . List.mapAccumL f a
-- > mapAccumL f a . fromString == fmap fromString . List.mapAccumL f a
-- >
-- > takeWhile pt pc . fromString == fromString . takeWhile pc
-- > dropWhile pt pc . fromString == fromString . dropWhile pc
-- >
-- > mconcat . intersperse (singleton c) . split (== c) == id
-- > find p . fromString == List.find p
-- > elem c . fromString == List.elem c
--
-- A 'TextualMonoid' may contain non-character data insterspersed between its characters. Every class method that
-- returns a modified 'TextualMonoid' instance generally preserves this non-character data. Methods like 'foldr' can
-- access both the non-character and character data and expect two arguments for the two purposes. For each of these
-- methods there is also a simplified version with underscore in name (like 'foldr_') that ignores the non-character
-- data.
--
-- All of the following expressions are identities:
--
-- > map id
-- > concatMap singleton
-- > foldl  (<>) (\a c-> a <> singleton c) mempty
-- > foldr  (<>) ((<>) . singleton) mempty
-- > foldl' (<>) (\a c-> a <> singleton c) mempty
-- > scanl1 (const id)
-- > scanr1 const
-- > uncurry (mapAccumL (,))
-- > uncurry (mapAccumR (,))
-- > takeWhile (const True) (const True)
-- > dropWhile (const False) (const False)
-- > toString undefined . fromString
-- > toText undefined . fromText

class (IsString t, LeftReductive t, LeftGCDMonoid t, FactorialMonoid t) => TextualMonoid t where
   -- | Contructs a new data type instance Like 'fromString', but from a 'Text' input instead of 'String'.
   --
   -- > fromText == fromString . Text.unpack
   fromText :: Text -> t
   -- | Creates a prime monoid containing a single character.
   --
   -- > singleton c == fromString [c]
   singleton :: Char -> t
   -- | Specialized version of 'Factorial.splitPrimePrefix'. Every prime factor of a textual monoid must consist of a
   -- single character or no character at all.
   splitCharacterPrefix :: t -> Maybe (Char, t)
   -- | Extracts a single character that prefixes the monoid, if the monoid begins with a character. Otherwise returns
   -- 'Nothing'.
   --
   -- > characterPrefix == fmap fst . splitCharacterPrefix
   characterPrefix :: t -> Maybe Char
   -- | Equivalent to 'List.map' from "Data.List" with a @Char -> Char@ function. Preserves all non-character data.
   --
   -- > map f == concatMap (singleton . f)
   map :: (Char -> Char) -> t -> t
   -- | Equivalent to 'List.concatMap' from "Data.List" with a @Char -> String@ function. Preserves all non-character
   -- data.
   concatMap :: (Char -> t) -> t -> t
   -- | Returns the list of characters the monoid contains, once the argument function converts all its non-character
   -- factors into characters.
   toString :: (t -> String) -> t -> String
   -- | Converts the monoid into 'Text', given a function to convert the non-character factors into chunks of 'Text'.
   toText :: (t -> Text) -> t -> Text
   -- | Equivalent to 'List.any' from "Data.List". Ignores all non-character data.
   any :: (Char -> Bool) -> t -> Bool
   -- | Equivalent to 'List.all' from "Data.List". Ignores all non-character data.
   all :: (Char -> Bool) -> t -> Bool

   -- | The first argument folds over the non-character prime factors, the second over characters. Otherwise equivalent
   -- to 'List.foldl' from "Data.List".
   foldl   :: (a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
   -- | Strict version of 'foldl'.
   foldl'  :: (a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
   -- | The first argument folds over the non-character prime factors, the second over characters. Otherwise equivalent
   -- to 'List.foldl\'' from "Data.List".
   foldr   :: (t -> a -> a) -> (Char -> a -> a) -> a -> t -> a

   -- | Equivalent to 'List.scanl' from "Data.List" when applied to a 'String', but preserves all non-character data.
   scanl :: (Char -> Char -> Char) -> Char -> t -> t
   -- | Equivalent to 'List.scanl1' from "Data.List" when applied to a 'String', but preserves all non-character data.
   --
   -- > scanl f c == scanl1 f . (singleton c <>)
   scanl1 :: (Char -> Char -> Char) -> t -> t
   -- | Equivalent to 'List.scanr' from "Data.List" when applied to a 'String', but preserves all non-character data.
   scanr :: (Char -> Char -> Char) -> Char -> t -> t
   -- | Equivalent to 'List.scanr1' from "Data.List" when applied to a 'String', but preserves all non-character data.
   --
   -- > scanr f c == scanr1 f . (<> singleton c)
   scanr1 :: (Char -> Char -> Char) -> t -> t
   -- | Equivalent to 'List.mapAccumL' from "Data.List" when applied to a 'String', but preserves all non-character
   -- data.
   mapAccumL :: (a -> Char -> (a, Char)) -> a -> t -> (a, t)
   -- | Equivalent to 'List.mapAccumR' from "Data.List" when applied to a 'String', but preserves all non-character
   -- data.
   mapAccumR :: (a -> Char -> (a, Char)) -> a -> t -> (a, t)

   -- | The first predicate tests the non-character data, the second one the characters. Otherwise equivalent to
   -- 'List.takeWhile' from "Data.List" when applied to a 'String'.
   takeWhile :: (t -> Bool) -> (Char -> Bool) -> t -> t
   -- | The first predicate tests the non-character data, the second one the characters. Otherwise equivalent to
   -- 'List.dropWhile' from "Data.List" when applied to a 'String'.
   dropWhile :: (t -> Bool) -> (Char -> Bool) -> t -> t
   -- | 'break pt pc' is equivalent to @span (not . pt) (not . pc)@.
   break :: (t -> Bool) -> (Char -> Bool) -> t -> (t, t)
   -- | 'span pt pc t' is equivalent to @(takeWhile pt pc t, dropWhile pt pc t)@.
   span :: (t -> Bool) -> (Char -> Bool) -> t -> (t, t)
   -- | A stateful variant of 'span', threading the result of the test function as long as it returns 'Just'.
   spanMaybe :: s -> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
   -- | Strict version of 'spanMaybe'.
   spanMaybe' :: s -> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
   -- | Splits the monoid into components delimited by character separators satisfying the given predicate. The
   -- characters satisfying the predicate are not a part of the result.
   --
   -- > split p == Factorial.split (maybe False p . characterPrefix)
   split :: (Char -> Bool) -> t -> [t]
   -- | Like 'List.find' from "Data.List" when applied to a 'String'. Ignores non-character data.
   find :: (Char -> Bool) -> t -> Maybe Char
   -- | Like 'List.elem' from "Data.List" when applied to a 'String'. Ignores non-character data.
   elem :: Char -> t -> Bool

   -- | > foldl_ = foldl const
   foldl_   :: (a -> Char -> a) -> a -> t -> a
   foldl_'  :: (a -> Char -> a) -> a -> t -> a
   foldr_   :: (Char -> a -> a) -> a -> t -> a
   -- | > takeWhile_ = takeWhile . const
   takeWhile_ :: Bool -> (Char -> Bool) -> t -> t
   -- | > dropWhile_ = dropWhile . const
   dropWhile_ :: Bool -> (Char -> Bool) -> t -> t
   -- | > break_ = break . const
   break_ :: Bool -> (Char -> Bool) -> t -> (t, t)
   -- | > span_ = span . const
   span_ :: Bool -> (Char -> Bool) -> t -> (t, t)
   -- | > spanMaybe_ s = spanMaybe s (const . Just)
   spanMaybe_ :: s -> (s -> Char -> Maybe s) -> t -> (t, t, s)
   spanMaybe_' :: s -> (s -> Char -> Maybe s) -> t -> (t, t, s)


   fromText = String -> t
forall a. IsString a => String -> a
fromString (String -> t) -> (Text -> String) -> Text -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
Text.unpack
   singleton = String -> t
forall a. IsString a => String -> a
fromString (String -> t) -> (Char -> String) -> Char -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> String -> String
forall a. a -> [a] -> [a]
:[])

   characterPrefix = ((Char, t) -> Char) -> Maybe (Char, t) -> Maybe Char
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Char, t) -> Char
forall a b. (a, b) -> a
fst (Maybe (Char, t) -> Maybe Char)
-> (t -> Maybe (Char, t)) -> t -> Maybe Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Maybe (Char, t)
forall t. TextualMonoid t => t -> Maybe (Char, t)
splitCharacterPrefix

   map Char -> Char
f = (Char -> t) -> t -> t
forall t. TextualMonoid t => (Char -> t) -> t -> t
concatMap (Char -> t
forall t. TextualMonoid t => Char -> t
singleton (Char -> t) -> (Char -> Char) -> Char -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Char
f)
   concatMap Char -> t
f = (t -> t -> t) -> (Char -> t -> t) -> t -> t -> t
forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
foldr t -> t -> t
forall a. Monoid a => a -> a -> a
mappend (t -> t -> t
forall a. Monoid a => a -> a -> a
mappend (t -> t -> t) -> (Char -> t) -> Char -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> t
f) t
forall a. Monoid a => a
mempty
   toString t -> String
f = (t -> String -> String)
-> (Char -> String -> String) -> String -> t -> String
forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
foldr (String -> String -> String
forall a. Monoid a => a -> a -> a
mappend (String -> String -> String)
-> (t -> String) -> t -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> String
f) (:) []
   toText t -> Text
f = String -> Text
Text.pack (String -> Text) -> (t -> String) -> t -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t -> String) -> t -> String
forall t. TextualMonoid t => (t -> String) -> t -> String
toString (Text -> String
Text.unpack (Text -> String) -> (t -> Text) -> t -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Text
f)
   all Char -> Bool
p = (t -> Bool -> Bool) -> (Char -> Bool -> Bool) -> Bool -> t -> Bool
forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
foldr ((Bool -> Bool) -> t -> Bool -> Bool
forall a b. a -> b -> a
const Bool -> Bool
forall a. a -> a
id) (Bool -> Bool -> Bool
(&&) (Bool -> Bool -> Bool) -> (Char -> Bool) -> Char -> Bool -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
p) Bool
True
   any Char -> Bool
p = (t -> Bool -> Bool) -> (Char -> Bool -> Bool) -> Bool -> t -> Bool
forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
foldr ((Bool -> Bool) -> t -> Bool -> Bool
forall a b. a -> b -> a
const Bool -> Bool
forall a. a -> a
id) (Bool -> Bool -> Bool
(||) (Bool -> Bool -> Bool) -> (Char -> Bool) -> Char -> Bool -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
p) Bool
False

   foldl a -> t -> a
ft a -> Char -> a
fc = (a -> t -> a) -> a -> t -> a
forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl (\a
a t
prime-> a -> (Char -> a) -> Maybe Char -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (a -> t -> a
ft a
a t
prime) (a -> Char -> a
fc a
a) (t -> Maybe Char
forall t. TextualMonoid t => t -> Maybe Char
characterPrefix t
prime))
   foldr t -> a -> a
ft Char -> a -> a
fc = (t -> a -> a) -> a -> t -> a
forall m a. Factorial m => (m -> a -> a) -> a -> m -> a
Factorial.foldr (\t
prime-> (a -> a) -> (Char -> a -> a) -> Maybe Char -> a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (t -> a -> a
ft t
prime) Char -> a -> a
fc (t -> Maybe Char
forall t. TextualMonoid t => t -> Maybe Char
characterPrefix t
prime))
   foldl' a -> t -> a
ft a -> Char -> a
fc = (a -> t -> a) -> a -> t -> a
forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl' (\a
a t
prime-> a -> (Char -> a) -> Maybe Char -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (a -> t -> a
ft a
a t
prime) (a -> Char -> a
fc a
a) (t -> Maybe Char
forall t. TextualMonoid t => t -> Maybe Char
characterPrefix t
prime))
   foldl_ = (a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
foldl a -> t -> a
forall a b. a -> b -> a
const
   foldr_ = (t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
foldr ((a -> a) -> t -> a -> a
forall a b. a -> b -> a
const a -> a
forall a. a -> a
id)
   foldl_' = (a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
foldl' a -> t -> a
forall a b. a -> b -> a
const

   scanl Char -> Char -> Char
f Char
c = t -> t -> t
forall a. Monoid a => a -> a -> a
mappend (Char -> t
forall t. TextualMonoid t => Char -> t
singleton Char
c) (t -> t) -> (t -> t) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t, Char) -> t
forall a b. (a, b) -> a
fst ((t, Char) -> t) -> (t -> (t, Char)) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((t, Char) -> t -> (t, Char))
-> ((t, Char) -> Char -> (t, Char)) -> (t, Char) -> t -> (t, Char)
forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
foldl (t, Char) -> t -> (t, Char)
forall t. Monoid t => (t, Char) -> t -> (t, Char)
foldlOther ((Char -> Char -> Char) -> (t, Char) -> Char -> (t, Char)
forall t.
TextualMonoid t =>
(Char -> Char -> Char) -> (t, Char) -> Char -> (t, Char)
foldlChars Char -> Char -> Char
f) (t
forall a. Monoid a => a
mempty, Char
c)
   scanl1 Char -> Char -> Char
f t
t = case (t -> Maybe (t, t)
forall m. FactorialMonoid m => m -> Maybe (m, m)
Factorial.splitPrimePrefix t
t, t -> Maybe (Char, t)
forall t. TextualMonoid t => t -> Maybe (Char, t)
splitCharacterPrefix t
t)
                of (Maybe (t, t)
Nothing, Maybe (Char, t)
_) -> t
t
                   (Just (t
prefix, t
suffix), Maybe (Char, t)
Nothing) -> t -> t -> t
forall a. Monoid a => a -> a -> a
mappend t
prefix ((Char -> Char -> Char) -> t -> t
forall t. TextualMonoid t => (Char -> Char -> Char) -> t -> t
scanl1 Char -> Char -> Char
f t
suffix)
                   (Just (t, t)
_, Just (Char
c, t
suffix)) -> (Char -> Char -> Char) -> Char -> t -> t
forall t.
TextualMonoid t =>
(Char -> Char -> Char) -> Char -> t -> t
scanl Char -> Char -> Char
f Char
c t
suffix
   scanr Char -> Char -> Char
f Char
c = (t, Char) -> t
forall a b. (a, b) -> a
fst ((t, Char) -> t) -> (t -> (t, Char)) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t -> (t, Char) -> (t, Char))
-> (Char -> (t, Char) -> (t, Char)) -> (t, Char) -> t -> (t, Char)
forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
foldr t -> (t, Char) -> (t, Char)
forall t a. Monoid t => t -> (t, a) -> (t, a)
foldrOther ((Char -> Char -> Char) -> Char -> (t, Char) -> (t, Char)
forall t.
TextualMonoid t =>
(Char -> Char -> Char) -> Char -> (t, Char) -> (t, Char)
foldrChars Char -> Char -> Char
f) (Char -> t
forall t. TextualMonoid t => Char -> t
singleton Char
c, Char
c)
   scanr1 Char -> Char -> Char
f = (t, Maybe Char) -> t
forall a b. (a, b) -> a
fst ((t, Maybe Char) -> t) -> (t -> (t, Maybe Char)) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t -> (t, Maybe Char) -> (t, Maybe Char))
-> (Char -> (t, Maybe Char) -> (t, Maybe Char))
-> (t, Maybe Char)
-> t
-> (t, Maybe Char)
forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
foldr t -> (t, Maybe Char) -> (t, Maybe Char)
forall t a. Monoid t => t -> (t, a) -> (t, a)
foldrOther Char -> (t, Maybe Char) -> (t, Maybe Char)
forall a.
TextualMonoid a =>
Char -> (a, Maybe Char) -> (a, Maybe Char)
fc (t
forall a. Monoid a => a
mempty, Maybe Char
forall a. Maybe a
Nothing)
      where fc :: Char -> (a, Maybe Char) -> (a, Maybe Char)
fc Char
c (a
t, Maybe Char
Nothing) = (a -> a -> a
forall a. Monoid a => a -> a -> a
mappend (Char -> a
forall t. TextualMonoid t => Char -> t
singleton Char
c) a
t, Char -> Maybe Char
forall a. a -> Maybe a
Just Char
c)
            fc Char
c1 (a
t, Just Char
c2) = (a -> a -> a
forall a. Monoid a => a -> a -> a
mappend (Char -> a
forall t. TextualMonoid t => Char -> t
singleton Char
c') a
t, Char -> Maybe Char
forall a. a -> Maybe a
Just Char
c')
               where c' :: Char
c' = Char -> Char -> Char
f Char
c1 Char
c2
   mapAccumL a -> Char -> (a, Char)
f a
a0 = ((a, t) -> t -> (a, t))
-> ((a, t) -> Char -> (a, t)) -> (a, t) -> t -> (a, t)
forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
foldl (a, t) -> t -> (a, t)
forall b a. Monoid b => (a, b) -> b -> (a, b)
ft (a, t) -> Char -> (a, t)
forall b. TextualMonoid b => (a, b) -> Char -> (a, b)
fc (a
a0, t
forall a. Monoid a => a
mempty)
      where ft :: (a, b) -> b -> (a, b)
ft (a
a, b
t1) b
t2 = (a
a, b -> b -> b
forall a. Monoid a => a -> a -> a
mappend b
t1 b
t2)
            fc :: (a, b) -> Char -> (a, b)
fc (a
a, b
t) Char
c = (a
a', b -> b -> b
forall a. Monoid a => a -> a -> a
mappend b
t (Char -> b
forall t. TextualMonoid t => Char -> t
singleton Char
c'))
               where (a
a', Char
c') = a -> Char -> (a, Char)
f a
a Char
c
   mapAccumR a -> Char -> (a, Char)
f a
a0 = (t -> (a, t) -> (a, t))
-> (Char -> (a, t) -> (a, t)) -> (a, t) -> t -> (a, t)
forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
foldr t -> (a, t) -> (a, t)
forall b a. Monoid b => b -> (a, b) -> (a, b)
ft Char -> (a, t) -> (a, t)
forall b. TextualMonoid b => Char -> (a, b) -> (a, b)
fc (a
a0, t
forall a. Monoid a => a
mempty)
      where ft :: b -> (a, b) -> (a, b)
ft b
t1 (a
a, b
t2) = (a
a, b -> b -> b
forall a. Monoid a => a -> a -> a
mappend b
t1 b
t2)
            fc :: Char -> (a, b) -> (a, b)
fc Char
c (a
a, b
t) = (a
a', b -> b -> b
forall a. Monoid a => a -> a -> a
mappend (Char -> b
forall t. TextualMonoid t => Char -> t
singleton Char
c') b
t)
               where (a
a', Char
c') = a -> Char -> (a, Char)
f a
a Char
c

   takeWhile t -> Bool
pt Char -> Bool
pc = (t, t) -> t
forall a b. (a, b) -> a
fst ((t, t) -> t) -> (t -> (t, t)) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t -> Bool) -> (Char -> Bool) -> t -> (t, t)
forall t.
TextualMonoid t =>
(t -> Bool) -> (Char -> Bool) -> t -> (t, t)
span t -> Bool
pt Char -> Bool
pc
   dropWhile t -> Bool
pt Char -> Bool
pc = (t, t) -> t
forall a b. (a, b) -> b
snd ((t, t) -> t) -> (t -> (t, t)) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t -> Bool) -> (Char -> Bool) -> t -> (t, t)
forall t.
TextualMonoid t =>
(t -> Bool) -> (Char -> Bool) -> t -> (t, t)
span t -> Bool
pt Char -> Bool
pc
   span t -> Bool
pt Char -> Bool
pc = (t -> Bool) -> t -> (t, t)
forall m. FactorialMonoid m => (m -> Bool) -> m -> (m, m)
Factorial.span (\t
prime-> Bool -> (Char -> Bool) -> Maybe Char -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (t -> Bool
pt t
prime) Char -> Bool
pc (t -> Maybe Char
forall t. TextualMonoid t => t -> Maybe Char
characterPrefix t
prime))
   break t -> Bool
pt Char -> Bool
pc = (t -> Bool) -> t -> (t, t)
forall m. FactorialMonoid m => (m -> Bool) -> m -> (m, m)
Factorial.break (\t
prime-> Bool -> (Char -> Bool) -> Maybe Char -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (t -> Bool
pt t
prime) Char -> Bool
pc (t -> Maybe Char
forall t. TextualMonoid t => t -> Maybe Char
characterPrefix t
prime))
   spanMaybe s
s0 s -> t -> Maybe s
ft s -> Char -> Maybe s
fc t
t0 = (t -> t) -> s -> t -> (t, t, s)
spanAfter t -> t
forall a. a -> a
id s
s0 t
t0
      where spanAfter :: (t -> t) -> s -> t -> (t, t, s)
spanAfter t -> t
g s
s t
t = case t -> Maybe (t, t)
forall m. FactorialMonoid m => m -> Maybe (m, m)
Factorial.splitPrimePrefix t
t
                              of Just (t
prime, t
rest) | Just s
s' <- Maybe s -> (Char -> Maybe s) -> Maybe Char -> Maybe s
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (s -> t -> Maybe s
ft s
s t
prime) (s -> Char -> Maybe s
fc s
s) (t -> Maybe Char
forall t. TextualMonoid t => t -> Maybe Char
characterPrefix t
prime) ->
                                                        (t -> t) -> s -> t -> (t, t, s)
spanAfter (t -> t
g (t -> t) -> (t -> t) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> t -> t
forall a. Monoid a => a -> a -> a
mappend t
prime) s
s' t
rest
                                                    | Bool
otherwise -> (t -> t
g t
forall a. Monoid a => a
mempty, t
t, s
s)
                                 Maybe (t, t)
Nothing -> (t
t0, t
t, s
s)
   spanMaybe' s
s0 s -> t -> Maybe s
ft s -> Char -> Maybe s
fc t
t0 = (t -> t) -> s -> t -> (t, t, s)
spanAfter t -> t
forall a. a -> a
id s
s0 t
t0
      where spanAfter :: (t -> t) -> s -> t -> (t, t, s)
spanAfter t -> t
g s
s t
t = s -> (t, t, s) -> (t, t, s)
seq s
s ((t, t, s) -> (t, t, s)) -> (t, t, s) -> (t, t, s)
forall a b. (a -> b) -> a -> b
$
                              case t -> Maybe (t, t)
forall m. FactorialMonoid m => m -> Maybe (m, m)
Factorial.splitPrimePrefix t
t
                              of Just (t
prime, t
rest) | Just s
s' <- Maybe s -> (Char -> Maybe s) -> Maybe Char -> Maybe s
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (s -> t -> Maybe s
ft s
s t
prime) (s -> Char -> Maybe s
fc s
s) (t -> Maybe Char
forall t. TextualMonoid t => t -> Maybe Char
characterPrefix t
prime) ->
                                                        (t -> t) -> s -> t -> (t, t, s)
spanAfter (t -> t
g (t -> t) -> (t -> t) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> t -> t
forall a. Monoid a => a -> a -> a
mappend t
prime) s
s' t
rest
                                                    | Bool
otherwise -> (t -> t
g t
forall a. Monoid a => a
mempty, t
t, s
s)
                                 Maybe (t, t)
Nothing -> (t
t0, t
t, s
s)
   takeWhile_ = (t -> Bool) -> (Char -> Bool) -> t -> t
forall t.
TextualMonoid t =>
(t -> Bool) -> (Char -> Bool) -> t -> t
takeWhile ((t -> Bool) -> (Char -> Bool) -> t -> t)
-> (Bool -> t -> Bool) -> Bool -> (Char -> Bool) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> t -> Bool
forall a b. a -> b -> a
const
   dropWhile_ = (t -> Bool) -> (Char -> Bool) -> t -> t
forall t.
TextualMonoid t =>
(t -> Bool) -> (Char -> Bool) -> t -> t
dropWhile ((t -> Bool) -> (Char -> Bool) -> t -> t)
-> (Bool -> t -> Bool) -> Bool -> (Char -> Bool) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> t -> Bool
forall a b. a -> b -> a
const
   break_ = (t -> Bool) -> (Char -> Bool) -> t -> (t, t)
forall t.
TextualMonoid t =>
(t -> Bool) -> (Char -> Bool) -> t -> (t, t)
break ((t -> Bool) -> (Char -> Bool) -> t -> (t, t))
-> (Bool -> t -> Bool) -> Bool -> (Char -> Bool) -> t -> (t, t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> t -> Bool
forall a b. a -> b -> a
const
   span_ = (t -> Bool) -> (Char -> Bool) -> t -> (t, t)
forall t.
TextualMonoid t =>
(t -> Bool) -> (Char -> Bool) -> t -> (t, t)
span ((t -> Bool) -> (Char -> Bool) -> t -> (t, t))
-> (Bool -> t -> Bool) -> Bool -> (Char -> Bool) -> t -> (t, t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> t -> Bool
forall a b. a -> b -> a
const
   spanMaybe_ s
s = s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
spanMaybe s
s (Maybe s -> t -> Maybe s
forall a b. a -> b -> a
const (Maybe s -> t -> Maybe s) -> (s -> Maybe s) -> s -> t -> Maybe s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Maybe s
forall a. a -> Maybe a
Just)
   spanMaybe_' s
s = s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
spanMaybe' s
s (Maybe s -> t -> Maybe s
forall a b. a -> b -> a
const (Maybe s -> t -> Maybe s) -> (s -> Maybe s) -> s -> t -> Maybe s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Maybe s
forall a. a -> Maybe a
Just)

   split Char -> Bool
p t
m = t
prefix t -> [t] -> [t]
forall a. a -> [a] -> [a]
: [t]
splitRest
      where (t
prefix, t
rest) = (t -> Bool) -> (Char -> Bool) -> t -> (t, t)
forall t.
TextualMonoid t =>
(t -> Bool) -> (Char -> Bool) -> t -> (t, t)
break (Bool -> t -> Bool
forall a b. a -> b -> a
const Bool
False) Char -> Bool
p t
m
            splitRest :: [t]
splitRest = case t -> Maybe (Char, t)
forall t. TextualMonoid t => t -> Maybe (Char, t)
splitCharacterPrefix t
rest
                        of Maybe (Char, t)
Nothing -> []
                           Just (Char
_, t
tl) -> (Char -> Bool) -> t -> [t]
forall t. TextualMonoid t => (Char -> Bool) -> t -> [t]
split Char -> Bool
p t
tl
   find Char -> Bool
p = (t -> Maybe Char -> Maybe Char)
-> (Char -> Maybe Char -> Maybe Char)
-> Maybe Char
-> t
-> Maybe Char
forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
foldr ((Maybe Char -> Maybe Char) -> t -> Maybe Char -> Maybe Char
forall a b. a -> b -> a
const Maybe Char -> Maybe Char
forall a. a -> a
id) (\Char
c Maybe Char
r-> if Char -> Bool
p Char
c then Char -> Maybe Char
forall a. a -> Maybe a
Just Char
c else Maybe Char
r) Maybe Char
forall a. Maybe a
Nothing
   elem Char
c = (Char -> Bool) -> t -> Bool
forall t. TextualMonoid t => (Char -> Bool) -> t -> Bool
any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
c)

   {-# INLINE characterPrefix #-}
   {-# INLINE concatMap #-}
   {-# INLINE dropWhile #-}
   {-# INLINE fromText #-}
   {-# INLINE map #-}
   {-# INLINE mapAccumL #-}
   {-# INLINE mapAccumR #-}
   {-# INLINE scanl #-}
   {-# INLINE scanl1 #-}
   {-# INLINE scanr #-}
   {-# INLINE scanr1 #-}
   {-# INLINE singleton #-}
   {-# INLINE spanMaybe #-}
   {-# INLINE spanMaybe' #-}
   {-# INLINE split #-}
   {-# INLINE takeWhile #-}
   {-# INLINE foldl_ #-}
   {-# INLINE foldl_' #-}
   {-# INLINE foldr_ #-}
   {-# INLINE spanMaybe_ #-}
   {-# INLINE spanMaybe_' #-}
   {-# INLINE span_ #-}
   {-# INLINE break_ #-}
   {-# INLINE takeWhile_ #-}
   {-# INLINE dropWhile_ #-}
   {-# MINIMAL splitCharacterPrefix #-}

foldlChars :: TextualMonoid t => (Char -> Char -> Char) -> (t, Char) -> Char -> (t, Char)
foldlOther :: Monoid t => (t, Char) -> t -> (t, Char)
foldrChars :: TextualMonoid t => (Char -> Char -> Char) -> Char -> (t, Char) -> (t, Char)
foldrOther :: Monoid t => t -> (t, a) -> (t, a)
foldlChars :: (Char -> Char -> Char) -> (t, Char) -> Char -> (t, Char)
foldlChars Char -> Char -> Char
f (t
t, Char
c1) Char
c2 = (t -> t -> t
forall a. Monoid a => a -> a -> a
mappend t
t (Char -> t
forall t. TextualMonoid t => Char -> t
singleton Char
c'), Char
c')
   where c' :: Char
c' = Char -> Char -> Char
f Char
c1 Char
c2
foldlOther :: (t, Char) -> t -> (t, Char)
foldlOther (t
t1, Char
c) t
t2 = (t -> t -> t
forall a. Monoid a => a -> a -> a
mappend t
t1 t
t2, Char
c)
foldrChars :: (Char -> Char -> Char) -> Char -> (t, Char) -> (t, Char)
foldrChars Char -> Char -> Char
f Char
c1 (t
t, Char
c2) = (t -> t -> t
forall a. Monoid a => a -> a -> a
mappend (Char -> t
forall t. TextualMonoid t => Char -> t
singleton Char
c') t
t, Char
c')
   where c' :: Char
c' = Char -> Char -> Char
f Char
c1 Char
c2
foldrOther :: t -> (t, a) -> (t, a)
foldrOther t
t1 (t
t2, a
c) = (t -> t -> t
forall a. Monoid a => a -> a -> a
mappend t
t1 t
t2, a
c)

instance TextualMonoid String where
   fromText :: Text -> String
fromText = Text -> String
Text.unpack
   singleton :: Char -> String
singleton Char
c = [Char
c]
   splitCharacterPrefix :: String -> Maybe (Char, String)
splitCharacterPrefix (Char
c:String
rest) = (Char, String) -> Maybe (Char, String)
forall a. a -> Maybe a
Just (Char
c, String
rest)
   splitCharacterPrefix [] = Maybe (Char, String)
forall a. Maybe a
Nothing
   characterPrefix :: String -> Maybe Char
characterPrefix (Char
c:String
_) = Char -> Maybe Char
forall a. a -> Maybe a
Just Char
c
   characterPrefix [] = Maybe Char
forall a. Maybe a
Nothing
   map :: (Char -> Char) -> String -> String
map = (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
List.map
   concatMap :: (Char -> String) -> String -> String
concatMap = (Char -> String) -> String -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
List.concatMap
   toString :: (String -> String) -> String -> String
toString = (String -> String) -> (String -> String) -> String -> String
forall a b. a -> b -> a
const String -> String
forall a. a -> a
id
   any :: (Char -> Bool) -> String -> Bool
any = (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
List.any
   all :: (Char -> Bool) -> String -> Bool
all = (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
List.all

   foldl :: (a -> String -> a) -> (a -> Char -> a) -> a -> String -> a
foldl   = ((a -> Char -> a) -> a -> String -> a)
-> (a -> String -> a) -> (a -> Char -> a) -> a -> String -> a
forall a b. a -> b -> a
const (a -> Char -> a) -> a -> String -> a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl
   foldl' :: (a -> String -> a) -> (a -> Char -> a) -> a -> String -> a
foldl'  = ((a -> Char -> a) -> a -> String -> a)
-> (a -> String -> a) -> (a -> Char -> a) -> a -> String -> a
forall a b. a -> b -> a
const (a -> Char -> a) -> a -> String -> a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl'
   foldr :: (String -> a -> a) -> (Char -> a -> a) -> a -> String -> a
foldr   = ((Char -> a -> a) -> a -> String -> a)
-> (String -> a -> a) -> (Char -> a -> a) -> a -> String -> a
forall a b. a -> b -> a
const (Char -> a -> a) -> a -> String -> a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
List.foldr

   scanl :: (Char -> Char -> Char) -> Char -> String -> String
scanl = (Char -> Char -> Char) -> Char -> String -> String
forall b a. (b -> a -> b) -> b -> [a] -> [b]
List.scanl
   scanl1 :: (Char -> Char -> Char) -> String -> String
scanl1 = (Char -> Char -> Char) -> String -> String
forall a. (a -> a -> a) -> [a] -> [a]
List.scanl1
   scanr :: (Char -> Char -> Char) -> Char -> String -> String
scanr = (Char -> Char -> Char) -> Char -> String -> String
forall a b. (a -> b -> b) -> b -> [a] -> [b]
List.scanr
   scanr1 :: (Char -> Char -> Char) -> String -> String
scanr1 = (Char -> Char -> Char) -> String -> String
forall a. (a -> a -> a) -> [a] -> [a]
List.scanr1
   mapAccumL :: (a -> Char -> (a, Char)) -> a -> String -> (a, String)
mapAccumL = (a -> Char -> (a, Char)) -> a -> String -> (a, String)
forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> (a, c)) -> a -> t b -> (a, t c)
List.mapAccumL
   mapAccumR :: (a -> Char -> (a, Char)) -> a -> String -> (a, String)
mapAccumR = (a -> Char -> (a, Char)) -> a -> String -> (a, String)
forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> (a, c)) -> a -> t b -> (a, t c)
List.mapAccumR

   takeWhile :: (String -> Bool) -> (Char -> Bool) -> String -> String
takeWhile String -> Bool
_ = (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
List.takeWhile
   dropWhile :: (String -> Bool) -> (Char -> Bool) -> String -> String
dropWhile String -> Bool
_ = (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
List.dropWhile
   break :: (String -> Bool) -> (Char -> Bool) -> String -> (String, String)
break String -> Bool
_ = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
List.break
   span :: (String -> Bool) -> (Char -> Bool) -> String -> (String, String)
span String -> Bool
_ = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
List.span
   spanMaybe :: s
-> (s -> String -> Maybe s)
-> (s -> Char -> Maybe s)
-> String
-> (String, String, s)
spanMaybe s
s0 s -> String -> Maybe s
_ft s -> Char -> Maybe s
fc String
l = (String -> String
prefix' [], String -> String
suffix' [], s
s')
      where (String -> String
prefix', String -> String
suffix', s
s', Bool
_) = ((String -> String, String -> String, s, Bool)
 -> Char -> (String -> String, String -> String, s, Bool))
-> (String -> String, String -> String, s, Bool)
-> String
-> (String -> String, String -> String, s, Bool)
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' (String -> String, String -> String, s, Bool)
-> Char -> (String -> String, String -> String, s, Bool)
forall c.
(String -> c, String -> String, s, Bool)
-> Char -> (String -> c, String -> String, s, Bool)
g (String -> String
forall a. a -> a
id, String -> String
forall a. a -> a
id, s
s0, Bool
True) String
l
            g :: (String -> c, String -> String, s, Bool)
-> Char -> (String -> c, String -> String, s, Bool)
g (String -> c
prefix, String -> String
suffix, s
s, Bool
live) Char
c | Bool
live, Just s
s1 <- s -> Char -> Maybe s
fc s
s Char
c = (String -> c
prefix (String -> c) -> (String -> String) -> String -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char
cChar -> String -> String
forall a. a -> [a] -> [a]
:), String -> String
forall a. a -> a
id, s
s1, Bool
True)
                                          | Bool
otherwise = (String -> c
prefix, String -> String
suffix (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char
cChar -> String -> String
forall a. a -> [a] -> [a]
:), s
s, Bool
False)
   spanMaybe' :: s
-> (s -> String -> Maybe s)
-> (s -> Char -> Maybe s)
-> String
-> (String, String, s)
spanMaybe' s
s0 s -> String -> Maybe s
_ft s -> Char -> Maybe s
fc String
l = (String -> String
prefix' [], String -> String
suffix' [], s
s')
      where (String -> String
prefix', String -> String
suffix', s
s', Bool
_) = ((String -> String, String -> String, s, Bool)
 -> Char -> (String -> String, String -> String, s, Bool))
-> (String -> String, String -> String, s, Bool)
-> String
-> (String -> String, String -> String, s, Bool)
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' (String -> String, String -> String, s, Bool)
-> Char -> (String -> String, String -> String, s, Bool)
forall c.
(String -> c, String -> String, s, Bool)
-> Char -> (String -> c, String -> String, s, Bool)
g (String -> String
forall a. a -> a
id, String -> String
forall a. a -> a
id, s
s0, Bool
True) String
l
            g :: (String -> c, String -> String, s, Bool)
-> Char -> (String -> c, String -> String, s, Bool)
g (String -> c
prefix, String -> String
suffix, s
s, Bool
live) Char
c | Bool
live, Just s
s1 <- s -> Char -> Maybe s
fc s
s Char
c = s
-> (String -> c, String -> String, s, Bool)
-> (String -> c, String -> String, s, Bool)
seq s
s1 (String -> c
prefix (String -> c) -> (String -> String) -> String -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char
cChar -> String -> String
forall a. a -> [a] -> [a]
:), String -> String
forall a. a -> a
id, s
s1, Bool
True)
                                          | Bool
otherwise = (String -> c
prefix, String -> String
suffix (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char
cChar -> String -> String
forall a. a -> [a] -> [a]
:), s
s, Bool
False)
   find :: (Char -> Bool) -> String -> Maybe Char
find = (Char -> Bool) -> String -> Maybe Char
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
List.find
   elem :: Char -> String -> Bool
elem = Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
List.elem

   {-# INLINE all #-}
   {-# INLINE any #-}
   {-# INLINE break #-}
   {-# INLINE characterPrefix #-}
   {-# INLINE concatMap #-}
   {-# INLINE dropWhile #-}
   {-# INLINE elem #-}
   {-# INLINE find #-}
   {-# INLINE foldl   #-}
   {-# INLINE foldl'  #-}
   {-# INLINE foldr   #-}
   {-# INLINE fromText #-}
   {-# INLINE map #-}
   {-# INLINE mapAccumL #-}
   {-# INLINE mapAccumR #-}
   {-# INLINE scanl #-}
   {-# INLINE scanl1 #-}
   {-# INLINE scanr #-}
   {-# INLINE scanr1 #-}
   {-# INLINE singleton #-}
   {-# INLINE span #-}
   {-# INLINE spanMaybe #-}
   {-# INLINE spanMaybe' #-}
   {-# INLINE splitCharacterPrefix #-}
   {-# INLINE takeWhile #-}

instance TextualMonoid Text where
   fromText :: Text -> Text
fromText = Text -> Text
forall a. a -> a
id
   singleton :: Char -> Text
singleton = Char -> Text
Text.singleton
   splitCharacterPrefix :: Text -> Maybe (Char, Text)
splitCharacterPrefix = Text -> Maybe (Char, Text)
Text.uncons
   characterPrefix :: Text -> Maybe Char
characterPrefix Text
t = if Text -> Bool
Text.null Text
t then Maybe Char
forall a. Maybe a
Nothing else Char -> Maybe Char
forall a. a -> Maybe a
Just (Text -> Char
Text.head Text
t)
   map :: (Char -> Char) -> Text -> Text
map = (Char -> Char) -> Text -> Text
Text.map
   concatMap :: (Char -> Text) -> Text -> Text
concatMap = (Char -> Text) -> Text -> Text
Text.concatMap
   toString :: (Text -> String) -> Text -> String
toString = (Text -> String) -> (Text -> String) -> Text -> String
forall a b. a -> b -> a
const Text -> String
Text.unpack
   toText :: (Text -> Text) -> Text -> Text
toText = (Text -> Text) -> (Text -> Text) -> Text -> Text
forall a b. a -> b -> a
const Text -> Text
forall a. a -> a
id
   any :: (Char -> Bool) -> Text -> Bool
any = (Char -> Bool) -> Text -> Bool
Text.any
   all :: (Char -> Bool) -> Text -> Bool
all = (Char -> Bool) -> Text -> Bool
Text.all

   foldl :: (a -> Text -> a) -> (a -> Char -> a) -> a -> Text -> a
foldl   = ((a -> Char -> a) -> a -> Text -> a)
-> (a -> Text -> a) -> (a -> Char -> a) -> a -> Text -> a
forall a b. a -> b -> a
const (a -> Char -> a) -> a -> Text -> a
forall a. (a -> Char -> a) -> a -> Text -> a
Text.foldl
   foldl' :: (a -> Text -> a) -> (a -> Char -> a) -> a -> Text -> a
foldl'  = ((a -> Char -> a) -> a -> Text -> a)
-> (a -> Text -> a) -> (a -> Char -> a) -> a -> Text -> a
forall a b. a -> b -> a
const (a -> Char -> a) -> a -> Text -> a
forall a. (a -> Char -> a) -> a -> Text -> a
Text.foldl'
   foldr :: (Text -> a -> a) -> (Char -> a -> a) -> a -> Text -> a
foldr   = ((Char -> a -> a) -> a -> Text -> a)
-> (Text -> a -> a) -> (Char -> a -> a) -> a -> Text -> a
forall a b. a -> b -> a
const (Char -> a -> a) -> a -> Text -> a
forall a. (Char -> a -> a) -> a -> Text -> a
Text.foldr

   scanl :: (Char -> Char -> Char) -> Char -> Text -> Text
scanl = (Char -> Char -> Char) -> Char -> Text -> Text
Text.scanl
   scanl1 :: (Char -> Char -> Char) -> Text -> Text
scanl1 = (Char -> Char -> Char) -> Text -> Text
Text.scanl1
   scanr :: (Char -> Char -> Char) -> Char -> Text -> Text
scanr = (Char -> Char -> Char) -> Char -> Text -> Text
Text.scanr
   scanr1 :: (Char -> Char -> Char) -> Text -> Text
scanr1 = (Char -> Char -> Char) -> Text -> Text
Text.scanr1
   mapAccumL :: (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
mapAccumL = (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
forall a. (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
Text.mapAccumL
   mapAccumR :: (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
mapAccumR = (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
forall a. (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
Text.mapAccumR

   takeWhile :: (Text -> Bool) -> (Char -> Bool) -> Text -> Text
takeWhile Text -> Bool
_ = (Char -> Bool) -> Text -> Text
Text.takeWhile
   dropWhile :: (Text -> Bool) -> (Char -> Bool) -> Text -> Text
dropWhile Text -> Bool
_ = (Char -> Bool) -> Text -> Text
Text.dropWhile
   break :: (Text -> Bool) -> (Char -> Bool) -> Text -> (Text, Text)
break Text -> Bool
_ = (Char -> Bool) -> Text -> (Text, Text)
Text.break
   span :: (Text -> Bool) -> (Char -> Bool) -> Text -> (Text, Text)
span Text -> Bool
_ = (Char -> Bool) -> Text -> (Text, Text)
Text.span
   spanMaybe :: s
-> (s -> Text -> Maybe s)
-> (s -> Char -> Maybe s)
-> Text
-> (Text, Text, s)
spanMaybe s
s0 s -> Text -> Maybe s
_ft s -> Char -> Maybe s
fc Text
t = case (Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s))
-> ((Int, s) -> (Int, s)) -> Text -> (Int, s) -> (Int, s)
forall a. (Char -> a -> a) -> a -> Text -> a
Text.foldr Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
g (Int, s) -> (Int, s)
forall a. a -> a
id Text
t (Int
0, s
s0)
                           of (Int
i, s
s') | (Text
prefix, Text
suffix) <- Int -> Text -> (Text, Text)
Text.splitAt Int
i Text
t -> (Text
prefix, Text
suffix, s
s')
      where g :: Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
g Char
c (Int, s) -> (Int, s)
cont (Int
i, s
s) | Just s
s' <- s -> Char -> Maybe s
fc s
s Char
c = let i' :: Int
i' = Int -> Int
forall a. Enum a => a -> a
succ Int
i :: Int in Int -> (Int, s) -> (Int, s)
seq Int
i' ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
forall a b. (a -> b) -> a -> b
$ (Int, s) -> (Int, s)
cont (Int
i', s
s')
                            | Bool
otherwise = (Int
i, s
s)
   spanMaybe' :: s
-> (s -> Text -> Maybe s)
-> (s -> Char -> Maybe s)
-> Text
-> (Text, Text, s)
spanMaybe' s
s0 s -> Text -> Maybe s
_ft s -> Char -> Maybe s
fc Text
t = case (Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s))
-> ((Int, s) -> (Int, s)) -> Text -> (Int, s) -> (Int, s)
forall a. (Char -> a -> a) -> a -> Text -> a
Text.foldr Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
g (Int, s) -> (Int, s)
forall a. a -> a
id Text
t (Int
0, s
s0)
                            of (Int
i, s
s') | (Text
prefix, Text
suffix) <- Int -> Text -> (Text, Text)
Text.splitAt Int
i Text
t -> (Text
prefix, Text
suffix, s
s')
      where g :: Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
g Char
c (Int, s) -> (Int, s)
cont (Int
i, s
s) | Just s
s' <- s -> Char -> Maybe s
fc s
s Char
c = let i' :: Int
i' = Int -> Int
forall a. Enum a => a -> a
succ Int
i :: Int in Int -> (Int, s) -> (Int, s)
seq Int
i' ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
forall a b. (a -> b) -> a -> b
$ s -> (Int, s) -> (Int, s)
seq s
s' ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
forall a b. (a -> b) -> a -> b
$ (Int, s) -> (Int, s)
cont (Int
i', s
s')
                            | Bool
otherwise = (Int
i, s
s)
   split :: (Char -> Bool) -> Text -> [Text]
split = (Char -> Bool) -> Text -> [Text]
Text.split
   find :: (Char -> Bool) -> Text -> Maybe Char
find = (Char -> Bool) -> Text -> Maybe Char
Text.find

   {-# INLINE all #-}
   {-# INLINE any #-}
   {-# INLINE break #-}
   {-# INLINE characterPrefix #-}
   {-# INLINE concatMap #-}
   {-# INLINE dropWhile #-}
   {-# INLINE find #-}
   {-# INLINE foldl   #-}
   {-# INLINE foldl'  #-}
   {-# INLINE foldr   #-}
   {-# INLINE fromText #-}
   {-# INLINE map #-}
   {-# INLINE mapAccumL #-}
   {-# INLINE mapAccumR #-}
   {-# INLINE scanl #-}
   {-# INLINE scanl1 #-}
   {-# INLINE scanr #-}
   {-# INLINE scanr1 #-}
   {-# INLINE singleton #-}
   {-# INLINE span #-}
   {-# INLINE spanMaybe #-}
   {-# INLINE spanMaybe' #-}
   {-# INLINE split #-}
   {-# INLINE splitCharacterPrefix #-}
   {-# INLINE takeWhile #-}

instance TextualMonoid LazyText.Text where
   fromText :: Text -> Text
fromText = Text -> Text
LazyText.fromStrict
   singleton :: Char -> Text
singleton = Char -> Text
LazyText.singleton
   splitCharacterPrefix :: Text -> Maybe (Char, Text)
splitCharacterPrefix = Text -> Maybe (Char, Text)
LazyText.uncons
   characterPrefix :: Text -> Maybe Char
characterPrefix Text
t = if Text -> Bool
LazyText.null Text
t then Maybe Char
forall a. Maybe a
Nothing else Char -> Maybe Char
forall a. a -> Maybe a
Just (Text -> Char
LazyText.head Text
t)
   map :: (Char -> Char) -> Text -> Text
map = (Char -> Char) -> Text -> Text
LazyText.map
   concatMap :: (Char -> Text) -> Text -> Text
concatMap = (Char -> Text) -> Text -> Text
LazyText.concatMap
   toString :: (Text -> String) -> Text -> String
toString = (Text -> String) -> (Text -> String) -> Text -> String
forall a b. a -> b -> a
const Text -> String
LazyText.unpack
   toText :: (Text -> Text) -> Text -> Text
toText = (Text -> Text) -> (Text -> Text) -> Text -> Text
forall a b. a -> b -> a
const Text -> Text
LazyText.toStrict
   any :: (Char -> Bool) -> Text -> Bool
any = (Char -> Bool) -> Text -> Bool
LazyText.any
   all :: (Char -> Bool) -> Text -> Bool
all = (Char -> Bool) -> Text -> Bool
LazyText.all

   foldl :: (a -> Text -> a) -> (a -> Char -> a) -> a -> Text -> a
foldl   = ((a -> Char -> a) -> a -> Text -> a)
-> (a -> Text -> a) -> (a -> Char -> a) -> a -> Text -> a
forall a b. a -> b -> a
const (a -> Char -> a) -> a -> Text -> a
forall a. (a -> Char -> a) -> a -> Text -> a
LazyText.foldl
   foldl' :: (a -> Text -> a) -> (a -> Char -> a) -> a -> Text -> a
foldl'  = ((a -> Char -> a) -> a -> Text -> a)
-> (a -> Text -> a) -> (a -> Char -> a) -> a -> Text -> a
forall a b. a -> b -> a
const (a -> Char -> a) -> a -> Text -> a
forall a. (a -> Char -> a) -> a -> Text -> a
LazyText.foldl'
   foldr :: (Text -> a -> a) -> (Char -> a -> a) -> a -> Text -> a
foldr   = ((Char -> a -> a) -> a -> Text -> a)
-> (Text -> a -> a) -> (Char -> a -> a) -> a -> Text -> a
forall a b. a -> b -> a
const (Char -> a -> a) -> a -> Text -> a
forall a. (Char -> a -> a) -> a -> Text -> a
LazyText.foldr

   scanl :: (Char -> Char -> Char) -> Char -> Text -> Text
scanl = (Char -> Char -> Char) -> Char -> Text -> Text
LazyText.scanl
   scanl1 :: (Char -> Char -> Char) -> Text -> Text
scanl1 = (Char -> Char -> Char) -> Text -> Text
LazyText.scanl1
   scanr :: (Char -> Char -> Char) -> Char -> Text -> Text
scanr = (Char -> Char -> Char) -> Char -> Text -> Text
LazyText.scanr
   scanr1 :: (Char -> Char -> Char) -> Text -> Text
scanr1 = (Char -> Char -> Char) -> Text -> Text
LazyText.scanr1
   mapAccumL :: (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
mapAccumL = (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
forall a. (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
LazyText.mapAccumL
   mapAccumR :: (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
mapAccumR = (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
forall a. (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)
LazyText.mapAccumR

   takeWhile :: (Text -> Bool) -> (Char -> Bool) -> Text -> Text
takeWhile Text -> Bool
_ = (Char -> Bool) -> Text -> Text
LazyText.takeWhile
   dropWhile :: (Text -> Bool) -> (Char -> Bool) -> Text -> Text
dropWhile Text -> Bool
_ = (Char -> Bool) -> Text -> Text
LazyText.dropWhile
   break :: (Text -> Bool) -> (Char -> Bool) -> Text -> (Text, Text)
break Text -> Bool
_ = (Char -> Bool) -> Text -> (Text, Text)
LazyText.break
   span :: (Text -> Bool) -> (Char -> Bool) -> Text -> (Text, Text)
span Text -> Bool
_ = (Char -> Bool) -> Text -> (Text, Text)
LazyText.span
   spanMaybe :: s
-> (s -> Text -> Maybe s)
-> (s -> Char -> Maybe s)
-> Text
-> (Text, Text, s)
spanMaybe s
s0 s -> Text -> Maybe s
_ft s -> Char -> Maybe s
fc Text
t = case (Char -> ((Int64, s) -> (Int64, s)) -> (Int64, s) -> (Int64, s))
-> ((Int64, s) -> (Int64, s)) -> Text -> (Int64, s) -> (Int64, s)
forall a. (Char -> a -> a) -> a -> Text -> a
LazyText.foldr Char -> ((Int64, s) -> (Int64, s)) -> (Int64, s) -> (Int64, s)
g (Int64, s) -> (Int64, s)
forall a. a -> a
id Text
t (Int64
0, s
s0)
                           of (Int64
i, s
s') | (Text
prefix, Text
suffix) <- Int64 -> Text -> (Text, Text)
LazyText.splitAt Int64
i Text
t -> (Text
prefix, Text
suffix, s
s')
      where g :: Char -> ((Int64, s) -> (Int64, s)) -> (Int64, s) -> (Int64, s)
g Char
c (Int64, s) -> (Int64, s)
cont (Int64
i, s
s) | Just s
s' <- s -> Char -> Maybe s
fc s
s Char
c = let i' :: Int64
i' = Int64 -> Int64
forall a. Enum a => a -> a
succ Int64
i :: Int64 in Int64 -> (Int64, s) -> (Int64, s)
seq Int64
i' ((Int64, s) -> (Int64, s)) -> (Int64, s) -> (Int64, s)
forall a b. (a -> b) -> a -> b
$ (Int64, s) -> (Int64, s)
cont (Int64
i', s
s')
                            | Bool
otherwise = (Int64
i, s
s)
   spanMaybe' :: s
-> (s -> Text -> Maybe s)
-> (s -> Char -> Maybe s)
-> Text
-> (Text, Text, s)
spanMaybe' s
s0 s -> Text -> Maybe s
_ft s -> Char -> Maybe s
fc Text
t = case (Char -> ((Int64, s) -> (Int64, s)) -> (Int64, s) -> (Int64, s))
-> ((Int64, s) -> (Int64, s)) -> Text -> (Int64, s) -> (Int64, s)
forall a. (Char -> a -> a) -> a -> Text -> a
LazyText.foldr Char -> ((Int64, s) -> (Int64, s)) -> (Int64, s) -> (Int64, s)
g (Int64, s) -> (Int64, s)
forall a. a -> a
id Text
t (Int64
0, s
s0)
                            of (Int64
i, s
s') | (Text
prefix, Text
suffix) <- Int64 -> Text -> (Text, Text)
LazyText.splitAt Int64
i Text
t -> (Text
prefix, Text
suffix, s
s')
      where g :: Char -> ((Int64, s) -> (Int64, s)) -> (Int64, s) -> (Int64, s)
g Char
c (Int64, s) -> (Int64, s)
cont (Int64
i, s
s) | Just s
s' <- s -> Char -> Maybe s
fc s
s Char
c = let i' :: Int64
i' = Int64 -> Int64
forall a. Enum a => a -> a
succ Int64
i :: Int64 in Int64 -> (Int64, s) -> (Int64, s)
seq Int64
i' ((Int64, s) -> (Int64, s)) -> (Int64, s) -> (Int64, s)
forall a b. (a -> b) -> a -> b
$ s -> (Int64, s) -> (Int64, s)
seq s
s' ((Int64, s) -> (Int64, s)) -> (Int64, s) -> (Int64, s)
forall a b. (a -> b) -> a -> b
$ (Int64, s) -> (Int64, s)
cont (Int64
i', s
s')
                            | Bool
otherwise = (Int64
i, s
s)
   split :: (Char -> Bool) -> Text -> [Text]
split = (Char -> Bool) -> Text -> [Text]
LazyText.split
   find :: (Char -> Bool) -> Text -> Maybe Char
find = (Char -> Bool) -> Text -> Maybe Char
LazyText.find
   {-# INLINE all #-}
   {-# INLINE any #-}
   {-# INLINE break #-}
   {-# INLINE characterPrefix #-}
   {-# INLINE concatMap #-}
   {-# INLINE dropWhile #-}
   {-# INLINE find #-}
   {-# INLINE foldl   #-}
   {-# INLINE foldl'  #-}
   {-# INLINE foldr   #-}
   {-# INLINE fromText #-}
   {-# INLINE map #-}
   {-# INLINE mapAccumL #-}
   {-# INLINE mapAccumR #-}
   {-# INLINE scanl #-}
   {-# INLINE scanl1 #-}
   {-# INLINE scanr #-}
   {-# INLINE scanr1 #-}
   {-# INLINE singleton #-}
   {-# INLINE span #-}
   {-# INLINE spanMaybe #-}
   {-# INLINE spanMaybe' #-}
   {-# INLINE split #-}
   {-# INLINE splitCharacterPrefix #-}
   {-# INLINE takeWhile #-}

instance TextualMonoid (Sequence.Seq Char) where
   singleton :: Char -> Seq Char
singleton = Char -> Seq Char
forall a. a -> Seq a
Sequence.singleton
   splitCharacterPrefix :: Seq Char -> Maybe (Char, Seq Char)
splitCharacterPrefix Seq Char
s = case Seq Char -> ViewL Char
forall a. Seq a -> ViewL a
Sequence.viewl Seq Char
s
                            of ViewL Char
Sequence.EmptyL -> Maybe (Char, Seq Char)
forall a. Maybe a
Nothing
                               Char
c Sequence.:< Seq Char
rest -> (Char, Seq Char) -> Maybe (Char, Seq Char)
forall a. a -> Maybe a
Just (Char
c, Seq Char
rest)
   characterPrefix :: Seq Char -> Maybe Char
characterPrefix Seq Char
s = case Seq Char -> ViewL Char
forall a. Seq a -> ViewL a
Sequence.viewl Seq Char
s
                       of ViewL Char
Sequence.EmptyL -> Maybe Char
forall a. Maybe a
Nothing
                          Char
c Sequence.:< Seq Char
_ -> Char -> Maybe Char
forall a. a -> Maybe a
Just Char
c
   map :: (Char -> Char) -> Seq Char -> Seq Char
map = (Char -> Char) -> Seq Char -> Seq Char
forall (t :: * -> *) a b. Traversable t => (a -> b) -> t a -> t b
Traversable.fmapDefault
   concatMap :: (Char -> Seq Char) -> Seq Char -> Seq Char
concatMap = (Char -> Seq Char) -> Seq Char -> Seq Char
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Foldable.foldMap
   toString :: (Seq Char -> String) -> Seq Char -> String
toString = (Seq Char -> String) -> (Seq Char -> String) -> Seq Char -> String
forall a b. a -> b -> a
const Seq Char -> String
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
   any :: (Char -> Bool) -> Seq Char -> Bool
any = (Char -> Bool) -> Seq Char -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Foldable.any
   all :: (Char -> Bool) -> Seq Char -> Bool
all = (Char -> Bool) -> Seq Char -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Foldable.all

   foldl :: (a -> Seq Char -> a) -> (a -> Char -> a) -> a -> Seq Char -> a
foldl   = ((a -> Char -> a) -> a -> Seq Char -> a)
-> (a -> Seq Char -> a) -> (a -> Char -> a) -> a -> Seq Char -> a
forall a b. a -> b -> a
const (a -> Char -> a) -> a -> Seq Char -> a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl
   foldl' :: (a -> Seq Char -> a) -> (a -> Char -> a) -> a -> Seq Char -> a
foldl'  = ((a -> Char -> a) -> a -> Seq Char -> a)
-> (a -> Seq Char -> a) -> (a -> Char -> a) -> a -> Seq Char -> a
forall a b. a -> b -> a
const (a -> Char -> a) -> a -> Seq Char -> a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl'
   foldr :: (Seq Char -> a -> a) -> (Char -> a -> a) -> a -> Seq Char -> a
foldr   = ((Char -> a -> a) -> a -> Seq Char -> a)
-> (Seq Char -> a -> a) -> (Char -> a -> a) -> a -> Seq Char -> a
forall a b. a -> b -> a
const (Char -> a -> a) -> a -> Seq Char -> a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr

   scanl :: (Char -> Char -> Char) -> Char -> Seq Char -> Seq Char
scanl = (Char -> Char -> Char) -> Char -> Seq Char -> Seq Char
forall a b. (a -> b -> a) -> a -> Seq b -> Seq a
Sequence.scanl
   scanl1 :: (Char -> Char -> Char) -> Seq Char -> Seq Char
scanl1 Char -> Char -> Char
f Seq Char
v | Seq Char -> Bool
forall a. Seq a -> Bool
Sequence.null Seq Char
v = Seq Char
forall a. Seq a
Sequence.empty
              | Bool
otherwise = (Char -> Char -> Char) -> Seq Char -> Seq Char
forall a. (a -> a -> a) -> Seq a -> Seq a
Sequence.scanl1 Char -> Char -> Char
f Seq Char
v
   scanr :: (Char -> Char -> Char) -> Char -> Seq Char -> Seq Char
scanr = (Char -> Char -> Char) -> Char -> Seq Char -> Seq Char
forall a b. (a -> b -> b) -> b -> Seq a -> Seq b
Sequence.scanr
   scanr1 :: (Char -> Char -> Char) -> Seq Char -> Seq Char
scanr1 Char -> Char -> Char
f Seq Char
v | Seq Char -> Bool
forall a. Seq a -> Bool
Sequence.null Seq Char
v = Seq Char
forall a. Seq a
Sequence.empty
              | Bool
otherwise = (Char -> Char -> Char) -> Seq Char -> Seq Char
forall a. (a -> a -> a) -> Seq a -> Seq a
Sequence.scanr1 Char -> Char -> Char
f Seq Char
v

   takeWhile :: (Seq Char -> Bool) -> (Char -> Bool) -> Seq Char -> Seq Char
takeWhile Seq Char -> Bool
_ = (Char -> Bool) -> Seq Char -> Seq Char
forall a. (a -> Bool) -> Seq a -> Seq a
Sequence.takeWhileL
   dropWhile :: (Seq Char -> Bool) -> (Char -> Bool) -> Seq Char -> Seq Char
dropWhile Seq Char -> Bool
_ = (Char -> Bool) -> Seq Char -> Seq Char
forall a. (a -> Bool) -> Seq a -> Seq a
Sequence.dropWhileL
   break :: (Seq Char -> Bool)
-> (Char -> Bool) -> Seq Char -> (Seq Char, Seq Char)
break Seq Char -> Bool
_ = (Char -> Bool) -> Seq Char -> (Seq Char, Seq Char)
forall a. (a -> Bool) -> Seq a -> (Seq a, Seq a)
Sequence.breakl
   span :: (Seq Char -> Bool)
-> (Char -> Bool) -> Seq Char -> (Seq Char, Seq Char)
span Seq Char -> Bool
_ = (Char -> Bool) -> Seq Char -> (Seq Char, Seq Char)
forall a. (a -> Bool) -> Seq a -> (Seq a, Seq a)
Sequence.spanl
   spanMaybe :: s
-> (s -> Seq Char -> Maybe s)
-> (s -> Char -> Maybe s)
-> Seq Char
-> (Seq Char, Seq Char, s)
spanMaybe s
s0 s -> Seq Char -> Maybe s
_ft s -> Char -> Maybe s
fc Seq Char
b = case (Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s))
-> ((Int, s) -> (Int, s)) -> Seq Char -> (Int, s) -> (Int, s)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
g (Int, s) -> (Int, s)
forall a. a -> a
id Seq Char
b (Int
0, s
s0)
                           of (Int
i, s
s') | (Seq Char
prefix, Seq Char
suffix) <- Int -> Seq Char -> (Seq Char, Seq Char)
forall a. Int -> Seq a -> (Seq a, Seq a)
Sequence.splitAt Int
i Seq Char
b -> (Seq Char
prefix, Seq Char
suffix, s
s')
      where g :: Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
g Char
c (Int, s) -> (Int, s)
cont (Int
i, s
s) | Just s
s' <- s -> Char -> Maybe s
fc s
s Char
c = let i' :: Int
i' = Int -> Int
forall a. Enum a => a -> a
succ Int
i :: Int in Int -> (Int, s) -> (Int, s)
seq Int
i' ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
forall a b. (a -> b) -> a -> b
$ (Int, s) -> (Int, s)
cont (Int
i', s
s')
                            | Bool
otherwise = (Int
i, s
s)
   spanMaybe' :: s
-> (s -> Seq Char -> Maybe s)
-> (s -> Char -> Maybe s)
-> Seq Char
-> (Seq Char, Seq Char, s)
spanMaybe' s
s0 s -> Seq Char -> Maybe s
_ft s -> Char -> Maybe s
fc Seq Char
b = case (Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s))
-> ((Int, s) -> (Int, s)) -> Seq Char -> (Int, s) -> (Int, s)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
g (Int, s) -> (Int, s)
forall a. a -> a
id Seq Char
b (Int
0, s
s0)
                            of (Int
i, s
s') | (Seq Char
prefix, Seq Char
suffix) <- Int -> Seq Char -> (Seq Char, Seq Char)
forall a. Int -> Seq a -> (Seq a, Seq a)
Sequence.splitAt Int
i Seq Char
b -> (Seq Char
prefix, Seq Char
suffix, s
s')
      where g :: Char -> ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
g Char
c (Int, s) -> (Int, s)
cont (Int
i, s
s) | Just s
s' <- s -> Char -> Maybe s
fc s
s Char
c = let i' :: Int
i' = Int -> Int
forall a. Enum a => a -> a
succ Int
i :: Int in Int -> (Int, s) -> (Int, s)
seq Int
i' ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
forall a b. (a -> b) -> a -> b
$ s -> (Int, s) -> (Int, s)
seq s
s' ((Int, s) -> (Int, s)) -> (Int, s) -> (Int, s)
forall a b. (a -> b) -> a -> b
$ (Int, s) -> (Int, s)
cont (Int
i', s
s')
                            | Bool
otherwise = (Int
i, s
s)
   find :: (Char -> Bool) -> Seq Char -> Maybe Char
find = (Char -> Bool) -> Seq Char -> Maybe Char
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
Foldable.find
   elem :: Char -> Seq Char -> Bool
elem = Char -> Seq Char -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
Foldable.elem

   {-# INLINE all #-}
   {-# INLINE any #-}
   {-# INLINE break #-}
   {-# INLINE characterPrefix #-}
   {-# INLINE concatMap #-}
   {-# INLINE dropWhile #-}
   {-# INLINE elem #-}
   {-# INLINE find #-}
   {-# INLINE foldl   #-}
   {-# INLINE foldl'  #-}
   {-# INLINE foldr   #-}
   {-# INLINE map #-}
   {-# INLINE scanl #-}
   {-# INLINE scanl1 #-}
   {-# INLINE scanr #-}
   {-# INLINE scanr1 #-}
   {-# INLINE singleton #-}
   {-# INLINE span #-}
   {-# INLINE spanMaybe #-}
   {-# INLINE spanMaybe' #-}
   {-# INLINE splitCharacterPrefix #-}
   {-# INLINE takeWhile #-}