{-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, FlexibleInstances #-}
{-# OPTIONS -fno-warn-orphans #-}
{-# LANGUAGE CPP #-}
module Data.ListLike.DList () where
import Data.ListLike.Base
import Data.ListLike.FoldableLL
import Data.ListLike.String
#if MIN_VERSION_dlist(1,0,0)
import Data.DList.Unsafe (DList(UnsafeDList), unsafeApplyDList)
#else
import Data.DList (DList)
#endif
import qualified Data.DList as D
import qualified Data.Foldable as F
import qualified Data.List as List
import qualified Data.String as S
import Control.Category
import Data.Char (Char)
instance FoldableLL (DList a) a where
foldl :: forall a. (a -> a -> a) -> a -> DList a -> a
foldl = (a -> a -> a) -> a -> DList a -> a
forall b a. (b -> a -> b) -> b -> DList a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl
foldr :: forall b. (a -> b -> b) -> b -> DList a -> b
foldr = (a -> b -> b) -> b -> DList a -> b
forall a b. (a -> b -> b) -> b -> DList a -> b
D.foldr
foldl1 :: (a -> a -> a) -> DList a -> a
foldl1 = (a -> a -> a) -> DList a -> a
forall a. (a -> a -> a) -> DList a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
F.foldl1
foldr1 :: (a -> a -> a) -> DList a -> a
foldr1 = (a -> a -> a) -> DList a -> a
forall a. (a -> a -> a) -> DList a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
F.foldr1
foldl' :: forall a. (a -> a -> a) -> a -> DList a -> a
foldl' = (a -> a -> a) -> a -> DList a -> a
forall b a. (b -> a -> b) -> b -> DList a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl'
foldr' :: forall b. (a -> b -> b) -> b -> DList a -> b
foldr' = (a -> b -> b) -> b -> DList a -> b
forall a b. (a -> b -> b) -> b -> DList a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr'
instance ListLike (DList a) a where
empty :: DList a
empty = DList a
forall a. DList a
D.empty
singleton :: a -> DList a
singleton = a -> DList a
forall a. a -> DList a
D.singleton
cons :: a -> DList a -> DList a
cons = a -> DList a -> DList a
forall a. a -> DList a -> DList a
D.cons
snoc :: DList a -> a -> DList a
snoc = DList a -> a -> DList a
forall a. DList a -> a -> DList a
D.snoc
append :: DList a -> DList a -> DList a
append = DList a -> DList a -> DList a
forall a. DList a -> DList a -> DList a
D.append
head :: DList a -> a
head = DList a -> a
forall a. DList a -> a
D.head
#if MIN_VERSION_dlist(1,0,0)
tail :: DList a -> DList a
tail = ([a] -> [a]) -> DList a
forall a. ([a] -> [a]) -> DList a
UnsafeDList (([a] -> [a]) -> DList a)
-> (DList a -> [a] -> [a]) -> DList a -> DList a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ([a] -> [a]
forall a. HasCallStack => [a] -> [a]
List.tail ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.) (([a] -> [a]) -> [a] -> [a])
-> (DList a -> [a] -> [a]) -> DList a -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. DList a -> [a] -> [a]
forall a. DList a -> [a] -> [a]
unsafeApplyDList
#else
tail = D.tail
#endif
rigidMap :: (a -> a) -> DList a -> DList a
rigidMap = (a -> a) -> DList a -> DList a
forall a b. (a -> b) -> DList a -> DList b
D.map
null :: DList a -> Bool
null = [a] -> Bool
forall full item. ListLike full item => full -> Bool
null ([a] -> Bool) -> (DList a -> [a]) -> DList a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. DList a -> [a]
forall a. DList a -> [a]
D.toList
replicate :: Int -> a -> DList a
replicate = Int -> a -> DList a
forall a. Int -> a -> DList a
D.replicate
instance StringLike (DList Char) where
toString :: DList Char -> String
toString = DList Char -> String
forall a. DList a -> [a]
D.toList
lines :: forall full. ListLike full (DList Char) => DList Char -> full
lines = (String -> DList Char) -> [String] -> full
forall full' item'.
ListLike full' item' =>
(String -> item') -> [String] -> full'
forall full item full' item'.
(ListLike full item, ListLike full' item') =>
(item -> item') -> full -> full'
map String -> DList Char
forall a. [a] -> DList a
D.fromList ([String] -> full)
-> (DList Char -> [String]) -> DList Char -> full
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> [String]
S.lines (String -> [String])
-> (DList Char -> String) -> DList Char -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. DList Char -> String
forall a. DList a -> [a]
D.toList
words :: forall full. ListLike full (DList Char) => DList Char -> full
words = (String -> DList Char) -> [String] -> full
forall full' item'.
ListLike full' item' =>
(String -> item') -> [String] -> full'
forall full item full' item'.
(ListLike full item, ListLike full' item') =>
(item -> item') -> full -> full'
map String -> DList Char
forall a. [a] -> DList a
D.fromList ([String] -> full)
-> (DList Char -> [String]) -> DList Char -> full
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> [String]
S.words (String -> [String])
-> (DList Char -> String) -> DList Char -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. DList Char -> String
forall a. DList a -> [a]
D.toList
unlines :: forall full. ListLike full (DList Char) => full -> DList Char
unlines = String -> DList Char
forall a. [a] -> DList a
D.fromList (String -> DList Char) -> (full -> String) -> full -> DList Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. [String] -> String
S.unlines ([String] -> String) -> (full -> [String]) -> full -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (DList Char -> String) -> full -> [String]
forall full' item'.
ListLike full' item' =>
(DList Char -> item') -> full -> full'
forall full item full' item'.
(ListLike full item, ListLike full' item') =>
(item -> item') -> full -> full'
map DList Char -> String
forall a. DList a -> [a]
D.toList
unwords :: forall full. ListLike full (DList Char) => full -> DList Char
unwords = String -> DList Char
forall a. [a] -> DList a
D.fromList (String -> DList Char) -> (full -> String) -> full -> DList Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. [String] -> String
S.unwords ([String] -> String) -> (full -> [String]) -> full -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (DList Char -> String) -> full -> [String]
forall full' item'.
ListLike full' item' =>
(DList Char -> item') -> full -> full'
forall full item full' item'.
(ListLike full item, ListLike full' item') =>
(item -> item') -> full -> full'
map DList Char -> String
forall a. DList a -> [a]
D.toList