    {-# LANGUAGE LambdaCase #-}

    module GHC.Data.List.NonEmpty (module Data.List.NonEmpty, module GHC.Data.List.NonEmpty, toList) where

    import Prelude (Bool, (.))
    import Control.Applicative
    import qualified Control.Monad as List (zipWithM)
    import Data.Foldable (Foldable (toList))
    import Data.List.NonEmpty hiding (toList, unzip)
    import qualified Data.List as List
    import qualified GHC.Data.List as List

    zipWithM :: Applicative f => (a -> b -> f c) -> NonEmpty a -> NonEmpty b -> f (NonEmpty c)
    zipWithM :: forall (f :: * -> *) a b c.
    Applicative f =>
    (a -> b -> f c) -> NonEmpty a -> NonEmpty b -> f (NonEmpty c)
    zipWithM a -> b -> f c
    f (a
    a:|[a]
    as) (b
    b:|[b]
    bs) = (c -> [c] -> NonEmpty c) -> f c -> f [c] -> f (NonEmpty c)
    forall a b c. (a -> b -> c) -> f a -> f b -> f c
    forall (f :: * -> *) a b c.
    Applicative f =>
    (a -> b -> c) -> f a -> f b -> f c
    liftA2 c -> [c] -> NonEmpty c
    forall a. a -> [a] -> NonEmpty a
    (:|) (a -> b -> f c
    f a
    a b
    b) ((a -> b -> f c) -> [a] -> [b] -> f [c]
    forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> m c) -> [a] -> [b] -> m [c]
    List.zipWithM a -> b -> f c
    f [a]
    as [b]
    bs)
    -- Inline to enable fusion of `List.zipWithM`
    -- See Note [Fusion for zipN/zipWithN] in List.hs
    {-# INLINE zipWithM #-}

    unzip :: NonEmpty (a, b) -> (NonEmpty a, NonEmpty b)
    unzip :: forall a b. NonEmpty (a, b) -> (NonEmpty a, NonEmpty b)
    unzip ((a
    a,b
    b):|[(a, b)]
    xs) = (a
    aa -> [a] -> NonEmpty a
    forall a. a -> [a] -> NonEmpty a
    :|[a]
    as, b
    bb -> [b] -> NonEmpty b
    forall a. a -> [a] -> NonEmpty a
    :|[b]
    bs)
      where
        ([a]
    as, [b]
    bs) = [(a, b)] -> ([a], [b])
    forall a b. [(a, b)] -> ([a], [b])
    List.unzip [(a, b)]
    xs

    unzip3 :: NonEmpty (a, b, c) -> (NonEmpty a, NonEmpty b, NonEmpty c)
    unzip3 :: forall a b c.
    NonEmpty (a, b, c) -> (NonEmpty a, NonEmpty b, NonEmpty c)
    unzip3 ((a
    a,b
    b,c
    c):|[(a, b, c)]
    xs) = (a
    aa -> [a] -> NonEmpty a
    forall a. a -> [a] -> NonEmpty a
    :|[a]
    as, b
    bb -> [b] -> NonEmpty b
    forall a. a -> [a] -> NonEmpty a
    :|[b]
    bs, c
    cc -> [c] -> NonEmpty c
    forall a. a -> [a] -> NonEmpty a
    :|[c]
    cs)
      where
        ([a]
    as, [b]
    bs, [c]
    cs) = [(a, b, c)] -> ([a], [b], [c])
    forall a b c. [(a, b, c)] -> ([a], [b], [c])
    List.unzip3 [(a, b, c)]
    xs

    mapAndUnzip :: (a -> (b, c)) -> NonEmpty a -> (NonEmpty b, NonEmpty c)
    mapAndUnzip :: forall a b c.
    (a -> (b, c)) -> NonEmpty a -> (NonEmpty b, NonEmpty c)
    mapAndUnzip a -> (b, c)
    f (a
    x:|[a]
    xs) = (b
    bb -> [b] -> NonEmpty b
    forall a. a -> [a] -> NonEmpty a
    :|[b]
    bs, c
    cc -> [c] -> NonEmpty c
    forall a. a -> [a] -> NonEmpty a
    :|[c]
    cs)
      where
        (b
    b, c
    c) = a -> (b, c)
    f a
    x
        ([b]
    bs, [c]
    cs) = (a -> (b, c)) -> [a] -> ([b], [c])
    forall a b c. (a -> (b, c)) -> [a] -> ([b], [c])
    List.mapAndUnzip a -> (b, c)
    f [a]
    xs

    mapAndUnzip3 :: (a -> (b, c, d)) -> NonEmpty a -> (NonEmpty b, NonEmpty c, NonEmpty d)
    mapAndUnzip3 :: forall a b c d.
    (a -> (b, c, d))
    -> NonEmpty a -> (NonEmpty b, NonEmpty c, NonEmpty d)
    mapAndUnzip3 a -> (b, c, d)
    f (a
    x:|[a]
    xs) = (b
    bb -> [b] -> NonEmpty b
    forall a. a -> [a] -> NonEmpty a
    :|[b]
    bs, c
    cc -> [c] -> NonEmpty c
    forall a. a -> [a] -> NonEmpty a
    :|[c]
    cs, d
    dd -> [d] -> NonEmpty d
    forall a. a -> [a] -> NonEmpty a
    :|[d]
    ds)
      where
        (b
    b, c
    c, d
    d) = a -> (b, c, d)
    f a
    x
        ([b]
    bs, [c]
    cs, [d]
    ds) = (a -> (b, c, d)) -> [a] -> ([b], [c], [d])
    forall a b c d. (a -> (b, c, d)) -> [a] -> ([b], [c], [d])
    List.mapAndUnzip3 a -> (b, c, d)
    f [a]
    xs

    isSingleton :: NonEmpty a -> Bool
    isSingleton :: forall a. NonEmpty a -> Bool
    isSingleton = [a] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    List.null ([a] -> Bool) -> (NonEmpty a -> [a]) -> NonEmpty a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . NonEmpty a -> [a]
    forall a. NonEmpty a -> [a]
    tail