{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Redundant lambda" #-}
{-# HLINT ignore "Avoid restricted function" #-}
module Data.List.Infinite (
Infinite (..),
head,
tail,
uncons,
toList,
foldr,
map,
scanl,
scanl',
scanl1,
mapAccumL,
traverse_,
for_,
concat,
concatMap,
intersperse,
intercalate,
interleave,
transpose,
subsequences,
subsequences1,
permutations,
(...),
(....),
iterate,
iterate',
unfoldr,
tabulate,
repeat,
cycle,
prependList,
take,
drop,
splitAt,
takeWhile,
dropWhile,
span,
break,
group,
inits,
inits1,
tails,
isPrefixOf,
stripPrefix,
filter,
lookup,
find,
mapMaybe,
catMaybes,
partition,
mapEither,
partitionEithers,
(!!),
elemIndex,
elemIndices,
findIndex,
findIndices,
zip,
zipWith,
zip3,
zipWith3,
zip4,
zipWith4,
zip5,
zipWith5,
zip6,
zipWith6,
zip7,
zipWith7,
heteroZip,
heteroZipWith,
unzip,
unzip3,
unzip4,
unzip5,
unzip6,
unzip7,
lines,
words,
unlines,
unwords,
nub,
nubOrd,
delete,
(\\),
union,
intersect,
insert,
nubBy,
nubOrdBy,
deleteBy,
deleteFirstsBy,
unionBy,
intersectBy,
groupBy,
insertBy,
genericTake,
genericDrop,
genericSplitAt,
) where
import Control.Applicative (Applicative (..))
import Control.Arrow (first, second)
import Control.Exception (assert)
import Control.Monad (Monad (..))
import Control.Monad.Fix (MonadFix (..))
import Data.Bits ((.&.))
import Data.Char (Char, isSpace)
import Data.Coerce (coerce)
import Data.Either (Either, either)
import Data.Eq (Eq, (/=), (==))
import qualified Data.Foldable as F
import Data.Function (fix, ($))
import Data.Functor (Functor (..))
import qualified Data.List as List
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NE
import Data.Maybe (maybe)
import Data.Ord (Ord, Ordering (..), compare, (<), (<=), (>), (>=))
import qualified Data.Traversable as Traversable
import Data.Void (Void)
import GHC.Exts (oneShot)
import qualified GHC.Exts
import Numeric.Natural (Natural)
import Prelude (Bool (..), Enum, Int, Integer, Integral, Maybe (..), Traversable, Word, const, enumFrom, enumFromThen, flip, fromIntegral, id, maxBound, minBound, not, otherwise, snd, uncurry, (&&), (+), (-), (.), (||))
import Data.List.Infinite.Internal
import qualified Data.List.Infinite.Set as Set
import Data.List.Infinite.Zip
foldr :: (a -> b -> b) -> Infinite a -> b
foldr :: forall a b. (a -> b -> b) -> Infinite a -> b
foldr a -> b -> b
f = Infinite a -> b
go
where
go :: Infinite a -> b
go (a
x :< Infinite a
xs) = a -> b -> b
f a
x (Infinite a -> b
go Infinite a
xs)
{-# INLINE [0] foldr #-}
{-# RULES
"foldr/build" forall cons (g :: forall b. (a -> b -> b) -> b).
foldr cons (build g) =
g cons
"foldr/cons/build" forall cons x (g :: forall b. (a -> b -> b) -> b).
foldr cons (x :< build g) =
cons x (g cons)
#-}
para :: forall a b. (a -> Infinite a -> b -> b) -> Infinite a -> b
para :: forall a b. (a -> Infinite a -> b -> b) -> Infinite a -> b
para a -> Infinite a -> b -> b
f = Infinite a -> b
go
where
go :: Infinite a -> b
go :: Infinite a -> b
go (a
x :< Infinite a
xs) = a -> Infinite a -> b -> b
f a
x Infinite a
xs (Infinite a -> b
go Infinite a
xs)
toList :: Infinite a -> [a]
toList :: forall a. Infinite a -> [a]
toList = (a -> [a] -> [a]) -> Infinite a -> [a]
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (:)
{-# NOINLINE [0] toList #-}
{-# RULES
"toList" [~1] forall xs.
toList xs =
GHC.Exts.build (\cons -> const (foldr cons xs))
#-}
(...) :: Enum a => a -> Infinite a
... :: forall a. Enum a => a -> Infinite a
(...) = [a] -> Infinite a
forall a. [a] -> Infinite a
unsafeCycle ([a] -> Infinite a) -> (a -> [a]) -> a -> Infinite a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a]
forall a. Enum a => a -> [a]
enumFrom
{-# INLINE [0] (...) #-}
infix 0 ...
{-# RULES
"ellipsis3Int" (...) = ellipsis3Int
"ellipsis3Word" (...) = ellipsis3Word
"ellipsis3Integer" (...) = ellipsis3Integer
"ellipsis3Natural" (...) = ellipsis3Natural
#-}
ellipsis3Int :: Int -> Infinite Int
ellipsis3Int :: Int -> Infinite Int
ellipsis3Int Int
from = (Int -> Int) -> Int -> Infinite Int
forall a. (a -> a) -> a -> Infinite a
iterate' (\Int
n -> if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
forall a. Bounded a => a
maxBound then Int
from else Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
from
{-# INLINE ellipsis3Int #-}
ellipsis3Word :: Word -> Infinite Word
ellipsis3Word :: Word -> Infinite Word
ellipsis3Word Word
from = (Word -> Word) -> Word -> Infinite Word
forall a. (a -> a) -> a -> Infinite a
iterate' (\Word
n -> if Word
n Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
== Word
forall a. Bounded a => a
maxBound then Word
from else Word
n Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1) Word
from
{-# INLINE ellipsis3Word #-}
ellipsis3Integer :: Integer -> Infinite Integer
ellipsis3Integer :: Integer -> Infinite Integer
ellipsis3Integer = (Integer -> Integer) -> Integer -> Infinite Integer
forall a. (a -> a) -> a -> Infinite a
iterate' (Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
1)
{-# INLINE ellipsis3Integer #-}
ellipsis3Natural :: Natural -> Infinite Natural
ellipsis3Natural :: Natural -> Infinite Natural
ellipsis3Natural = (Natural -> Natural) -> Natural -> Infinite Natural
forall a. (a -> a) -> a -> Infinite a
iterate' (Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ Natural
1)
{-# INLINE ellipsis3Natural #-}
(....) :: Enum a => (a, a) -> Infinite a
.... :: forall a. Enum a => (a, a) -> Infinite a
(....) = [a] -> Infinite a
forall a. [a] -> Infinite a
unsafeCycle ([a] -> Infinite a) -> ((a, a) -> [a]) -> (a, a) -> Infinite a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> [a]) -> (a, a) -> [a]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> [a]
forall a. Enum a => a -> a -> [a]
enumFromThen
{-# INLINE [0] (....) #-}
infix 0 ....
{-# RULES
"ellipsis4Int" (....) = ellipsis4Int
"ellipsis4Word" (....) = ellipsis4Word
"ellipsis4Integer" (....) = ellipsis4Integer
"ellipsis4Natural" (....) = ellipsis4Natural
#-}
ellipsis4Int :: (Int, Int) -> Infinite Int
ellipsis4Int :: (Int, Int) -> Infinite Int
ellipsis4Int (Int
from, Int
thn)
| Int
from Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
thn =
let d :: Int
d = Int
thn Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
from
in (Int -> Int) -> Int -> Infinite Int
forall a. (a -> a) -> a -> Infinite a
iterate' (\Int
n -> if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
forall a. Bounded a => a
maxBound Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
d then Int
from else Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
d) Int
from
| Bool
otherwise =
let d :: Int
d = Int
from Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
thn
in (Int -> Int) -> Int -> Infinite Int
forall a. (a -> a) -> a -> Infinite a
iterate' (\Int
n -> if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
forall a. Bounded a => a
minBound Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
d then Int
from else Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
d) Int
from
{-# INLINE ellipsis4Int #-}
ellipsis4Word :: (Word, Word) -> Infinite Word
ellipsis4Word :: (Word, Word) -> Infinite Word
ellipsis4Word (Word
from, Word
thn)
| Word
from Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
thn =
let d :: Word
d = Word
thn Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
from
in (Word -> Word) -> Word -> Infinite Word
forall a. (a -> a) -> a -> Infinite a
iterate' (\Word
n -> if Word
n Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
> Word
forall a. Bounded a => a
maxBound Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
d then Word
from else Word
n Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
d) Word
from
| Bool
otherwise =
let d :: Word
d = Word
from Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
thn
in (Word -> Word) -> Word -> Infinite Word
forall a. (a -> a) -> a -> Infinite a
iterate' (\Word
n -> if Word
n Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
< Word
d then Word
from else Word
n Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
d) Word
from
{-# INLINE ellipsis4Word #-}
ellipsis4Integer :: (Integer, Integer) -> Infinite Integer
ellipsis4Integer :: (Integer, Integer) -> Infinite Integer
ellipsis4Integer (Integer
from, Integer
thn) = (Integer -> Integer) -> Integer -> Infinite Integer
forall a. (a -> a) -> a -> Infinite a
iterate' (Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ (Integer
thn Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
from)) Integer
from
{-# INLINE ellipsis4Integer #-}
ellipsis4Natural :: (Natural, Natural) -> Infinite Natural
ellipsis4Natural :: (Natural, Natural) -> Infinite Natural
ellipsis4Natural (Natural
from, Natural
thn)
| Natural
from Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
<= Natural
thn =
(Natural -> Natural) -> Natural -> Infinite Natural
forall a. (a -> a) -> a -> Infinite a
iterate' (Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ (Natural
thn Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
- Natural
from)) Natural
from
| Bool
otherwise =
let d :: Natural
d = Natural
from Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
- Natural
thn
in (Natural -> Natural) -> Natural -> Infinite Natural
forall a. (a -> a) -> a -> Infinite a
iterate' (\Natural
n -> if Natural
n Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
< Natural
d then Natural
from else Natural
n Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
- Natural
d) Natural
from
{-# INLINE ellipsis4Natural #-}
instance Functor Infinite where
fmap :: forall a b. (a -> b) -> Infinite a -> Infinite b
fmap = (a -> b) -> Infinite a -> Infinite b
forall a b. (a -> b) -> Infinite a -> Infinite b
map
<$ :: forall a b. a -> Infinite b -> Infinite a
(<$) = Infinite a -> Infinite b -> Infinite a
forall a b. a -> b -> a
const (Infinite a -> Infinite b -> Infinite a)
-> (a -> Infinite a) -> a -> Infinite b -> Infinite a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Infinite a
forall a. a -> Infinite a
repeat
instance Applicative Infinite where
pure :: forall a. a -> Infinite a
pure = a -> Infinite a
forall a. a -> Infinite a
repeat
(a -> b
f :< Infinite (a -> b)
fs) <*> :: forall a b. Infinite (a -> b) -> Infinite a -> Infinite b
<*> (a
x :< Infinite a
xs) = a -> b
f a
x b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< (Infinite (a -> b)
fs Infinite (a -> b) -> Infinite a -> Infinite b
forall a b. Infinite (a -> b) -> Infinite a -> Infinite b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Infinite a
xs)
<* :: forall a b. Infinite a -> Infinite b -> Infinite a
(<*) = Infinite a -> Infinite b -> Infinite a
forall a b. a -> b -> a
const
*> :: forall a b. Infinite a -> Infinite b -> Infinite b
(*>) = (Infinite b -> Infinite b)
-> Infinite a -> Infinite b -> Infinite b
forall a b. a -> b -> a
const Infinite b -> Infinite b
forall a. a -> a
id
liftA2 :: forall a b c.
(a -> b -> c) -> Infinite a -> Infinite b -> Infinite c
liftA2 = (a -> b -> c) -> Infinite a -> Infinite b -> Infinite c
forall a b c.
(a -> b -> c) -> Infinite a -> Infinite b -> Infinite c
zipWith
instance Monad Infinite where
Infinite a
xs >>= :: forall a b. Infinite a -> (a -> Infinite b) -> Infinite b
>>= a -> Infinite b
f = (Natural -> a -> b) -> Infinite Natural -> Infinite a -> Infinite b
forall a b c.
(a -> b -> c) -> Infinite a -> Infinite b -> Infinite c
zipWith (\(!Natural
n) -> Infinite b -> b
forall a. Infinite a -> a
head (Infinite b -> b) -> (a -> Infinite b) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Infinite b -> Infinite b
forall i a. Integral i => i -> Infinite a -> Infinite a
genericDrop Natural
n (Infinite b -> Infinite b) -> (a -> Infinite b) -> a -> Infinite b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Infinite b
f) (Natural -> Infinite Natural
forall a. Enum a => a -> Infinite a
(...) (Natural
0 :: Natural)) Infinite a
xs
{-# INLINE (>>=) #-}
>> :: forall a b. Infinite a -> Infinite b -> Infinite b
(>>) = Infinite a -> Infinite b -> Infinite b
forall a b. Infinite a -> Infinite b -> Infinite b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
instance MonadFix Infinite where
mfix :: forall a. (a -> Infinite a) -> Infinite a
mfix a -> Infinite a
f = (Natural -> a) -> Infinite Natural -> Infinite a
forall a b. (a -> b) -> Infinite a -> Infinite b
map (\(!Natural
n) -> (a -> a) -> a
forall a. (a -> a) -> a
fix ((a -> a) -> a) -> (a -> a) -> a
forall a b. (a -> b) -> a -> b
$ Infinite a -> a
forall a. Infinite a -> a
head (Infinite a -> a) -> (a -> Infinite a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Infinite a -> Infinite a
forall i a. Integral i => i -> Infinite a -> Infinite a
genericDrop Natural
n (Infinite a -> Infinite a) -> (a -> Infinite a) -> a -> Infinite a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Infinite a
f) (Natural -> Infinite Natural
forall a. Enum a => a -> Infinite a
(...) (Natural
0 :: Natural))
head :: Infinite a -> a
head :: forall a. Infinite a -> a
head (a
x :< Infinite a
_) = a
x
{-# NOINLINE [1] head #-}
{-# RULES
"head/build" forall (g :: forall b. (a -> b -> b) -> b).
head (build g) =
g const
#-}
tail :: Infinite a -> Infinite a
tail :: forall a. Infinite a -> Infinite a
tail (a
_ :< Infinite a
xs) = Infinite a
xs
uncons :: Infinite a -> (a, Infinite a)
uncons :: forall a. Infinite a -> (a, Infinite a)
uncons (a
x :< Infinite a
xs) = (a
x, Infinite a
xs)
map :: (a -> b) -> Infinite a -> Infinite b
map :: forall a b. (a -> b) -> Infinite a -> Infinite b
map = (a -> Infinite b -> Infinite b) -> Infinite a -> Infinite b
forall a b. (a -> b -> b) -> Infinite a -> b
foldr ((a -> Infinite b -> Infinite b) -> Infinite a -> Infinite b)
-> ((a -> b) -> a -> Infinite b -> Infinite b)
-> (a -> b)
-> Infinite a
-> Infinite b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
(:<) (b -> Infinite b -> Infinite b)
-> (a -> b) -> a -> Infinite b -> Infinite b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)
mapFB :: (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst
mapFB :: forall elt lst a.
(elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst
mapFB = (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.)
{-# NOINLINE [0] map #-}
{-# INLINE [0] mapFB #-}
{-# RULES
"map" [~1] forall f xs.
map f xs =
build (\cons -> foldr (mapFB cons f) xs)
"mapList" [1] forall f.
foldr (mapFB (:<) f) =
map f
"mapFB" forall cons f g.
mapFB (mapFB cons f) g =
mapFB cons (f . g)
"map/coerce" [1]
map coerce =
coerce
#-}
concat :: Infinite (NonEmpty a) -> Infinite a
concat :: forall a. Infinite (NonEmpty a) -> Infinite a
concat = (NonEmpty a -> Infinite a -> Infinite a)
-> Infinite (NonEmpty a) -> Infinite a
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(a
x :| [a]
xs) Infinite a
acc -> a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< ([a]
xs [a] -> Infinite a -> Infinite a
forall a. [a] -> Infinite a -> Infinite a
`prependList` Infinite a
acc))
{-# NOINLINE [1] concat #-}
{-# RULES
"concat" forall xs.
concat xs =
build (\cons -> foldr (flip (F.foldr cons)) xs)
#-}
concatMap :: (a -> NonEmpty b) -> Infinite a -> Infinite b
concatMap :: forall a b. (a -> NonEmpty b) -> Infinite a -> Infinite b
concatMap a -> NonEmpty b
f = (a -> Infinite b -> Infinite b) -> Infinite a -> Infinite b
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
a Infinite b
acc -> let (b
x :| [b]
xs) = a -> NonEmpty b
f a
a in b
x b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< ([b]
xs [b] -> Infinite b -> Infinite b
forall a. [a] -> Infinite a -> Infinite a
`prependList` Infinite b
acc))
{-# NOINLINE [1] concatMap #-}
{-# RULES
"concatMap" forall f xs.
concatMap f xs =
build (\cons -> foldr (flip (F.foldr cons) . f) xs)
#-}
interleave :: Infinite a -> Infinite a -> Infinite a
interleave :: forall a. Infinite a -> Infinite a -> Infinite a
interleave (a
x :< Infinite a
xs) Infinite a
ys = a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a -> Infinite a -> Infinite a
forall a. Infinite a -> Infinite a -> Infinite a
interleave Infinite a
ys Infinite a
xs
intersperse :: a -> Infinite a -> Infinite a
intersperse :: forall a. a -> Infinite a -> Infinite a
intersperse a
a = (a -> Infinite a -> Infinite a) -> Infinite a -> Infinite a
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x -> (a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:<) (Infinite a -> Infinite a)
-> (Infinite a -> Infinite a) -> Infinite a -> Infinite a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:<))
{-# NOINLINE [1] intersperse #-}
{-# RULES
"intersperse" forall a xs.
intersperse a xs =
build (\cons -> foldr (\x -> cons x . cons a) xs)
#-}
intercalate :: NonEmpty a -> Infinite [a] -> Infinite a
intercalate :: forall a. NonEmpty a -> Infinite [a] -> Infinite a
intercalate ~(a
a :| [a]
as) = ([a] -> Infinite a -> Infinite a) -> Infinite [a] -> Infinite a
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\[a]
xs -> [a] -> Infinite a -> Infinite a
forall a. [a] -> Infinite a -> Infinite a
prependList [a]
xs (Infinite a -> Infinite a)
-> (Infinite a -> Infinite a) -> Infinite a -> Infinite a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:<) (Infinite a -> Infinite a)
-> (Infinite a -> Infinite a) -> Infinite a -> Infinite a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Infinite a -> Infinite a
forall a. [a] -> Infinite a -> Infinite a
prependList [a]
as)
{-# NOINLINE [1] intercalate #-}
{-# RULES
"intercalate" forall as xss.
intercalate as xss =
build (\cons -> foldr (\xs acc -> F.foldr cons (F.foldr cons acc as) xs) xss)
#-}
transpose :: Functor f => f (Infinite a) -> Infinite (f a)
transpose :: forall (f :: * -> *) a.
Functor f =>
f (Infinite a) -> Infinite (f a)
transpose f (Infinite a)
xss = (Infinite a -> a) -> f (Infinite a) -> f a
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Infinite a -> a
forall a. Infinite a -> a
head f (Infinite a)
xss f a -> Infinite (f a) -> Infinite (f a)
forall a. a -> Infinite a -> Infinite a
:< f (Infinite a) -> Infinite (f a)
forall (f :: * -> *) a.
Functor f =>
f (Infinite a) -> Infinite (f a)
transpose ((Infinite a -> Infinite a) -> f (Infinite a) -> f (Infinite a)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Infinite a -> Infinite a
forall a. Infinite a -> Infinite a
tail f (Infinite a)
xss)
subsequences :: Infinite a -> Infinite [a]
subsequences :: forall a. Infinite a -> Infinite [a]
subsequences = ([] [a] -> Infinite [a] -> Infinite [a]
forall a. a -> Infinite a -> Infinite a
:<) (Infinite [a] -> Infinite [a])
-> (Infinite a -> Infinite [a]) -> Infinite a -> Infinite [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NonEmpty a -> [a]) -> Infinite (NonEmpty a) -> Infinite [a]
forall a b. (a -> b) -> Infinite a -> Infinite b
map NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
NE.toList (Infinite (NonEmpty a) -> Infinite [a])
-> (Infinite a -> Infinite (NonEmpty a))
-> Infinite a
-> Infinite [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Infinite a -> Infinite (NonEmpty a)
forall a. Infinite a -> Infinite (NonEmpty a)
subsequences1
subsequences1 :: Infinite a -> Infinite (NonEmpty a)
subsequences1 :: forall a. Infinite a -> Infinite (NonEmpty a)
subsequences1 = (a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a))
-> Infinite a -> Infinite (NonEmpty a)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
forall a. a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
go
where
go :: a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
go :: forall a. a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
go a
x Infinite (NonEmpty a)
sxs = (a
x a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| []) NonEmpty a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
forall a. a -> Infinite a -> Infinite a
:< (NonEmpty a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a))
-> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr NonEmpty a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
f Infinite (NonEmpty a)
sxs
where
f :: NonEmpty a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
f NonEmpty a
ys Infinite (NonEmpty a)
r = NonEmpty a
ys NonEmpty a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
forall a. a -> Infinite a -> Infinite a
:< (a
x a -> NonEmpty a -> NonEmpty a
forall a. a -> NonEmpty a -> NonEmpty a
`NE.cons` NonEmpty a
ys) NonEmpty a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
forall a. a -> Infinite a -> Infinite a
:< Infinite (NonEmpty a)
r
permutations :: Infinite a -> Infinite (Infinite a)
permutations :: forall a. Infinite a -> Infinite (Infinite a)
permutations Infinite a
xs0 = Infinite a
xs0 Infinite a -> Infinite (Infinite a) -> Infinite (Infinite a)
forall a. a -> Infinite a -> Infinite a
:< Infinite a -> [a] -> Infinite (Infinite a)
forall a. Infinite a -> [a] -> Infinite (Infinite a)
perms Infinite a
xs0 []
where
perms :: forall a. Infinite a -> [a] -> Infinite (Infinite a)
perms :: forall a. Infinite a -> [a] -> Infinite (Infinite a)
perms (a
t :< Infinite a
ts) [a]
is = ([a] -> Infinite (Infinite a) -> Infinite (Infinite a))
-> Infinite (Infinite a) -> [[a]] -> Infinite (Infinite a)
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
List.foldr [a] -> Infinite (Infinite a) -> Infinite (Infinite a)
interleaveList (Infinite a -> [a] -> Infinite (Infinite a)
forall a. Infinite a -> [a] -> Infinite (Infinite a)
perms Infinite a
ts (a
t a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
is)) ([a] -> [[a]]
forall a. [a] -> [[a]]
List.permutations [a]
is)
where
interleaveList :: [a] -> Infinite (Infinite a) -> Infinite (Infinite a)
interleaveList :: [a] -> Infinite (Infinite a) -> Infinite (Infinite a)
interleaveList = ((Infinite a, Infinite (Infinite a)) -> Infinite (Infinite a)
forall a b. (a, b) -> b
snd ((Infinite a, Infinite (Infinite a)) -> Infinite (Infinite a))
-> (Infinite (Infinite a) -> (Infinite a, Infinite (Infinite a)))
-> Infinite (Infinite a)
-> Infinite (Infinite a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Infinite (Infinite a) -> (Infinite a, Infinite (Infinite a)))
-> Infinite (Infinite a) -> Infinite (Infinite a))
-> ([a]
-> Infinite (Infinite a) -> (Infinite a, Infinite (Infinite a)))
-> [a]
-> Infinite (Infinite a)
-> Infinite (Infinite a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Infinite a -> Infinite a)
-> [a]
-> Infinite (Infinite a)
-> (Infinite a, Infinite (Infinite a))
forall b.
(Infinite a -> b) -> [a] -> Infinite b -> (Infinite a, Infinite b)
interleaveList' Infinite a -> Infinite a
forall a. a -> a
id
interleaveList' :: (Infinite a -> b) -> [a] -> Infinite b -> (Infinite a, Infinite b)
interleaveList' :: forall b.
(Infinite a -> b) -> [a] -> Infinite b -> (Infinite a, Infinite b)
interleaveList' Infinite a -> b
_ [] Infinite b
r = (Infinite a
ts, Infinite b
r)
interleaveList' Infinite a -> b
f (a
y : [a]
ys) Infinite b
r = (a
y a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
us, Infinite a -> b
f (a
t a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< a
y a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
us) b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< Infinite b
zs)
where
(Infinite a
us, Infinite b
zs) = (Infinite a -> b) -> [a] -> Infinite b -> (Infinite a, Infinite b)
forall b.
(Infinite a -> b) -> [a] -> Infinite b -> (Infinite a, Infinite b)
interleaveList' (Infinite a -> b
f (Infinite a -> b) -> (Infinite a -> Infinite a) -> Infinite a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
y a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:<)) [a]
ys Infinite b
r
scanl :: (b -> a -> b) -> b -> Infinite a -> Infinite b
scanl :: forall b a. (b -> a -> b) -> b -> Infinite a -> Infinite b
scanl b -> a -> b
f b
z0 = (b
z0 b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:<) (Infinite b -> Infinite b)
-> (Infinite a -> Infinite b) -> Infinite a -> Infinite b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Infinite a -> b -> Infinite b) -> b -> Infinite a -> Infinite b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> (b -> Infinite b) -> b -> Infinite b)
-> Infinite a -> b -> Infinite b
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x b -> Infinite b
acc b
z -> let fzx :: b
fzx = b -> a -> b
f b
z a
x in b
fzx b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< b -> Infinite b
acc b
fzx)) b
z0
scanlFB :: (elt' -> elt -> elt') -> (elt' -> lst -> lst) -> elt -> (elt' -> lst) -> elt' -> lst
scanlFB :: forall elt' elt lst.
(elt' -> elt -> elt')
-> (elt' -> lst -> lst) -> elt -> (elt' -> lst) -> elt' -> lst
scanlFB elt' -> elt -> elt'
f elt' -> lst -> lst
cons = \elt
elt elt' -> lst
g -> (elt' -> lst) -> elt' -> lst
forall a b. (a -> b) -> a -> b
oneShot (\elt'
x -> let elt' :: elt'
elt' = elt' -> elt -> elt'
f elt'
x elt
elt in elt'
elt' elt' -> lst -> lst
`cons` elt' -> lst
g elt'
elt')
{-# NOINLINE [1] scanl #-}
{-# INLINE [0] scanlFB #-}
{-# RULES
"scanl" [~1] forall f a bs.
scanl f a bs =
build (\cons -> a `cons` foldr (scanlFB f cons) bs a)
"scanlList" [1] forall f (a :: a) bs.
foldr (scanlFB f (:<)) bs a =
tail (scanl f a bs)
#-}
scanl' :: (b -> a -> b) -> b -> Infinite a -> Infinite b
scanl' :: forall b a. (b -> a -> b) -> b -> Infinite a -> Infinite b
scanl' b -> a -> b
f b
z0 = (b
z0 b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:<) (Infinite b -> Infinite b)
-> (Infinite a -> Infinite b) -> Infinite a -> Infinite b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Infinite a -> b -> Infinite b) -> b -> Infinite a -> Infinite b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> (b -> Infinite b) -> b -> Infinite b)
-> Infinite a -> b -> Infinite b
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x b -> Infinite b
acc b
z -> let !fzx :: b
fzx = b -> a -> b
f b
z a
x in b
fzx b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< b -> Infinite b
acc b
fzx)) b
z0
scanlFB' :: (elt' -> elt -> elt') -> (elt' -> lst -> lst) -> elt -> (elt' -> lst) -> elt' -> lst
scanlFB' :: forall elt' elt lst.
(elt' -> elt -> elt')
-> (elt' -> lst -> lst) -> elt -> (elt' -> lst) -> elt' -> lst
scanlFB' elt' -> elt -> elt'
f elt' -> lst -> lst
cons = \elt
elt elt' -> lst
g -> (elt' -> lst) -> elt' -> lst
forall a b. (a -> b) -> a -> b
oneShot (\elt'
x -> let !elt' :: elt'
elt' = elt' -> elt -> elt'
f elt'
x elt
elt in elt'
elt' elt' -> lst -> lst
`cons` elt' -> lst
g elt'
elt')
{-# NOINLINE [1] scanl' #-}
{-# INLINE [0] scanlFB' #-}
{-# RULES
"scanl'" [~1] forall f a bs.
scanl' f a bs =
build (\cons -> a `cons` foldr (scanlFB' f cons) bs a)
"scanlList'" [1] forall f (a :: a) bs.
foldr (scanlFB' f (:<)) bs a =
tail (scanl' f a bs)
#-}
scanl1 :: (a -> a -> a) -> Infinite a -> Infinite a
scanl1 :: forall a. (a -> a -> a) -> Infinite a -> Infinite a
scanl1 a -> a -> a
f (a
x :< Infinite a
xs) = (a -> a -> a) -> a -> Infinite a -> Infinite a
forall b a. (b -> a -> b) -> b -> Infinite a -> Infinite b
scanl a -> a -> a
f a
x Infinite a
xs
mapAccumL :: (acc -> x -> (acc, y)) -> acc -> Infinite x -> Infinite y
mapAccumL :: forall acc x y.
(acc -> x -> (acc, y)) -> acc -> Infinite x -> Infinite y
mapAccumL acc -> x -> (acc, y)
f = (Infinite x -> acc -> Infinite y)
-> acc -> Infinite x -> Infinite y
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((x -> (acc -> Infinite y) -> acc -> Infinite y)
-> Infinite x -> acc -> Infinite y
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\x
x acc -> Infinite y
acc acc
s -> let (acc
s', y
y) = acc -> x -> (acc, y)
f acc
s x
x in y
y y -> Infinite y -> Infinite y
forall a. a -> Infinite a -> Infinite a
:< acc -> Infinite y
acc acc
s'))
mapAccumLFB :: (acc -> x -> (acc, y)) -> x -> (acc -> Infinite y) -> acc -> Infinite y
mapAccumLFB :: forall acc x y.
(acc -> x -> (acc, y))
-> x -> (acc -> Infinite y) -> acc -> Infinite y
mapAccumLFB acc -> x -> (acc, y)
f = \x
x acc -> Infinite y
r -> (acc -> Infinite y) -> acc -> Infinite y
forall a b. (a -> b) -> a -> b
oneShot (\acc
s -> let (acc
s', y
y) = acc -> x -> (acc, y)
f acc
s x
x in y
y y -> Infinite y -> Infinite y
forall a. a -> Infinite a -> Infinite a
:< acc -> Infinite y
r acc
s')
{-# NOINLINE [1] mapAccumL #-}
{-# INLINE [0] mapAccumLFB #-}
{-# RULES
"mapAccumL" [~1] forall f s xs.
mapAccumL f s xs =
foldr (mapAccumLFB f) xs s
"mapAccumLList" [1] forall f s xs.
foldr (mapAccumLFB f) xs s =
mapAccumL f s xs
#-}
iterate :: (a -> a) -> a -> Infinite a
iterate :: forall a. (a -> a) -> a -> Infinite a
iterate a -> a
f = a -> Infinite a
go
where
go :: a -> Infinite a
go a
x = a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< a -> Infinite a
go (a -> a
f a
x)
iterateFB :: (elt -> lst -> lst) -> (elt -> elt) -> elt -> lst
iterateFB :: forall elt lst. (elt -> lst -> lst) -> (elt -> elt) -> elt -> lst
iterateFB elt -> lst -> lst
cons elt -> elt
f = elt -> lst
go
where
go :: elt -> lst
go elt
x = elt
x elt -> lst -> lst
`cons` elt -> lst
go (elt -> elt
f elt
x)
{-# NOINLINE [1] iterate #-}
{-# INLINE [0] iterateFB #-}
{-# RULES
"iterate" [~1] forall f x. iterate f x = build (\cons -> iterateFB cons f x)
"iterateFB" [1] iterateFB (:<) = iterate
#-}
iterate' :: (a -> a) -> a -> Infinite a
iterate' :: forall a. (a -> a) -> a -> Infinite a
iterate' a -> a
f = a -> Infinite a
go
where
go :: a -> Infinite a
go !a
x = a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< a -> Infinite a
go (a -> a
f a
x)
iterateFB' :: (elt -> lst -> lst) -> (elt -> elt) -> elt -> lst
iterateFB' :: forall elt lst. (elt -> lst -> lst) -> (elt -> elt) -> elt -> lst
iterateFB' elt -> lst -> lst
cons elt -> elt
f = elt -> lst
go
where
go :: elt -> lst
go !elt
x = elt
x elt -> lst -> lst
`cons` elt -> lst
go (elt -> elt
f elt
x)
{-# NOINLINE [1] iterate' #-}
{-# INLINE [0] iterateFB' #-}
{-# RULES
"iterate'" [~1] forall f x. iterate' f x = build (\cons -> iterateFB' cons f x)
"iterateFB'" [1] iterateFB' (:<) = iterate'
#-}
repeat :: a -> Infinite a
repeat :: forall a. a -> Infinite a
repeat a
x = Infinite a
go
where
go :: Infinite a
go = a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
go
repeatFB :: (elt -> lst -> lst) -> elt -> lst
repeatFB :: forall elt lst. (elt -> lst -> lst) -> elt -> lst
repeatFB elt -> lst -> lst
cons elt
x = lst
go
where
go :: lst
go = elt
x elt -> lst -> lst
`cons` lst
go
{-# NOINLINE [1] repeat #-}
{-# INLINE [0] repeatFB #-}
{-# RULES
"repeat" [~1] forall x. repeat x = build (`repeatFB` x)
"repeatFB" [1] repeatFB (:<) = repeat
#-}
cycle :: NonEmpty a -> Infinite a
cycle :: forall a. NonEmpty a -> Infinite a
cycle (a
x :| [a]
xs) = [a] -> Infinite a
forall a. [a] -> Infinite a
unsafeCycle (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs)
{-# INLINE cycle #-}
unsafeCycle :: [a] -> Infinite a
unsafeCycle :: forall a. [a] -> Infinite a
unsafeCycle [a]
xs = Infinite a
go
where
go :: Infinite a
go = [a]
xs [a] -> Infinite a -> Infinite a
forall a. [a] -> Infinite a -> Infinite a
`prependList` Infinite a
go
unsafeCycleFB :: (elt -> lst -> lst) -> [elt] -> lst
unsafeCycleFB :: forall elt lst. (elt -> lst -> lst) -> [elt] -> lst
unsafeCycleFB elt -> lst -> lst
cons [elt]
xs = lst
go
where
go :: lst
go = (elt -> lst -> lst) -> lst -> [elt] -> lst
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr elt -> lst -> lst
cons lst
go [elt]
xs
{-# NOINLINE [1] unsafeCycle #-}
{-# INLINE [0] unsafeCycleFB #-}
{-# RULES
"unsafeCycle" [~1] forall x. unsafeCycle x = build (`unsafeCycleFB` x)
"unsafeCycleFB" [1] unsafeCycleFB (:<) = unsafeCycle
#-}
unfoldr :: (b -> (a, b)) -> b -> Infinite a
unfoldr :: forall b a. (b -> (a, b)) -> b -> Infinite a
unfoldr b -> (a, b)
f = b -> Infinite a
go
where
go :: b -> Infinite a
go b
b = let (a
a, b
b') = b -> (a, b)
f b
b in a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< b -> Infinite a
go b
b'
{-# INLINE unfoldr #-}
tabulate :: (Word -> a) -> Infinite a
tabulate :: forall a. (Word -> a) -> Infinite a
tabulate Word -> a
f = (Word -> (a, Word)) -> Word -> Infinite a
forall b a. (b -> (a, b)) -> b -> Infinite a
unfoldr (\Word
n -> (Word -> a
f Word
n, Word
n Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1)) Word
0
{-# INLINE tabulate #-}
take :: Int -> Infinite a -> [a]
take :: forall a. Int -> Infinite a -> [a]
take = (Int -> Infinite a -> [a]) -> Int -> Infinite a -> [a]
forall a. a -> a
GHC.Exts.inline Int -> Infinite a -> [a]
forall i a. Integral i => i -> Infinite a -> [a]
genericTake
{-# INLINE [1] take #-}
{-# INLINE [1] genericTake #-}
{-# INLINE [0] genericTakeFB #-}
{-# RULES
"take"
take =
genericTake
"genericTake" [~1] forall n xs.
genericTake n xs =
GHC.Exts.build
( \cons nil ->
if n >= 1
then foldr (genericTakeFB cons nil) xs n
else nil
)
"genericTakeList" [1] forall n xs.
foldr (genericTakeFB (:) []) xs n =
genericTake n xs
#-}
genericTake :: Integral i => i -> Infinite a -> [a]
genericTake :: forall i a. Integral i => i -> Infinite a -> [a]
genericTake i
n
| i
n i -> i -> Bool
forall a. Ord a => a -> a -> Bool
< i
1 = [a] -> Infinite a -> [a]
forall a b. a -> b -> a
const []
| Bool
otherwise = (Infinite a -> i -> [a]) -> i -> Infinite a -> [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> (i -> [a]) -> i -> [a]) -> Infinite a -> i -> [a]
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
hd i -> [a]
f i
m -> a
hd a -> [a] -> [a]
forall a. a -> [a] -> [a]
: (if i
m i -> i -> Bool
forall a. Ord a => a -> a -> Bool
<= i
1 then [] else i -> [a]
f (i
m i -> i -> i
forall a. Num a => a -> a -> a
- i
1)))) i
n
genericTakeFB :: Integral i => (elt -> lst -> lst) -> lst -> elt -> (i -> lst) -> i -> lst
genericTakeFB :: forall i elt lst.
Integral i =>
(elt -> lst -> lst) -> lst -> elt -> (i -> lst) -> i -> lst
genericTakeFB elt -> lst -> lst
cons lst
nil elt
x i -> lst
xs = \i
m -> if i
m i -> i -> Bool
forall a. Ord a => a -> a -> Bool
<= i
1 then elt
x elt -> lst -> lst
`cons` lst
nil else elt
x elt -> lst -> lst
`cons` i -> lst
xs (i
m i -> i -> i
forall a. Num a => a -> a -> a
- i
1)
drop :: Int -> Infinite a -> Infinite a
drop :: forall a. Int -> Infinite a -> Infinite a
drop = (Int -> Infinite a -> Infinite a)
-> Int -> Infinite a -> Infinite a
forall a. a -> a
GHC.Exts.inline Int -> Infinite a -> Infinite a
forall i a. Integral i => i -> Infinite a -> Infinite a
genericDrop
genericDrop :: Integral i => i -> Infinite a -> Infinite a
genericDrop :: forall i a. Integral i => i -> Infinite a -> Infinite a
genericDrop = (Infinite a -> i -> Infinite a) -> i -> Infinite a -> Infinite a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> Infinite a -> (i -> Infinite a) -> i -> Infinite a)
-> Infinite a -> i -> Infinite a
forall a b. (a -> Infinite a -> b -> b) -> Infinite a -> b
para (\a
hd Infinite a
tl i -> Infinite a
f i
m -> if i
m i -> i -> Bool
forall a. Ord a => a -> a -> Bool
< i
1 then a
hd a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
tl else i -> Infinite a
f (i
m i -> i -> i
forall a. Num a => a -> a -> a
- i
1)))
{-# INLINEABLE genericDrop #-}
splitAt :: Int -> Infinite a -> ([a], Infinite a)
splitAt :: forall a. Int -> Infinite a -> ([a], Infinite a)
splitAt = (Int -> Infinite a -> ([a], Infinite a))
-> Int -> Infinite a -> ([a], Infinite a)
forall a. a -> a
GHC.Exts.inline Int -> Infinite a -> ([a], Infinite a)
forall i a. Integral i => i -> Infinite a -> ([a], Infinite a)
genericSplitAt
genericSplitAt :: Integral i => i -> Infinite a -> ([a], Infinite a)
genericSplitAt :: forall i a. Integral i => i -> Infinite a -> ([a], Infinite a)
genericSplitAt i
n
| i
n i -> i -> Bool
forall a. Ord a => a -> a -> Bool
< i
1 = ([],)
| Bool
otherwise = (Infinite a -> i -> ([a], Infinite a))
-> i -> Infinite a -> ([a], Infinite a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a
-> Infinite a
-> (i -> ([a], Infinite a))
-> i
-> ([a], Infinite a))
-> Infinite a -> i -> ([a], Infinite a)
forall a b. (a -> Infinite a -> b -> b) -> Infinite a -> b
para (\a
hd Infinite a
tl i -> ([a], Infinite a)
f i
m -> if i
m i -> i -> Bool
forall a. Ord a => a -> a -> Bool
<= i
1 then ([a
hd], Infinite a
tl) else ([a] -> [a]) -> ([a], Infinite a) -> ([a], Infinite a)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (a
hd a -> [a] -> [a]
forall a. a -> [a] -> [a]
:) (i -> ([a], Infinite a)
f (i
m i -> i -> i
forall a. Num a => a -> a -> a
- i
1)))) i
n
{-# INLINEABLE genericSplitAt #-}
takeWhile :: (a -> Bool) -> Infinite a -> [a]
takeWhile :: forall a. (a -> Bool) -> Infinite a -> [a]
takeWhile a -> Bool
p = (a -> [a] -> [a]) -> Infinite a -> [a]
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x [a]
xs -> if a -> Bool
p a
x then a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs else [])
takeWhileFB :: (elt -> Bool) -> (elt -> lst -> lst) -> lst -> elt -> lst -> lst
takeWhileFB :: forall elt lst.
(elt -> Bool) -> (elt -> lst -> lst) -> lst -> elt -> lst -> lst
takeWhileFB elt -> Bool
p elt -> lst -> lst
cons lst
nil = \elt
x lst
r -> if elt -> Bool
p elt
x then elt
x elt -> lst -> lst
`cons` lst
r else lst
nil
{-# NOINLINE [1] takeWhile #-}
{-# INLINE [0] takeWhileFB #-}
{-# RULES
"takeWhile" [~1] forall p xs.
takeWhile p xs =
GHC.Exts.build (\cons nil -> foldr (takeWhileFB p cons nil) xs)
"takeWhileList" [1] forall p.
foldr (takeWhileFB p (:) []) =
takeWhile p
#-}
dropWhile :: (a -> Bool) -> Infinite a -> Infinite a
dropWhile :: forall a. (a -> Bool) -> Infinite a -> Infinite a
dropWhile a -> Bool
p = (a -> Infinite a -> Infinite a -> Infinite a)
-> Infinite a -> Infinite a
forall a b. (a -> Infinite a -> b -> b) -> Infinite a -> b
para (\a
x Infinite a
xs -> if a -> Bool
p a
x then Infinite a -> Infinite a
forall a. a -> a
id else Infinite a -> Infinite a -> Infinite a
forall a b. a -> b -> a
const (a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
xs))
span :: (a -> Bool) -> Infinite a -> ([a], Infinite a)
span :: forall a. (a -> Bool) -> Infinite a -> ([a], Infinite a)
span a -> Bool
p = (a -> Infinite a -> ([a], Infinite a) -> ([a], Infinite a))
-> Infinite a -> ([a], Infinite a)
forall a b. (a -> Infinite a -> b -> b) -> Infinite a -> b
para (\a
x Infinite a
xs -> if a -> Bool
p a
x then ([a] -> [a]) -> ([a], Infinite a) -> ([a], Infinite a)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
:) else ([a], Infinite a) -> ([a], Infinite a) -> ([a], Infinite a)
forall a b. a -> b -> a
const ([], a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
xs))
break :: (a -> Bool) -> Infinite a -> ([a], Infinite a)
break :: forall a. (a -> Bool) -> Infinite a -> ([a], Infinite a)
break = (a -> Bool) -> Infinite a -> ([a], Infinite a)
forall a. (a -> Bool) -> Infinite a -> ([a], Infinite a)
span ((a -> Bool) -> Infinite a -> ([a], Infinite a))
-> ((a -> Bool) -> a -> Bool)
-> (a -> Bool)
-> Infinite a
-> ([a], Infinite a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Bool
not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)
stripPrefix :: Eq a => [a] -> Infinite a -> Maybe (Infinite a)
stripPrefix :: forall a. Eq a => [a] -> Infinite a -> Maybe (Infinite a)
stripPrefix [] = Infinite a -> Maybe (Infinite a)
forall a. a -> Maybe a
Just
stripPrefix (a
p : [a]
ps) = (Infinite a -> NonEmpty a -> Maybe (Infinite a))
-> NonEmpty a -> Infinite a -> Maybe (Infinite a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a
-> Infinite a
-> (NonEmpty a -> Maybe (Infinite a))
-> NonEmpty a
-> Maybe (Infinite a))
-> Infinite a -> NonEmpty a -> Maybe (Infinite a)
forall a b. (a -> Infinite a -> b -> b) -> Infinite a -> b
para a
-> Infinite a
-> (NonEmpty a -> Maybe (Infinite a))
-> NonEmpty a
-> Maybe (Infinite a)
forall {a} {a}.
Eq a =>
a -> a -> (NonEmpty a -> Maybe a) -> NonEmpty a -> Maybe a
alg) (a
p a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
ps)
where
alg :: a -> a -> (NonEmpty a -> Maybe a) -> NonEmpty a -> Maybe a
alg a
x a
xs NonEmpty a -> Maybe a
acc (a
y :| [a]
ys)
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y = Maybe a -> (NonEmpty a -> Maybe a) -> Maybe (NonEmpty a) -> Maybe a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (a -> Maybe a
forall a. a -> Maybe a
Just a
xs) NonEmpty a -> Maybe a
acc ([a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [a]
ys)
| Bool
otherwise = Maybe a
forall a. Maybe a
Nothing
group :: Eq a => Infinite a -> Infinite (NonEmpty a)
group :: forall a. Eq a => Infinite a -> Infinite (NonEmpty a)
group = (a -> a -> Bool) -> Infinite a -> Infinite (NonEmpty a)
forall a. (a -> a -> Bool) -> Infinite a -> Infinite (NonEmpty a)
groupBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
groupBy :: (a -> a -> Bool) -> Infinite a -> Infinite (NonEmpty a)
groupBy :: forall a. (a -> a -> Bool) -> Infinite a -> Infinite (NonEmpty a)
groupBy a -> a -> Bool
f = Infinite a -> Infinite (NonEmpty a)
go
where
go :: Infinite a -> Infinite (NonEmpty a)
go (a
x :< Infinite a
xs) = (a
x a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
ys) NonEmpty a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
forall a. a -> Infinite a -> Infinite a
:< Infinite a -> Infinite (NonEmpty a)
go Infinite a
zs
where
([a]
ys, Infinite a
zs) = (a -> Bool) -> Infinite a -> ([a], Infinite a)
forall a. (a -> Bool) -> Infinite a -> ([a], Infinite a)
span (a -> a -> Bool
f a
x) Infinite a
xs
inits :: Infinite a -> Infinite [a]
inits :: forall a. Infinite a -> Infinite [a]
inits =
(SnocBuilder a -> [a]) -> Infinite (SnocBuilder a) -> Infinite [a]
forall a b. (a -> b) -> Infinite a -> Infinite b
map (\(SnocBuilder Word
_ [a]
front [a]
rear) -> [a]
front [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
List.++ [a] -> [a]
forall a. [a] -> [a]
List.reverse [a]
rear)
(Infinite (SnocBuilder a) -> Infinite [a])
-> (Infinite a -> Infinite (SnocBuilder a))
-> Infinite a
-> Infinite [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SnocBuilder a -> a -> SnocBuilder a)
-> SnocBuilder a -> Infinite a -> Infinite (SnocBuilder a)
forall b a. (b -> a -> b) -> b -> Infinite a -> Infinite b
scanl'
(\(SnocBuilder Word
count [a]
front [a]
rear) a
x -> Word -> [a] -> [a] -> SnocBuilder a
forall a. Word -> [a] -> [a] -> SnocBuilder a
snocBuilder (Word
count Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1) [a]
front (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
rear))
(Word -> [a] -> [a] -> SnocBuilder a
forall a. Word -> [a] -> [a] -> SnocBuilder a
SnocBuilder Word
0 [] [])
data SnocBuilder a = SnocBuilder
{ forall a. SnocBuilder a -> Word
_count :: !Word
, forall a. SnocBuilder a -> [a]
_front :: [a]
, forall a. SnocBuilder a -> [a]
_rear :: [a]
}
snocBuilder :: Word -> [a] -> [a] -> SnocBuilder a
snocBuilder :: forall a. Word -> [a] -> [a] -> SnocBuilder a
snocBuilder Word
count [a]
front [a]
rear
| Word
count Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
< Word
8 Bool -> Bool -> Bool
|| (Word
count Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. (Word
count Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1)) Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
/= Word
0 =
Word -> [a] -> [a] -> SnocBuilder a
forall a. Word -> [a] -> [a] -> SnocBuilder a
SnocBuilder Word
count [a]
front [a]
rear
| Bool
otherwise =
Word -> [a] -> [a] -> SnocBuilder a
forall a. Word -> [a] -> [a] -> SnocBuilder a
SnocBuilder Word
count ([a]
front [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
List.++ [a] -> [a]
forall a. [a] -> [a]
List.reverse [a]
rear) []
{-# INLINE snocBuilder #-}
inits1 :: Infinite a -> Infinite (NonEmpty a)
inits1 :: forall a. Infinite a -> Infinite (NonEmpty a)
inits1 (a
x :< Infinite a
xs) = ([a] -> NonEmpty a) -> Infinite [a] -> Infinite (NonEmpty a)
forall a b. (a -> b) -> Infinite a -> Infinite b
map (a
x a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:|) (Infinite a -> Infinite [a]
forall a. Infinite a -> Infinite [a]
inits Infinite a
xs)
tails :: Infinite a -> Infinite (Infinite a)
tails :: forall a. Infinite a -> Infinite (Infinite a)
tails = (a -> Infinite (Infinite a) -> Infinite (Infinite a))
-> Infinite a -> Infinite (Infinite a)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x xss :: Infinite (Infinite a)
xss@(~(Infinite a
xs :< Infinite (Infinite a)
_)) -> (a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
xs) Infinite a -> Infinite (Infinite a) -> Infinite (Infinite a)
forall a. a -> Infinite a -> Infinite a
:< Infinite (Infinite a)
xss)
isPrefixOf :: Eq a => [a] -> Infinite a -> Bool
isPrefixOf :: forall a. Eq a => [a] -> Infinite a -> Bool
isPrefixOf [] = Bool -> Infinite a -> Bool
forall a b. a -> b -> a
const Bool
True
isPrefixOf (a
p : [a]
ps) = (Infinite a -> NonEmpty a -> Bool)
-> NonEmpty a -> Infinite a -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> (NonEmpty a -> Bool) -> NonEmpty a -> Bool)
-> Infinite a -> NonEmpty a -> Bool
forall a b. (a -> b -> b) -> Infinite a -> b
foldr a -> (NonEmpty a -> Bool) -> NonEmpty a -> Bool
forall {a}. Eq a => a -> (NonEmpty a -> Bool) -> NonEmpty a -> Bool
alg) (a
p a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
ps)
where
alg :: a -> (NonEmpty a -> Bool) -> NonEmpty a -> Bool
alg a
x NonEmpty a -> Bool
acc (a
y :| [a]
ys) = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y Bool -> Bool -> Bool
&& Bool -> (NonEmpty a -> Bool) -> Maybe (NonEmpty a) -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True NonEmpty a -> Bool
acc ([a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [a]
ys)
lookup :: Eq a => a -> Infinite (a, b) -> b
lookup :: forall a b. Eq a => a -> Infinite (a, b) -> b
lookup a
a = ((a, b) -> b -> b) -> Infinite (a, b) -> b
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(a
a', b
b) b
b' -> if a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a' then b
b else b
b')
find :: (a -> Bool) -> Infinite a -> a
find :: forall a. (a -> Bool) -> Infinite a -> a
find a -> Bool
f = (a -> a -> a) -> Infinite a -> a
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
a a
a' -> if a -> Bool
f a
a then a
a else a
a')
filter :: (a -> Bool) -> Infinite a -> Infinite a
filter :: forall a. (a -> Bool) -> Infinite a -> Infinite a
filter a -> Bool
f = (a -> Infinite a -> Infinite a) -> Infinite a -> Infinite a
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
a -> if a -> Bool
f a
a then (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:<) else Infinite a -> Infinite a
forall a. a -> a
id)
filterFB :: (elt -> lst -> lst) -> (elt -> Bool) -> elt -> lst -> lst
filterFB :: forall elt lst.
(elt -> lst -> lst) -> (elt -> Bool) -> elt -> lst -> lst
filterFB elt -> lst -> lst
cons elt -> Bool
f elt
x lst
r
| elt -> Bool
f elt
x = elt
x elt -> lst -> lst
`cons` lst
r
| Bool
otherwise = lst
r
{-# NOINLINE [1] filter #-}
{-# INLINE [0] filterFB #-}
{-# RULES
"filter" [~1] forall f xs.
filter f xs =
build (\cons -> foldr (filterFB cons f) xs)
"filterList" [1] forall f.
foldr (filterFB (:<) f) =
filter f
"filterFB" forall cons f g.
filterFB (filterFB cons f) g =
filterFB cons (\x -> f x && g x)
#-}
partition :: (a -> Bool) -> Infinite a -> (Infinite a, Infinite a)
partition :: forall a. (a -> Bool) -> Infinite a -> (Infinite a, Infinite a)
partition a -> Bool
f = (a -> (Infinite a, Infinite a) -> (Infinite a, Infinite a))
-> Infinite a -> (Infinite a, Infinite a)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
a -> if a -> Bool
f a
a then (Infinite a -> Infinite a)
-> (Infinite a, Infinite a) -> (Infinite a, Infinite a)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:<) else (Infinite a -> Infinite a)
-> (Infinite a, Infinite a) -> (Infinite a, Infinite a)
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:<))
(!!) :: Infinite a -> Word -> a
!! :: forall a. Infinite a -> Word -> a
(!!) Infinite a
xs Word
n =
Bool -> a -> a
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Word
n Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
forall a. Bounded a => a
maxBound :: Int)) (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$
(a -> (Word -> a) -> Word -> a) -> Infinite a -> Word -> a
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x Word -> a
acc Word
m -> if Word
m Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
== Word
0 then a
x else Word -> a
acc (Word
m Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1)) Infinite a
xs Word
n
infixl 9 !!
elemIndex :: Eq a => a -> Infinite a -> Word
elemIndex :: forall a. Eq a => a -> Infinite a -> Word
elemIndex = (a -> Bool) -> Infinite a -> Word
forall a. (a -> Bool) -> Infinite a -> Word
findIndex ((a -> Bool) -> Infinite a -> Word)
-> (a -> a -> Bool) -> a -> Infinite a -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
elemIndices :: Eq a => a -> Infinite a -> Infinite Word
elemIndices :: forall a. Eq a => a -> Infinite a -> Infinite Word
elemIndices = (a -> Bool) -> Infinite a -> Infinite Word
forall a. (a -> Bool) -> Infinite a -> Infinite Word
findIndices ((a -> Bool) -> Infinite a -> Infinite Word)
-> (a -> a -> Bool) -> a -> Infinite a -> Infinite Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
findIndex :: (a -> Bool) -> Infinite a -> Word
findIndex :: forall a. (a -> Bool) -> Infinite a -> Word
findIndex a -> Bool
f = (Infinite a -> Word -> Word) -> Word -> Infinite a -> Word
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> (Word -> Word) -> Word -> Word) -> Infinite a -> Word -> Word
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x Word -> Word
acc !Word
m -> if a -> Bool
f a
x then Word
m else Word -> Word
acc (Word
m Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1))) Word
0
findIndices :: (a -> Bool) -> Infinite a -> Infinite Word
findIndices :: forall a. (a -> Bool) -> Infinite a -> Infinite Word
findIndices a -> Bool
f = (Infinite a -> Word -> Infinite Word)
-> Word -> Infinite a -> Infinite Word
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> (Word -> Infinite Word) -> Word -> Infinite Word)
-> Infinite a -> Word -> Infinite Word
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x Word -> Infinite Word
acc !Word
m -> (if a -> Bool
f a
x then (Word
m Word -> Infinite Word -> Infinite Word
forall a. a -> Infinite a -> Infinite a
:<) else Infinite Word -> Infinite Word
forall a. a -> a
id) (Word -> Infinite Word
acc (Word
m Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1)))) Word
0
heteroZip :: Traversable t => Infinite a -> t b -> t (a, b)
heteroZip :: forall (t :: * -> *) a b.
Traversable t =>
Infinite a -> t b -> t (a, b)
heteroZip = (a -> b -> (a, b)) -> Infinite a -> t b -> t (a, b)
forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> c) -> Infinite a -> t b -> t c
heteroZipWith (,)
heteroZipWith :: Traversable t => (a -> b -> c) -> Infinite a -> t b -> t c
heteroZipWith :: forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> c) -> Infinite a -> t b -> t c
heteroZipWith a -> b -> c
f = ((Infinite a, t c) -> t c
forall a b. (a, b) -> b
snd ((Infinite a, t c) -> t c)
-> (t b -> (Infinite a, t c)) -> t b -> t c
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((t b -> (Infinite a, t c)) -> t b -> t c)
-> (Infinite a -> t b -> (Infinite a, t c))
-> Infinite a
-> t b
-> t c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Infinite a -> b -> (Infinite a, c))
-> Infinite a -> t b -> (Infinite a, t c)
forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
Traversable.mapAccumL (\(a
x :< Infinite a
xs) b
b -> (Infinite a
xs, a -> b -> c
f a
x b
b))
unzip :: Infinite (a, b) -> (Infinite a, Infinite b)
unzip :: forall a b. Infinite (a, b) -> (Infinite a, Infinite b)
unzip = ((a, b) -> (Infinite a, Infinite b) -> (Infinite a, Infinite b))
-> Infinite (a, b) -> (Infinite a, Infinite b)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(a
a, b
b) ~(Infinite a
as, Infinite b
bs) -> (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
as, b
b b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< Infinite b
bs))
{-# INLINE unzip #-}
unzip3 :: Infinite (a, b, c) -> (Infinite a, Infinite b, Infinite c)
unzip3 :: forall a b c.
Infinite (a, b, c) -> (Infinite a, Infinite b, Infinite c)
unzip3 = ((a, b, c)
-> (Infinite a, Infinite b, Infinite c)
-> (Infinite a, Infinite b, Infinite c))
-> Infinite (a, b, c) -> (Infinite a, Infinite b, Infinite c)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(a
a, b
b, c
c) ~(Infinite a
as, Infinite b
bs, Infinite c
cs) -> (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
as, b
b b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< Infinite b
bs, c
c c -> Infinite c -> Infinite c
forall a. a -> Infinite a -> Infinite a
:< Infinite c
cs))
{-# INLINE unzip3 #-}
unzip4 :: Infinite (a, b, c, d) -> (Infinite a, Infinite b, Infinite c, Infinite d)
unzip4 :: forall a b c d.
Infinite (a, b, c, d)
-> (Infinite a, Infinite b, Infinite c, Infinite d)
unzip4 = ((a, b, c, d)
-> (Infinite a, Infinite b, Infinite c, Infinite d)
-> (Infinite a, Infinite b, Infinite c, Infinite d))
-> Infinite (a, b, c, d)
-> (Infinite a, Infinite b, Infinite c, Infinite d)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(a
a, b
b, c
c, d
d) ~(Infinite a
as, Infinite b
bs, Infinite c
cs, Infinite d
ds) -> (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
as, b
b b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< Infinite b
bs, c
c c -> Infinite c -> Infinite c
forall a. a -> Infinite a -> Infinite a
:< Infinite c
cs, d
d d -> Infinite d -> Infinite d
forall a. a -> Infinite a -> Infinite a
:< Infinite d
ds))
{-# INLINE unzip4 #-}
unzip5 :: Infinite (a, b, c, d, e) -> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e)
unzip5 :: forall a b c d e.
Infinite (a, b, c, d, e)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e)
unzip5 = ((a, b, c, d, e)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e))
-> Infinite (a, b, c, d, e)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(a
a, b
b, c
c, d
d, e
e) ~(Infinite a
as, Infinite b
bs, Infinite c
cs, Infinite d
ds, Infinite e
es) -> (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
as, b
b b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< Infinite b
bs, c
c c -> Infinite c -> Infinite c
forall a. a -> Infinite a -> Infinite a
:< Infinite c
cs, d
d d -> Infinite d -> Infinite d
forall a. a -> Infinite a -> Infinite a
:< Infinite d
ds, e
e e -> Infinite e -> Infinite e
forall a. a -> Infinite a -> Infinite a
:< Infinite e
es))
{-# INLINE unzip5 #-}
unzip6 :: Infinite (a, b, c, d, e, f) -> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e, Infinite f)
unzip6 :: forall a b c d e f.
Infinite (a, b, c, d, e, f)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e,
Infinite f)
unzip6 = ((a, b, c, d, e, f)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e,
Infinite f)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e,
Infinite f))
-> Infinite (a, b, c, d, e, f)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e,
Infinite f)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(a
a, b
b, c
c, d
d, e
e, f
f) ~(Infinite a
as, Infinite b
bs, Infinite c
cs, Infinite d
ds, Infinite e
es, Infinite f
fs) -> (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
as, b
b b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< Infinite b
bs, c
c c -> Infinite c -> Infinite c
forall a. a -> Infinite a -> Infinite a
:< Infinite c
cs, d
d d -> Infinite d -> Infinite d
forall a. a -> Infinite a -> Infinite a
:< Infinite d
ds, e
e e -> Infinite e -> Infinite e
forall a. a -> Infinite a -> Infinite a
:< Infinite e
es, f
f f -> Infinite f -> Infinite f
forall a. a -> Infinite a -> Infinite a
:< Infinite f
fs))
{-# INLINE unzip6 #-}
unzip7 :: Infinite (a, b, c, d, e, f, g) -> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e, Infinite f, Infinite g)
unzip7 :: forall a b c d e f g.
Infinite (a, b, c, d, e, f, g)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e,
Infinite f, Infinite g)
unzip7 = ((a, b, c, d, e, f, g)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e,
Infinite f, Infinite g)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e,
Infinite f, Infinite g))
-> Infinite (a, b, c, d, e, f, g)
-> (Infinite a, Infinite b, Infinite c, Infinite d, Infinite e,
Infinite f, Infinite g)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(a
a, b
b, c
c, d
d, e
e, f
f, g
g) ~(Infinite a
as, Infinite b
bs, Infinite c
cs, Infinite d
ds, Infinite e
es, Infinite f
fs, Infinite g
gs) -> (a
a a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
as, b
b b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< Infinite b
bs, c
c c -> Infinite c -> Infinite c
forall a. a -> Infinite a -> Infinite a
:< Infinite c
cs, d
d d -> Infinite d -> Infinite d
forall a. a -> Infinite a -> Infinite a
:< Infinite d
ds, e
e e -> Infinite e -> Infinite e
forall a. a -> Infinite a -> Infinite a
:< Infinite e
es, f
f f -> Infinite f -> Infinite f
forall a. a -> Infinite a -> Infinite a
:< Infinite f
fs, g
g g -> Infinite g -> Infinite g
forall a. a -> Infinite a -> Infinite a
:< Infinite g
gs))
{-# INLINE unzip7 #-}
lines :: Infinite Char -> Infinite [Char]
lines :: Infinite Char -> Infinite [Char]
lines = (Char -> Infinite [Char] -> Infinite [Char])
-> Infinite Char -> Infinite [Char]
forall a b. (a -> b -> b) -> Infinite a -> b
foldr Char -> Infinite [Char] -> Infinite [Char]
go
where
go :: Char -> Infinite [Char] -> Infinite [Char]
go Char
'\n' Infinite [Char]
xs = [] [Char] -> Infinite [Char] -> Infinite [Char]
forall a. a -> Infinite a -> Infinite a
:< Infinite [Char]
xs
go Char
c ~([Char]
x :< Infinite [Char]
xs) = (Char
c Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: [Char]
x) [Char] -> Infinite [Char] -> Infinite [Char]
forall a. a -> Infinite a -> Infinite a
:< Infinite [Char]
xs
unlines :: Infinite [Char] -> Infinite Char
unlines :: Infinite [Char] -> Infinite Char
unlines = ([Char] -> Infinite Char -> Infinite Char)
-> Infinite [Char] -> Infinite Char
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\[Char]
l Infinite Char
xs -> [Char]
l [Char] -> Infinite Char -> Infinite Char
forall a. [a] -> Infinite a -> Infinite a
`prependList` (Char
'\n' Char -> Infinite Char -> Infinite Char
forall a. a -> Infinite a -> Infinite a
:< Infinite Char
xs))
words :: Infinite Char -> Infinite (NonEmpty Char)
words :: Infinite Char -> Infinite (NonEmpty Char)
words = ([Char] -> Infinite (NonEmpty Char) -> Infinite (NonEmpty Char))
-> ([Char], Infinite (NonEmpty Char)) -> Infinite (NonEmpty Char)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [Char] -> Infinite (NonEmpty Char) -> Infinite (NonEmpty Char)
forall {a}. [a] -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
repack (([Char], Infinite (NonEmpty Char)) -> Infinite (NonEmpty Char))
-> (Infinite Char -> ([Char], Infinite (NonEmpty Char)))
-> Infinite Char
-> Infinite (NonEmpty Char)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char
-> ([Char], Infinite (NonEmpty Char))
-> ([Char], Infinite (NonEmpty Char)))
-> Infinite Char -> ([Char], Infinite (NonEmpty Char))
forall a b. (a -> b -> b) -> Infinite a -> b
foldr Char
-> ([Char], Infinite (NonEmpty Char))
-> ([Char], Infinite (NonEmpty Char))
go
where
repack :: [a] -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
repack [a]
zs Infinite (NonEmpty a)
acc = Infinite (NonEmpty a)
-> (NonEmpty a -> Infinite (NonEmpty a))
-> Maybe (NonEmpty a)
-> Infinite (NonEmpty a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Infinite (NonEmpty a)
acc (NonEmpty a -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
forall a. a -> Infinite a -> Infinite a
:< Infinite (NonEmpty a)
acc) ([a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [a]
zs)
go :: Char
-> ([Char], Infinite (NonEmpty Char))
-> ([Char], Infinite (NonEmpty Char))
go Char
x ~([Char]
zs, Infinite (NonEmpty Char)
acc) = ([Char]
zs', Infinite (NonEmpty Char)
acc')
where
s :: Bool
s = Char -> Bool
isSpace Char
x
zs' :: [Char]
zs' = if Bool
s then [] else Char
x Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: [Char]
zs
acc' :: Infinite (NonEmpty Char)
acc' = if Bool
s then [Char] -> Infinite (NonEmpty Char) -> Infinite (NonEmpty Char)
forall {a}. [a] -> Infinite (NonEmpty a) -> Infinite (NonEmpty a)
repack [Char]
zs Infinite (NonEmpty Char)
acc else Infinite (NonEmpty Char)
acc
wordsFB :: (NonEmpty Char -> lst -> lst) -> Infinite Char -> lst
wordsFB :: forall lst. (NonEmpty Char -> lst -> lst) -> Infinite Char -> lst
wordsFB NonEmpty Char -> lst -> lst
cons = ([Char] -> lst -> lst) -> ([Char], lst) -> lst
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [Char] -> lst -> lst
repack (([Char], lst) -> lst)
-> (Infinite Char -> ([Char], lst)) -> Infinite Char -> lst
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> ([Char], lst) -> ([Char], lst))
-> Infinite Char -> ([Char], lst)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr Char -> ([Char], lst) -> ([Char], lst)
go
where
repack :: [Char] -> lst -> lst
repack [Char]
zs lst
acc = lst -> (NonEmpty Char -> lst) -> Maybe (NonEmpty Char) -> lst
forall b a. b -> (a -> b) -> Maybe a -> b
maybe lst
acc (NonEmpty Char -> lst -> lst
`cons` lst
acc) ([Char] -> Maybe (NonEmpty Char)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [Char]
zs)
go :: Char -> ([Char], lst) -> ([Char], lst)
go Char
x ~([Char]
zs, lst
acc) = ([Char]
zs', lst
acc')
where
s :: Bool
s = Char -> Bool
isSpace Char
x
zs' :: [Char]
zs' = if Bool
s then [] else Char
x Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: [Char]
zs
acc' :: lst
acc' = if Bool
s then [Char] -> lst -> lst
repack [Char]
zs lst
acc else lst
acc
{-# NOINLINE [1] words #-}
{-# INLINE [0] wordsFB #-}
{-# RULES
"words" [~1] forall s. words s = build (`wordsFB` s)
"wordsList" [1] wordsFB (:<) = words
#-}
unwords :: Infinite (NonEmpty Char) -> Infinite Char
unwords :: Infinite (NonEmpty Char) -> Infinite Char
unwords = (NonEmpty Char -> Infinite Char -> Infinite Char)
-> Infinite (NonEmpty Char) -> Infinite Char
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(Char
l :| [Char]
ls) Infinite Char
acc -> Char
l Char -> Infinite Char -> Infinite Char
forall a. a -> Infinite a -> Infinite a
:< [Char]
ls [Char] -> Infinite Char -> Infinite Char
forall a. [a] -> Infinite a -> Infinite a
`prependList` (Char
' ' Char -> Infinite Char -> Infinite Char
forall a. a -> Infinite a -> Infinite a
:< Infinite Char
acc))
unwordsFB :: (Char -> lst -> lst) -> Infinite (NonEmpty Char) -> lst
unwordsFB :: forall lst. (Char -> lst -> lst) -> Infinite (NonEmpty Char) -> lst
unwordsFB Char -> lst -> lst
cons = (NonEmpty Char -> lst -> lst) -> Infinite (NonEmpty Char) -> lst
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\(Char
l :| [Char]
ls) lst
acc -> Char
l Char -> lst -> lst
`cons` (Char -> lst -> lst) -> lst -> [Char] -> lst
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
List.foldr Char -> lst -> lst
cons (Char
' ' Char -> lst -> lst
`cons` lst
acc) [Char]
ls)
{-# NOINLINE [1] unwords #-}
{-# INLINE [0] unwordsFB #-}
{-# RULES
"unwords" [~1] forall s. unwords s = build (`unwordsFB` s)
"unwordsList" [1] unwordsFB (:<) = unwords
#-}
nub :: Eq a => Infinite a -> Infinite a
nub :: forall a. Eq a => Infinite a -> Infinite a
nub = (a -> a -> Bool) -> Infinite a -> Infinite a
forall a. (a -> a -> Bool) -> Infinite a -> Infinite a
nubBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
nubBy :: (a -> a -> Bool) -> Infinite a -> Infinite a
nubBy :: forall a. (a -> a -> Bool) -> Infinite a -> Infinite a
nubBy a -> a -> Bool
eq = (Infinite a -> [a] -> Infinite a)
-> [a] -> Infinite a -> Infinite a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> ([a] -> Infinite a) -> [a] -> Infinite a)
-> Infinite a -> [a] -> Infinite a
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x [a] -> Infinite a
acc [a]
seen -> if (a -> Bool) -> [a] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
List.any (a -> a -> Bool
`eq` a
x) [a]
seen then [a] -> Infinite a
acc [a]
seen else a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< [a] -> Infinite a
acc (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
seen))) []
nubOrd :: Ord a => Infinite a -> Infinite a
nubOrd :: forall a. Ord a => Infinite a -> Infinite a
nubOrd = (a -> a -> Ordering) -> Infinite a -> Infinite a
forall a. (a -> a -> Ordering) -> Infinite a -> Infinite a
nubOrdBy a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
nubOrdBy :: (a -> a -> Ordering) -> Infinite a -> Infinite a
nubOrdBy :: forall a. (a -> a -> Ordering) -> Infinite a -> Infinite a
nubOrdBy a -> a -> Ordering
cmp = (Infinite a -> Set a -> Infinite a)
-> Set a -> Infinite a -> Infinite a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> (Set a -> Infinite a) -> Set a -> Infinite a)
-> Infinite a -> Set a -> Infinite a
forall a b. (a -> b -> b) -> Infinite a -> b
foldr (\a
x Set a -> Infinite a
acc Set a
seen -> if (a -> a -> Ordering) -> a -> Set a -> Bool
forall a. (a -> a -> Ordering) -> a -> Set a -> Bool
Set.member a -> a -> Ordering
cmp a
x Set a
seen then Set a -> Infinite a
acc Set a
seen else a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Set a -> Infinite a
acc ((a -> a -> Ordering) -> a -> Set a -> Set a
forall a. (a -> a -> Ordering) -> a -> Set a -> Set a
Set.insert a -> a -> Ordering
cmp a
x Set a
seen))) Set a
forall a. Set a
Set.empty
delete :: Eq a => a -> Infinite a -> Infinite a
delete :: forall a. Eq a => a -> Infinite a -> Infinite a
delete = (a -> a -> Bool) -> a -> Infinite a -> Infinite a
forall a b. (a -> b -> Bool) -> a -> Infinite b -> Infinite b
deleteBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
deleteBy :: (a -> b -> Bool) -> a -> Infinite b -> Infinite b
deleteBy :: forall a b. (a -> b -> Bool) -> a -> Infinite b -> Infinite b
deleteBy a -> b -> Bool
eq a
x = (b -> Infinite b -> Infinite b -> Infinite b)
-> Infinite b -> Infinite b
forall a b. (a -> Infinite a -> b -> b) -> Infinite a -> b
para (\b
y Infinite b
ys Infinite b
acc -> if a -> b -> Bool
eq a
x b
y then Infinite b
ys else b
y b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
:< Infinite b
acc)
(\\) :: Eq a => Infinite a -> [a] -> Infinite a
\\ :: forall a. Eq a => Infinite a -> [a] -> Infinite a
(\\) = (a -> a -> Bool) -> Infinite a -> [a] -> Infinite a
forall a b. (a -> b -> Bool) -> Infinite b -> [a] -> Infinite b
deleteFirstsBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
deleteFirstsBy :: (a -> b -> Bool) -> Infinite b -> [a] -> Infinite b
deleteFirstsBy :: forall a b. (a -> b -> Bool) -> Infinite b -> [a] -> Infinite b
deleteFirstsBy a -> b -> Bool
eq = (Infinite b -> a -> Infinite b) -> Infinite b -> [a] -> Infinite b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl ((a -> Infinite b -> Infinite b) -> Infinite b -> a -> Infinite b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> b -> Bool) -> a -> Infinite b -> Infinite b
forall a b. (a -> b -> Bool) -> a -> Infinite b -> Infinite b
deleteBy a -> b -> Bool
eq))
union :: Eq a => [a] -> Infinite a -> Infinite a
union :: forall a. Eq a => [a] -> Infinite a -> Infinite a
union = (a -> a -> Bool) -> [a] -> Infinite a -> Infinite a
forall a. (a -> a -> Bool) -> [a] -> Infinite a -> Infinite a
unionBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
unionBy :: (a -> a -> Bool) -> [a] -> Infinite a -> Infinite a
unionBy :: forall a. (a -> a -> Bool) -> [a] -> Infinite a -> Infinite a
unionBy a -> a -> Bool
eq [a]
xs Infinite a
ys = [a]
xs [a] -> Infinite a -> Infinite a
forall a. [a] -> Infinite a -> Infinite a
`prependList` (Infinite a -> a -> Infinite a) -> Infinite a -> [a] -> Infinite a
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl ((a -> Infinite a -> Infinite a) -> Infinite a -> a -> Infinite a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> a -> Bool) -> a -> Infinite a -> Infinite a
forall a b. (a -> b -> Bool) -> a -> Infinite b -> Infinite b
deleteBy a -> a -> Bool
eq)) ((a -> a -> Bool) -> Infinite a -> Infinite a
forall a. (a -> a -> Bool) -> Infinite a -> Infinite a
nubBy a -> a -> Bool
eq Infinite a
ys) [a]
xs
insert :: Ord a => a -> Infinite a -> Infinite a
insert :: forall a. Ord a => a -> Infinite a -> Infinite a
insert = (a -> a -> Ordering) -> a -> Infinite a -> Infinite a
forall a. (a -> a -> Ordering) -> a -> Infinite a -> Infinite a
insertBy a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
insertBy :: (a -> a -> Ordering) -> a -> Infinite a -> Infinite a
insertBy :: forall a. (a -> a -> Ordering) -> a -> Infinite a -> Infinite a
insertBy a -> a -> Ordering
cmp a
x = (a -> Infinite a -> Infinite a -> Infinite a)
-> Infinite a -> Infinite a
forall a b. (a -> Infinite a -> b -> b) -> Infinite a -> b
para (\a
y Infinite a
ys Infinite a
acc -> case a -> a -> Ordering
cmp a
x a
y of Ordering
GT -> a
y a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
acc; Ordering
_ -> a
x a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< a
y a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
:< Infinite a
ys)
intersect :: Eq a => Infinite a -> [a] -> Infinite a
intersect :: forall a. Eq a => Infinite a -> [a] -> Infinite a
intersect = (a -> a -> Bool) -> Infinite a -> [a] -> Infinite a
forall a b. (a -> b -> Bool) -> Infinite a -> [b] -> Infinite a
intersectBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
intersectBy :: (a -> b -> Bool) -> Infinite a -> [b] -> Infinite a
intersectBy :: forall a b. (a -> b -> Bool) -> Infinite a -> [b] -> Infinite a
intersectBy a -> b -> Bool
eq Infinite a
xs [b]
ys = (a -> Bool) -> Infinite a -> Infinite a
forall a. (a -> Bool) -> Infinite a -> Infinite a
filter (\a
x -> (b -> Bool) -> [b] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
List.any (a -> b -> Bool
eq a
x) [b]
ys) Infinite a
xs
prependList :: [a] -> Infinite a -> Infinite a
prependList :: forall a. [a] -> Infinite a -> Infinite a
prependList = (Infinite a -> [a] -> Infinite a)
-> [a] -> Infinite a -> Infinite a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> Infinite a -> Infinite a) -> Infinite a -> [a] -> Infinite a
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
(:<))
mapMaybe :: (a -> Maybe b) -> Infinite a -> Infinite b
mapMaybe :: forall a b. (a -> Maybe b) -> Infinite a -> Infinite b
mapMaybe = (a -> Infinite b -> Infinite b) -> Infinite a -> Infinite b
forall a b. (a -> b -> b) -> Infinite a -> b
foldr ((a -> Infinite b -> Infinite b) -> Infinite a -> Infinite b)
-> ((a -> Maybe b) -> a -> Infinite b -> Infinite b)
-> (a -> Maybe b)
-> Infinite a
-> Infinite b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Infinite b -> Infinite b)
-> (b -> Infinite b -> Infinite b)
-> Maybe b
-> Infinite b
-> Infinite b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Infinite b -> Infinite b
forall a. a -> a
id b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
(:<) (Maybe b -> Infinite b -> Infinite b)
-> (a -> Maybe b) -> a -> Infinite b -> Infinite b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)
catMaybes :: Infinite (Maybe a) -> Infinite a
catMaybes :: forall a. Infinite (Maybe a) -> Infinite a
catMaybes = (Maybe a -> Infinite a -> Infinite a)
-> Infinite (Maybe a) -> Infinite a
forall a b. (a -> b -> b) -> Infinite a -> b
foldr ((Infinite a -> Infinite a)
-> (a -> Infinite a -> Infinite a)
-> Maybe a
-> Infinite a
-> Infinite a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Infinite a -> Infinite a
forall a. a -> a
id a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
(:<))
mapEither :: (a -> Either b c) -> Infinite a -> (Infinite b, Infinite c)
mapEither :: forall a b c.
(a -> Either b c) -> Infinite a -> (Infinite b, Infinite c)
mapEither = (a -> (Infinite b, Infinite c) -> (Infinite b, Infinite c))
-> Infinite a -> (Infinite b, Infinite c)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr ((a -> (Infinite b, Infinite c) -> (Infinite b, Infinite c))
-> Infinite a -> (Infinite b, Infinite c))
-> ((a -> Either b c)
-> a -> (Infinite b, Infinite c) -> (Infinite b, Infinite c))
-> (a -> Either b c)
-> Infinite a
-> (Infinite b, Infinite c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((b -> (Infinite b, Infinite c) -> (Infinite b, Infinite c))
-> (c -> (Infinite b, Infinite c) -> (Infinite b, Infinite c))
-> Either b c
-> (Infinite b, Infinite c)
-> (Infinite b, Infinite c)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((Infinite b -> Infinite b)
-> (Infinite b, Infinite c) -> (Infinite b, Infinite c)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ((Infinite b -> Infinite b)
-> (Infinite b, Infinite c) -> (Infinite b, Infinite c))
-> (b -> Infinite b -> Infinite b)
-> b
-> (Infinite b, Infinite c)
-> (Infinite b, Infinite c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
(:<)) ((Infinite c -> Infinite c)
-> (Infinite b, Infinite c) -> (Infinite b, Infinite c)
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ((Infinite c -> Infinite c)
-> (Infinite b, Infinite c) -> (Infinite b, Infinite c))
-> (c -> Infinite c -> Infinite c)
-> c
-> (Infinite b, Infinite c)
-> (Infinite b, Infinite c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> Infinite c -> Infinite c
forall a. a -> Infinite a -> Infinite a
(:<)) (Either b c
-> (Infinite b, Infinite c) -> (Infinite b, Infinite c))
-> (a -> Either b c)
-> a
-> (Infinite b, Infinite c)
-> (Infinite b, Infinite c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)
partitionEithers :: Infinite (Either a b) -> (Infinite a, Infinite b)
partitionEithers :: forall a b. Infinite (Either a b) -> (Infinite a, Infinite b)
partitionEithers = (Either a b
-> (Infinite a, Infinite b) -> (Infinite a, Infinite b))
-> Infinite (Either a b) -> (Infinite a, Infinite b)
forall a b. (a -> b -> b) -> Infinite a -> b
foldr ((a -> (Infinite a, Infinite b) -> (Infinite a, Infinite b))
-> (b -> (Infinite a, Infinite b) -> (Infinite a, Infinite b))
-> Either a b
-> (Infinite a, Infinite b)
-> (Infinite a, Infinite b)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((Infinite a -> Infinite a)
-> (Infinite a, Infinite b) -> (Infinite a, Infinite b)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ((Infinite a -> Infinite a)
-> (Infinite a, Infinite b) -> (Infinite a, Infinite b))
-> (a -> Infinite a -> Infinite a)
-> a
-> (Infinite a, Infinite b)
-> (Infinite a, Infinite b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Infinite a -> Infinite a
forall a. a -> Infinite a -> Infinite a
(:<)) ((Infinite b -> Infinite b)
-> (Infinite a, Infinite b) -> (Infinite a, Infinite b)
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ((Infinite b -> Infinite b)
-> (Infinite a, Infinite b) -> (Infinite a, Infinite b))
-> (b -> Infinite b -> Infinite b)
-> b
-> (Infinite a, Infinite b)
-> (Infinite a, Infinite b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Infinite b -> Infinite b
forall a. a -> Infinite a -> Infinite a
(:<)))
traverse_ :: Applicative f => (a -> f ()) -> Infinite a -> f Void
traverse_ :: forall (f :: * -> *) a.
Applicative f =>
(a -> f ()) -> Infinite a -> f Void
traverse_ = (a -> f Void -> f Void) -> Infinite a -> f Void
forall a b. (a -> b -> b) -> Infinite a -> b
foldr ((a -> f Void -> f Void) -> Infinite a -> f Void)
-> ((a -> f ()) -> a -> f Void -> f Void)
-> (a -> f ())
-> Infinite a
-> f Void
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f () -> f Void -> f Void
forall a b. f a -> f b -> f b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) (f () -> f Void -> f Void) -> (a -> f ()) -> a -> f Void -> f Void
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)
for_ :: Applicative f => Infinite a -> (a -> f ()) -> f Void
for_ :: forall (f :: * -> *) a.
Applicative f =>
Infinite a -> (a -> f ()) -> f Void
for_ = ((a -> f ()) -> Infinite a -> f Void)
-> Infinite a -> (a -> f ()) -> f Void
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> f ()) -> Infinite a -> f Void
forall (f :: * -> *) a.
Applicative f =>
(a -> f ()) -> Infinite a -> f Void
traverse_