module Data.List.ZipNonEmpty(
ZipNonEmpty,
ne,
zipNe,
usingNe,
usingZne
) where
import Data.List
import Data.Semigroup
import Data.Foldable
import Data.Typeable (Typeable)
import Data.Data (Data)
import Data.List.NonEmpty
import Control.Applicative
import Control.Comonad
import Control.Functor.Pointed
import Control.Functor.Zip
newtype ZipNonEmpty a = Z {
ne :: NonEmpty a
} deriving (Eq, Ord, Typeable, Data, Functor, Pointed, Copointed, Zip, Comonad, Semigroup)
zipNe :: NonEmpty a
-> ZipNonEmpty a
zipNe = Z
usingNe :: (NonEmpty a -> NonEmpty b)
-> ZipNonEmpty a
-> ZipNonEmpty b
usingNe = (zipNe .) . (. ne)
usingZne :: (ZipNonEmpty a -> ZipNonEmpty b)
-> NonEmpty a
-> NonEmpty b
usingZne = (ne .) . (. zipNe)
instance (Show a) => Show (ZipNonEmpty a) where
show = show . ne
instance Applicative ZipNonEmpty where
pure = zipNe . unsafeToNonEmpty . repeat
f <*> a = let z = toList . ne
in zipNe . unsafeToNonEmpty $ zipWith id (z f) (z a)