{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}

module Data.Text1.IsText1(
  IsText1(..)
, unpacked1
, _NonEmpty
) where

import Control.Category ( Category(id, (.)) )
import Control.Applicative ( Applicative((<*>)), (<$>) )
import Control.Lens
    ( Traversable(traverse),
      indexing,
      from,
      iso,
      seconding,
      traversed,
      IndexedTraversal',
      Iso,
      Iso' )
import Data.Char ( Char )
import Data.Int ( Int )
import Data.List.NonEmpty ( NonEmpty((:|)) )
import Data.String ( String )
import Data.Text(Text)
import qualified Data.Text.Lazy as LazyText(Text)
import Data.Text.Lazy.Builder(Builder)
import Data.Text.Lens(IsText(packed, builder), text)
import Data.Tuple(uncurry)

class IsText1 t where
  packed1 ::
    Iso'
      (NonEmpty Char)
      t
  builder1 ::
    Iso'
      (Char, Builder)
      t
  _Text1_ ::
    IndexedTraversal' Int t Char
  _Text1_ =
    AnIso (NonEmpty Char) (NonEmpty Char) t t
-> Iso t t (NonEmpty Char) (NonEmpty Char)
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso (NonEmpty Char) (NonEmpty Char) t t
forall t. IsText1 t => Iso' (NonEmpty Char) t
packed1 ((NonEmpty Char -> f (NonEmpty Char)) -> t -> f t)
-> (p Char (f Char) -> NonEmpty Char -> f (NonEmpty Char))
-> p Char (f Char)
-> t
-> f t
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. p Char (f Char) -> NonEmpty Char -> f (NonEmpty Char)
forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
traversed
  {-# INLINE _Text1_ #-}

unpacked1 ::
  IsText1 t => Iso' t (NonEmpty Char)
unpacked1 :: Iso' t (NonEmpty Char)
unpacked1 =
  AnIso (NonEmpty Char) (NonEmpty Char) t t -> Iso' t (NonEmpty Char)
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso (NonEmpty Char) (NonEmpty Char) t t
forall t. IsText1 t => Iso' (NonEmpty Char) t
packed1

instance IsText1 (NonEmpty Char) where
  packed1 :: p (NonEmpty Char) (f (NonEmpty Char))
-> p (NonEmpty Char) (f (NonEmpty Char))
packed1 =
    p (NonEmpty Char) (f (NonEmpty Char))
-> p (NonEmpty Char) (f (NonEmpty Char))
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
  builder1 :: p (NonEmpty Char) (f (NonEmpty Char))
-> p (Char, Builder) (f (Char, Builder))
builder1 =
    AnIso Builder Builder [Char] [Char]
-> Iso
     (Char, Builder) (Char, Builder) (Char, [Char]) (Char, [Char])
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b x y.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b -> Iso (f x s) (g y t) (f x a) (g y b)
seconding (AnIso [Char] [Char] Builder Builder
-> Iso Builder Builder [Char] [Char]
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso [Char] [Char] Builder Builder
forall t. IsText t => Iso' t Builder
builder) (p (Char, [Char]) (f (Char, [Char]))
 -> p (Char, Builder) (f (Char, Builder)))
-> (p (NonEmpty Char) (f (NonEmpty Char))
    -> p (Char, [Char]) (f (Char, [Char])))
-> p (NonEmpty Char) (f (NonEmpty Char))
-> p (Char, Builder) (f (Char, Builder))
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. AnIso (NonEmpty Char) (NonEmpty Char) (Char, [Char]) (Char, [Char])
-> Iso
     (Char, [Char]) (Char, [Char]) (NonEmpty Char) (NonEmpty Char)
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso (NonEmpty Char) (NonEmpty Char) (Char, [Char]) (Char, [Char])
forall a b. Iso (NonEmpty a) (NonEmpty b) (a, [a]) (b, [b])
_NonEmpty
  _Text1_ :: p Char (f Char) -> NonEmpty Char -> f (NonEmpty Char)
_Text1_ =
    ((Char -> Indexing f Char)
 -> NonEmpty Char -> Indexing f (NonEmpty Char))
-> p Char (f Char) -> NonEmpty Char -> f (NonEmpty Char)
forall (p :: * -> * -> *) a (f :: * -> *) b s t.
Indexable Int p =>
((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
indexing (Char -> Indexing f Char)
-> NonEmpty Char -> Indexing f (NonEmpty Char)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse

instance IsText1 (Char, String) where
  packed1 :: p (Char, [Char]) (f (Char, [Char]))
-> p (NonEmpty Char) (f (NonEmpty Char))
packed1 =
    p (Char, [Char]) (f (Char, [Char]))
-> p (NonEmpty Char) (f (NonEmpty Char))
forall a b. Iso (NonEmpty a) (NonEmpty b) (a, [a]) (b, [b])
_NonEmpty
  builder1 :: p (Char, [Char]) (f (Char, [Char]))
-> p (Char, Builder) (f (Char, Builder))
builder1 =
    AnIso Builder Builder [Char] [Char]
-> Iso
     (Char, Builder) (Char, Builder) (Char, [Char]) (Char, [Char])
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b x y.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b -> Iso (f x s) (g y t) (f x a) (g y b)
seconding (AnIso [Char] [Char] Builder Builder
-> Iso Builder Builder [Char] [Char]
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso [Char] [Char] Builder Builder
forall t. IsText t => Iso' t Builder
builder)
  _Text1_ :: p Char (f Char) -> (Char, [Char]) -> f (Char, [Char])
_Text1_ =
    ((Char -> Indexing f Char)
 -> (Char, [Char]) -> Indexing f (Char, [Char]))
-> p Char (f Char) -> (Char, [Char]) -> f (Char, [Char])
forall (p :: * -> * -> *) a (f :: * -> *) b s t.
Indexable Int p =>
((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
indexing (\Char -> Indexing f Char
f (Char
c, [Char]
cs) -> (,) (Char -> [Char] -> (Char, [Char]))
-> Indexing f Char -> Indexing f ([Char] -> (Char, [Char]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> Indexing f Char
f Char
c Indexing f ([Char] -> (Char, [Char]))
-> Indexing f [Char] -> Indexing f (Char, [Char])
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> Indexing f Char) -> [Char] -> Indexing f [Char]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Char -> Indexing f Char
f [Char]
cs)

instance IsText1 (Char, Text) where
  packed1 :: p (Char, Text) (f (Char, Text))
-> p (NonEmpty Char) (f (NonEmpty Char))
packed1 =
    p (Char, [Char]) (f (Char, [Char]))
-> p (NonEmpty Char) (f (NonEmpty Char))
forall a b. Iso (NonEmpty a) (NonEmpty b) (a, [a]) (b, [b])
_NonEmpty (p (Char, [Char]) (f (Char, [Char]))
 -> p (NonEmpty Char) (f (NonEmpty Char)))
-> (p (Char, Text) (f (Char, Text))
    -> p (Char, [Char]) (f (Char, [Char])))
-> p (Char, Text) (f (Char, Text))
-> p (NonEmpty Char) (f (NonEmpty Char))
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. AnIso [Char] [Char] Text Text
-> Iso (Char, [Char]) (Char, [Char]) (Char, Text) (Char, Text)
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b x y.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b -> Iso (f x s) (g y t) (f x a) (g y b)
seconding AnIso [Char] [Char] Text Text
forall t. IsText t => Iso' [Char] t
packed
  builder1 :: p (Char, Text) (f (Char, Text))
-> p (Char, Builder) (f (Char, Builder))
builder1 =
    AnIso Builder Builder Text Text
-> Iso' (Char, Builder) (Char, Text)
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b x y.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b -> Iso (f x s) (g y t) (f x a) (g y b)
seconding (AnIso Text Text Builder Builder -> Iso Builder Builder Text Text
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso Text Text Builder Builder
forall t. IsText t => Iso' t Builder
builder)
  _Text1_ :: p Char (f Char) -> (Char, Text) -> f (Char, Text)
_Text1_ =
    ((Char -> Indexing f Char)
 -> (Char, Text) -> Indexing f (Char, Text))
-> p Char (f Char) -> (Char, Text) -> f (Char, Text)
forall (p :: * -> * -> *) a (f :: * -> *) b s t.
Indexable Int p =>
((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
indexing (\Char -> Indexing f Char
f (Char
h, Text
t) -> (,) (Char -> Text -> (Char, Text))
-> Indexing f Char -> Indexing f (Text -> (Char, Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> Indexing f Char
f Char
h Indexing f (Text -> (Char, Text))
-> Indexing f Text -> Indexing f (Char, Text)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> Indexing f Char) -> Text -> Indexing f Text
forall t. IsText t => IndexedTraversal' Int t Char
text Char -> Indexing f Char
f Text
t)

instance IsText1 (Char, LazyText.Text) where
  packed1 :: p (Char, Text) (f (Char, Text))
-> p (NonEmpty Char) (f (NonEmpty Char))
packed1 =
    p (Char, [Char]) (f (Char, [Char]))
-> p (NonEmpty Char) (f (NonEmpty Char))
forall a b. Iso (NonEmpty a) (NonEmpty b) (a, [a]) (b, [b])
_NonEmpty (p (Char, [Char]) (f (Char, [Char]))
 -> p (NonEmpty Char) (f (NonEmpty Char)))
-> (p (Char, Text) (f (Char, Text))
    -> p (Char, [Char]) (f (Char, [Char])))
-> p (Char, Text) (f (Char, Text))
-> p (NonEmpty Char) (f (NonEmpty Char))
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. AnIso [Char] [Char] Text Text
-> Iso (Char, [Char]) (Char, [Char]) (Char, Text) (Char, Text)
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b x y.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b -> Iso (f x s) (g y t) (f x a) (g y b)
seconding AnIso [Char] [Char] Text Text
forall t. IsText t => Iso' [Char] t
packed
  builder1 :: p (Char, Text) (f (Char, Text))
-> p (Char, Builder) (f (Char, Builder))
builder1 =
    AnIso Builder Builder Text Text
-> Iso' (Char, Builder) (Char, Text)
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b x y.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b -> Iso (f x s) (g y t) (f x a) (g y b)
seconding (AnIso Text Text Builder Builder -> Iso Builder Builder Text Text
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso Text Text Builder Builder
forall t. IsText t => Iso' t Builder
builder)
  _Text1_ :: p Char (f Char) -> (Char, Text) -> f (Char, Text)
_Text1_ =
    ((Char -> Indexing f Char)
 -> (Char, Text) -> Indexing f (Char, Text))
-> p Char (f Char) -> (Char, Text) -> f (Char, Text)
forall (p :: * -> * -> *) a (f :: * -> *) b s t.
Indexable Int p =>
((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
indexing (\Char -> Indexing f Char
f (Char
h, Text
t) -> (,) (Char -> Text -> (Char, Text))
-> Indexing f Char -> Indexing f (Text -> (Char, Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> Indexing f Char
f Char
h Indexing f (Text -> (Char, Text))
-> Indexing f Text -> Indexing f (Char, Text)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> Indexing f Char) -> Text -> Indexing f Text
forall t. IsText t => IndexedTraversal' Int t Char
text Char -> Indexing f Char
f Text
t)

_NonEmpty ::
  Iso
    (NonEmpty a)
    (NonEmpty b)
    (a, [a])
    (b, [b])
_NonEmpty :: p (a, [a]) (f (b, [b])) -> p (NonEmpty a) (f (NonEmpty b))
_NonEmpty =
  (NonEmpty a -> (a, [a]))
-> ((b, [b]) -> NonEmpty b)
-> Iso (NonEmpty a) (NonEmpty b) (a, [a]) (b, [b])
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
    (\(a
h :| [a]
t) -> (a
h, [a]
t))
    ((b -> [b] -> NonEmpty b) -> (b, [b]) -> NonEmpty b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry b -> [b] -> NonEmpty b
forall a. a -> [a] -> NonEmpty a
(:|))