{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeFamilies #-}
module Data.List.NonEmpty (
NonEmpty(..)
, map
, intersperse
, scanl
, scanr
, scanl1
, scanr1
, transpose
, sortBy
, sortWith
, length
, head
, tail
, last
, init
, (<|), cons
, uncons
, unfoldr
, sort
, reverse
, inits
, tails
, iterate
, repeat
, cycle
, unfold
, insert
, some1
, take
, drop
, splitAt
, takeWhile
, dropWhile
, span
, break
, filter
, partition
, group
, groupBy
, groupWith
, groupAllWith
, group1
, groupBy1
, groupWith1
, groupAllWith1
, isPrefixOf
, nub
, nubBy
, (!!)
, zip
, zipWith
, unzip
, fromList
, toList
, nonEmpty
, xor
) where
import Prelude hiding (break, cycle, drop, dropWhile,
filter, foldl, foldr, head, init, iterate,
last, length, map, repeat, reverse,
scanl, scanl1, scanr, scanr1, span,
splitAt, tail, take, takeWhile,
unzip, zip, zipWith, (!!))
import qualified Prelude
import Control.Applicative (Applicative (..), Alternative (many))
import Data.Foldable hiding (length, toList)
import qualified Data.Foldable as Foldable
import Data.Function (on)
import qualified Data.List as List
import Data.Ord (comparing)
import GHC.Base (NonEmpty(..))
infixr 5 <|
length :: NonEmpty a -> Int
length :: NonEmpty a -> Int
length (_ :| xs :: [a]
xs) = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length [a]
xs
xor :: NonEmpty Bool -> Bool
xor :: NonEmpty Bool -> Bool
xor (x :: Bool
x :| xs :: [Bool]
xs) = (Bool -> Bool -> Bool) -> Bool -> [Bool] -> Bool
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Bool -> Bool -> Bool
xor' Bool
x [Bool]
xs
where xor' :: Bool -> Bool -> Bool
xor' True y :: Bool
y = Bool -> Bool
not Bool
y
xor' False y :: Bool
y = Bool
y
unfold :: (a -> (b, Maybe a)) -> a -> NonEmpty b
unfold :: (a -> (b, Maybe a)) -> a -> NonEmpty b
unfold f :: a -> (b, Maybe a)
f a :: a
a = case a -> (b, Maybe a)
f a
a of
(b :: b
b, Nothing) -> b
b b -> [b] -> NonEmpty b
forall a. a -> [a] -> NonEmpty a
:| []
(b :: b
b, Just c :: a
c) -> b
b b -> NonEmpty b -> NonEmpty b
forall a. a -> NonEmpty a -> NonEmpty a
<| (a -> (b, Maybe a)) -> a -> NonEmpty b
forall a b. (a -> (b, Maybe a)) -> a -> NonEmpty b
unfold a -> (b, Maybe a)
f a
c
{-# DEPRECATED unfold "Use unfoldr" #-}
nonEmpty :: [a] -> Maybe (NonEmpty a)
nonEmpty :: [a] -> Maybe (NonEmpty a)
nonEmpty [] = Maybe (NonEmpty a)
forall a. Maybe a
Nothing
nonEmpty (a :: a
a:as :: [a]
as) = NonEmpty a -> Maybe (NonEmpty a)
forall a. a -> Maybe a
Just (a
a a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
as)
uncons :: NonEmpty a -> (a, Maybe (NonEmpty a))
uncons :: NonEmpty a -> (a, Maybe (NonEmpty a))
uncons ~(a :: a
a :| as :: [a]
as) = (a
a, [a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty [a]
as)
unfoldr :: (a -> (b, Maybe a)) -> a -> NonEmpty b
unfoldr :: (a -> (b, Maybe a)) -> a -> NonEmpty b
unfoldr f :: a -> (b, Maybe a)
f a :: a
a = case a -> (b, Maybe a)
f a
a of
(b :: b
b, mc :: Maybe a
mc) -> b
b b -> [b] -> NonEmpty b
forall a. a -> [a] -> NonEmpty a
:| [b] -> (a -> [b]) -> Maybe a -> [b]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] a -> [b]
go Maybe a
mc
where
go :: a -> [b]
go c :: a
c = case a -> (b, Maybe a)
f a
c of
(d :: b
d, me :: Maybe a
me) -> b
d b -> [b] -> [b]
forall a. a -> [a] -> [a]
: [b] -> (a -> [b]) -> Maybe a -> [b]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] a -> [b]
go Maybe a
me
head :: NonEmpty a -> a
head :: NonEmpty a -> a
head ~(a :: a
a :| _) = a
a
tail :: NonEmpty a -> [a]
tail :: NonEmpty a -> [a]
tail ~(_ :| as :: [a]
as) = [a]
as
last :: NonEmpty a -> a
last :: NonEmpty a -> a
last ~(a :: a
a :| as :: [a]
as) = [a] -> a
forall a. [a] -> a
List.last (a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
as)
init :: NonEmpty a -> [a]
init :: NonEmpty a -> [a]
init ~(a :: a
a :| as :: [a]
as) = [a] -> [a]
forall a. [a] -> [a]
List.init (a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
as)
(<|) :: a -> NonEmpty a -> NonEmpty a
a :: a
a <| :: a -> NonEmpty a -> NonEmpty a
<| ~(b :: a
b :| bs :: [a]
bs) = a
a a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| a
b a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
bs
cons :: a -> NonEmpty a -> NonEmpty a
cons :: a -> NonEmpty a -> NonEmpty a
cons = a -> NonEmpty a -> NonEmpty a
forall a. a -> NonEmpty a -> NonEmpty a
(<|)
sort :: Ord a => NonEmpty a -> NonEmpty a
sort :: NonEmpty a -> NonEmpty a
sort = ([a] -> [a]) -> NonEmpty a -> NonEmpty a
forall (f :: * -> *) a b.
Foldable f =>
([a] -> [b]) -> f a -> NonEmpty b
lift [a] -> [a]
forall a. Ord a => [a] -> [a]
List.sort
fromList :: [a] -> NonEmpty a
fromList :: [a] -> NonEmpty a
fromList (a :: a
a:as :: [a]
as) = a
a a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
as
fromList [] = [Char] -> NonEmpty a
forall a. [Char] -> a
errorWithoutStackTrace "NonEmpty.fromList: empty list"
toList :: NonEmpty a -> [a]
toList :: NonEmpty a -> [a]
toList ~(a :: a
a :| as :: [a]
as) = a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
as
lift :: Foldable f => ([a] -> [b]) -> f a -> NonEmpty b
lift :: ([a] -> [b]) -> f a -> NonEmpty b
lift f :: [a] -> [b]
f = [b] -> NonEmpty b
forall a. [a] -> NonEmpty a
fromList ([b] -> NonEmpty b) -> (f a -> [b]) -> f a -> NonEmpty b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [b]
f ([a] -> [b]) -> (f a -> [a]) -> f a -> [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
map :: (a -> b) -> NonEmpty a -> NonEmpty b
map :: (a -> b) -> NonEmpty a -> NonEmpty b
map f :: a -> b
f ~(a :: a
a :| as :: [a]
as) = a -> b
f a
a b -> [b] -> NonEmpty b
forall a. a -> [a] -> NonEmpty a
:| (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f [a]
as
inits :: Foldable f => f a -> NonEmpty [a]
inits :: f a -> NonEmpty [a]
inits = [[a]] -> NonEmpty [a]
forall a. [a] -> NonEmpty a
fromList ([[a]] -> NonEmpty [a]) -> (f a -> [[a]]) -> f a -> NonEmpty [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [[a]]
forall a. [a] -> [[a]]
List.inits ([a] -> [[a]]) -> (f a -> [a]) -> f a -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
tails :: Foldable f => f a -> NonEmpty [a]
tails :: f a -> NonEmpty [a]
tails = [[a]] -> NonEmpty [a]
forall a. [a] -> NonEmpty a
fromList ([[a]] -> NonEmpty [a]) -> (f a -> [[a]]) -> f a -> NonEmpty [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [[a]]
forall a. [a] -> [[a]]
List.tails ([a] -> [[a]]) -> (f a -> [a]) -> f a -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
insert :: (Foldable f, Ord a) => a -> f a -> NonEmpty a
insert :: a -> f a -> NonEmpty a
insert a :: a
a = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
fromList ([a] -> NonEmpty a) -> (f a -> [a]) -> f a -> NonEmpty a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a] -> [a]
forall a. Ord a => a -> [a] -> [a]
List.insert a
a ([a] -> [a]) -> (f a -> [a]) -> f a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
some1 :: Alternative f => f a -> f (NonEmpty a)
some1 :: f a -> f (NonEmpty a)
some1 x :: f a
x = (a -> [a] -> NonEmpty a) -> f a -> f [a] -> f (NonEmpty a)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
(:|) f a
x (f a -> f [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many f a
x)
scanl :: Foldable f => (b -> a -> b) -> b -> f a -> NonEmpty b
scanl :: (b -> a -> b) -> b -> f a -> NonEmpty b
scanl f :: b -> a -> b
f z :: b
z = [b] -> NonEmpty b
forall a. [a] -> NonEmpty a
fromList ([b] -> NonEmpty b) -> (f a -> [b]) -> f a -> NonEmpty b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> a -> b) -> b -> [a] -> [b]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
List.scanl b -> a -> b
f b
z ([a] -> [b]) -> (f a -> [a]) -> f a -> [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
scanr :: Foldable f => (a -> b -> b) -> b -> f a -> NonEmpty b
scanr :: (a -> b -> b) -> b -> f a -> NonEmpty b
scanr f :: a -> b -> b
f z :: b
z = [b] -> NonEmpty b
forall a. [a] -> NonEmpty a
fromList ([b] -> NonEmpty b) -> (f a -> [b]) -> f a -> NonEmpty b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b -> b) -> b -> [a] -> [b]
forall a b. (a -> b -> b) -> b -> [a] -> [b]
List.scanr a -> b -> b
f b
z ([a] -> [b]) -> (f a -> [a]) -> f a -> [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
scanl1 f :: a -> a -> a
f ~(a :: a
a :| as :: [a]
as) = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
fromList ((a -> a -> a) -> a -> [a] -> [a]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
List.scanl a -> a -> a
f a
a [a]
as)
scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
scanr1 f :: a -> a -> a
f ~(a :: a
a :| as :: [a]
as) = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
fromList ((a -> a -> a) -> [a] -> [a]
forall a. (a -> a -> a) -> [a] -> [a]
List.scanr1 a -> a -> a
f (a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
as))
intersperse :: a -> NonEmpty a -> NonEmpty a
intersperse :: a -> NonEmpty a -> NonEmpty a
intersperse a :: a
a ~(b :: a
b :| bs :: [a]
bs) = a
b a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| case [a]
bs of
[] -> []
_ -> a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a -> [a] -> [a]
forall a. a -> [a] -> [a]
List.intersperse a
a [a]
bs
iterate :: (a -> a) -> a -> NonEmpty a
iterate :: (a -> a) -> a -> NonEmpty a
iterate f :: a -> a
f a :: a
a = a
a a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| (a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
List.iterate a -> a
f (a -> a
f a
a)
cycle :: NonEmpty a -> NonEmpty a
cycle :: NonEmpty a -> NonEmpty a
cycle = [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
fromList ([a] -> NonEmpty a)
-> (NonEmpty a -> [a]) -> NonEmpty a -> NonEmpty a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
List.cycle ([a] -> [a]) -> (NonEmpty a -> [a]) -> NonEmpty a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
reverse :: NonEmpty a -> NonEmpty a
reverse :: NonEmpty a -> NonEmpty a
reverse = ([a] -> [a]) -> NonEmpty a -> NonEmpty a
forall (f :: * -> *) a b.
Foldable f =>
([a] -> [b]) -> f a -> NonEmpty b
lift [a] -> [a]
forall a. [a] -> [a]
List.reverse
repeat :: a -> NonEmpty a
repeat :: a -> NonEmpty a
repeat a :: a
a = a
a a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| a -> [a]
forall a. a -> [a]
List.repeat a
a
take :: Int -> NonEmpty a -> [a]
take :: Int -> NonEmpty a -> [a]
take n :: Int
n = Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
List.take Int
n ([a] -> [a]) -> (NonEmpty a -> [a]) -> NonEmpty a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
drop :: Int -> NonEmpty a -> [a]
drop :: Int -> NonEmpty a -> [a]
drop n :: Int
n = Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
List.drop Int
n ([a] -> [a]) -> (NonEmpty a -> [a]) -> NonEmpty a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
splitAt :: Int -> NonEmpty a -> ([a],[a])
splitAt :: Int -> NonEmpty a -> ([a], [a])
splitAt n :: Int
n = Int -> [a] -> ([a], [a])
forall a. Int -> [a] -> ([a], [a])
List.splitAt Int
n ([a] -> ([a], [a]))
-> (NonEmpty a -> [a]) -> NonEmpty a -> ([a], [a])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
takeWhile :: (a -> Bool) -> NonEmpty a -> [a]
takeWhile :: (a -> Bool) -> NonEmpty a -> [a]
takeWhile p :: a -> Bool
p = (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
List.takeWhile a -> Bool
p ([a] -> [a]) -> (NonEmpty a -> [a]) -> NonEmpty a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
dropWhile :: (a -> Bool) -> NonEmpty a -> [a]
dropWhile :: (a -> Bool) -> NonEmpty a -> [a]
dropWhile p :: a -> Bool
p = (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
List.dropWhile a -> Bool
p ([a] -> [a]) -> (NonEmpty a -> [a]) -> NonEmpty a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
span :: (a -> Bool) -> NonEmpty a -> ([a], [a])
span :: (a -> Bool) -> NonEmpty a -> ([a], [a])
span p :: a -> Bool
p = (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
List.span a -> Bool
p ([a] -> ([a], [a]))
-> (NonEmpty a -> [a]) -> NonEmpty a -> ([a], [a])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
break :: (a -> Bool) -> NonEmpty a -> ([a], [a])
break :: (a -> Bool) -> NonEmpty a -> ([a], [a])
break p :: a -> Bool
p = (a -> Bool) -> NonEmpty a -> ([a], [a])
forall a. (a -> Bool) -> NonEmpty a -> ([a], [a])
span (Bool -> Bool
not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
p)
filter :: (a -> Bool) -> NonEmpty a -> [a]
filter :: (a -> Bool) -> NonEmpty a -> [a]
filter p :: a -> Bool
p = (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
List.filter a -> Bool
p ([a] -> [a]) -> (NonEmpty a -> [a]) -> NonEmpty a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
partition :: (a -> Bool) -> NonEmpty a -> ([a], [a])
partition :: (a -> Bool) -> NonEmpty a -> ([a], [a])
partition p :: a -> Bool
p = (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
List.partition a -> Bool
p ([a] -> ([a], [a]))
-> (NonEmpty a -> [a]) -> NonEmpty a -> ([a], [a])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
group :: (Foldable f, Eq a) => f a -> [NonEmpty a]
group :: f a -> [NonEmpty a]
group = (a -> a -> Bool) -> f a -> [NonEmpty a]
forall (f :: * -> *) a.
Foldable f =>
(a -> a -> Bool) -> f a -> [NonEmpty a]
groupBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
groupBy :: Foldable f => (a -> a -> Bool) -> f a -> [NonEmpty a]
groupBy :: (a -> a -> Bool) -> f a -> [NonEmpty a]
groupBy eq0 :: a -> a -> Bool
eq0 = (a -> a -> Bool) -> [a] -> [NonEmpty a]
forall a. (a -> a -> Bool) -> [a] -> [NonEmpty a]
go a -> a -> Bool
eq0 ([a] -> [NonEmpty a]) -> (f a -> [a]) -> f a -> [NonEmpty a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
where
go :: (a -> a -> Bool) -> [a] -> [NonEmpty a]
go _ [] = []
go eq :: a -> a -> Bool
eq (x :: a
x : xs :: [a]
xs) = (a
x a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
ys) NonEmpty a -> [NonEmpty a] -> [NonEmpty a]
forall a. a -> [a] -> [a]
: (a -> a -> Bool) -> [a] -> [NonEmpty a]
forall (f :: * -> *) a.
Foldable f =>
(a -> a -> Bool) -> f a -> [NonEmpty a]
groupBy a -> a -> Bool
eq [a]
zs
where (ys :: [a]
ys, zs :: [a]
zs) = (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
List.span (a -> a -> Bool
eq a
x) [a]
xs
groupWith :: (Foldable f, Eq b) => (a -> b) -> f a -> [NonEmpty a]
groupWith :: (a -> b) -> f a -> [NonEmpty a]
groupWith f :: a -> b
f = (a -> a -> Bool) -> f a -> [NonEmpty a]
forall (f :: * -> *) a.
Foldable f =>
(a -> a -> Bool) -> f a -> [NonEmpty a]
groupBy (b -> b -> Bool
forall a. Eq a => a -> a -> Bool
(==) (b -> b -> Bool) -> (a -> b) -> a -> a -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` a -> b
f)
groupAllWith :: (Ord b) => (a -> b) -> [a] -> [NonEmpty a]
groupAllWith :: (a -> b) -> [a] -> [NonEmpty a]
groupAllWith f :: a -> b
f = (a -> b) -> [a] -> [NonEmpty a]
forall (f :: * -> *) b a.
(Foldable f, Eq b) =>
(a -> b) -> f a -> [NonEmpty a]
groupWith a -> b
f ([a] -> [NonEmpty a]) -> ([a] -> [a]) -> [a] -> [NonEmpty a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> Ordering) -> [a] -> [a]
forall a. (a -> a -> Ordering) -> [a] -> [a]
List.sortBy (b -> b -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (b -> b -> Ordering) -> (a -> b) -> a -> a -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` a -> b
f)
group1 :: Eq a => NonEmpty a -> NonEmpty (NonEmpty a)
group1 :: NonEmpty a -> NonEmpty (NonEmpty a)
group1 = (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a)
forall a. (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a)
groupBy1 a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
groupBy1 :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a)
groupBy1 :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a)
groupBy1 eq :: a -> a -> Bool
eq (x :: a
x :| xs :: [a]
xs) = (a
x a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
ys) NonEmpty a -> [NonEmpty a] -> NonEmpty (NonEmpty a)
forall a. a -> [a] -> NonEmpty a
:| (a -> a -> Bool) -> [a] -> [NonEmpty a]
forall (f :: * -> *) a.
Foldable f =>
(a -> a -> Bool) -> f a -> [NonEmpty a]
groupBy a -> a -> Bool
eq [a]
zs
where (ys :: [a]
ys, zs :: [a]
zs) = (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
List.span (a -> a -> Bool
eq a
x) [a]
xs
groupWith1 :: (Eq b) => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
groupWith1 :: (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
groupWith1 f :: a -> b
f = (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a)
forall a. (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a)
groupBy1 (b -> b -> Bool
forall a. Eq a => a -> a -> Bool
(==) (b -> b -> Bool) -> (a -> b) -> a -> a -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` a -> b
f)
groupAllWith1 :: (Ord b) => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
groupAllWith1 :: (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
groupAllWith1 f :: a -> b
f = (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
forall b a. Eq b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
groupWith1 a -> b
f (NonEmpty a -> NonEmpty (NonEmpty a))
-> (NonEmpty a -> NonEmpty a)
-> NonEmpty a
-> NonEmpty (NonEmpty a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> NonEmpty a -> NonEmpty a
forall o a. Ord o => (a -> o) -> NonEmpty a -> NonEmpty a
sortWith a -> b
f
isPrefixOf :: Eq a => [a] -> NonEmpty a -> Bool
isPrefixOf :: [a] -> NonEmpty a -> Bool
isPrefixOf [] _ = Bool
True
isPrefixOf (y :: a
y:ys :: [a]
ys) (x :: a
x :| xs :: [a]
xs) = (a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x) Bool -> Bool -> Bool
&& [a] -> [a] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
List.isPrefixOf [a]
ys [a]
xs
(!!) :: NonEmpty a -> Int -> a
!! :: NonEmpty a -> Int -> a
(!!) ~(x :: a
x :| xs :: [a]
xs) n :: Int
n
| Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0 = a
x
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = [a]
xs [a] -> Int -> a
forall a. [a] -> Int -> a
List.!! (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1)
| Bool
otherwise = [Char] -> a
forall a. [Char] -> a
errorWithoutStackTrace "NonEmpty.!! negative argument"
infixl 9 !!
zip :: NonEmpty a -> NonEmpty b -> NonEmpty (a,b)
zip :: NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
zip ~(x :: a
x :| xs :: [a]
xs) ~(y :: b
y :| ys :: [b]
ys) = (a
x, b
y) (a, b) -> [(a, b)] -> NonEmpty (a, b)
forall a. a -> [a] -> NonEmpty a
:| [a] -> [b] -> [(a, b)]
forall a b. [a] -> [b] -> [(a, b)]
List.zip [a]
xs [b]
ys
zipWith :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c
zipWith :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c
zipWith f :: a -> b -> c
f ~(x :: a
x :| xs :: [a]
xs) ~(y :: b
y :| ys :: [b]
ys) = a -> b -> c
f a
x b
y c -> [c] -> NonEmpty c
forall a. a -> [a] -> NonEmpty a
:| (a -> b -> c) -> [a] -> [b] -> [c]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
List.zipWith a -> b -> c
f [a]
xs [b]
ys
unzip :: Functor f => f (a,b) -> (f a, f b)
unzip :: f (a, b) -> (f a, f b)
unzip xs :: f (a, b)
xs = ((a, b) -> a
forall a b. (a, b) -> a
fst ((a, b) -> a) -> f (a, b) -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (a, b)
xs, (a, b) -> b
forall a b. (a, b) -> b
snd ((a, b) -> b) -> f (a, b) -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (a, b)
xs)
nub :: Eq a => NonEmpty a -> NonEmpty a
nub :: NonEmpty a -> NonEmpty a
nub = (a -> a -> Bool) -> NonEmpty a -> NonEmpty a
forall a. (a -> a -> Bool) -> NonEmpty a -> NonEmpty a
nubBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
nubBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a
nubBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a
nubBy eq :: a -> a -> Bool
eq (a :: a
a :| as :: [a]
as) = a
a a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| (a -> a -> Bool) -> [a] -> [a]
forall a. (a -> a -> Bool) -> [a] -> [a]
List.nubBy a -> a -> Bool
eq ((a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
List.filter (\b :: a
b -> Bool -> Bool
not (a -> a -> Bool
eq a
a a
b)) [a]
as)
transpose :: NonEmpty (NonEmpty a) -> NonEmpty (NonEmpty a)
transpose :: NonEmpty (NonEmpty a) -> NonEmpty (NonEmpty a)
transpose = ([a] -> NonEmpty a) -> NonEmpty [a] -> NonEmpty (NonEmpty a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [a] -> NonEmpty a
forall a. [a] -> NonEmpty a
fromList
(NonEmpty [a] -> NonEmpty (NonEmpty a))
-> (NonEmpty (NonEmpty a) -> NonEmpty [a])
-> NonEmpty (NonEmpty a)
-> NonEmpty (NonEmpty a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[a]] -> NonEmpty [a]
forall a. [a] -> NonEmpty a
fromList ([[a]] -> NonEmpty [a])
-> (NonEmpty (NonEmpty a) -> [[a]])
-> NonEmpty (NonEmpty a)
-> NonEmpty [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[a]] -> [[a]]
forall a. [[a]] -> [[a]]
List.transpose ([[a]] -> [[a]])
-> (NonEmpty (NonEmpty a) -> [[a]])
-> NonEmpty (NonEmpty a)
-> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty [a] -> [[a]]
forall a. NonEmpty a -> [a]
toList
(NonEmpty [a] -> [[a]])
-> (NonEmpty (NonEmpty a) -> NonEmpty [a])
-> NonEmpty (NonEmpty a)
-> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NonEmpty a -> [a]) -> NonEmpty (NonEmpty a) -> NonEmpty [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
toList
sortBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a
sortBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a
sortBy f :: a -> a -> Ordering
f = ([a] -> [a]) -> NonEmpty a -> NonEmpty a
forall (f :: * -> *) a b.
Foldable f =>
([a] -> [b]) -> f a -> NonEmpty b
lift ((a -> a -> Ordering) -> [a] -> [a]
forall a. (a -> a -> Ordering) -> [a] -> [a]
List.sortBy a -> a -> Ordering
f)
sortWith :: Ord o => (a -> o) -> NonEmpty a -> NonEmpty a
sortWith :: (a -> o) -> NonEmpty a -> NonEmpty a
sortWith = (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a
forall a. (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a
sortBy ((a -> a -> Ordering) -> NonEmpty a -> NonEmpty a)
-> ((a -> o) -> a -> a -> Ordering)
-> (a -> o)
-> NonEmpty a
-> NonEmpty a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> o) -> a -> a -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing