module Data.List.ZipNonEmpty(
ZipNonEmpty,
ne,
zipNe,
usingNe,
usingZne
) where
import Data.List
import Data.Foldable
import Data.List.NonEmpty
import Control.Applicative
newtype ZipNonEmpty a = Z {
ne :: NonEmpty a
} deriving (Eq, Ord)
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 Functor ZipNonEmpty where
fmap = usingNe . fmap
instance Applicative ZipNonEmpty where
pure = zipNe . unsafeToNonEmpty . repeat
f <*> a = let z = toList . ne
in zipNe . unsafeToNonEmpty $ zipWith id (z f) (z a)