@@ -0,0 +1,100 @@
44+toOneBased :: ZeroBased -> Int
45+toOneBased (ZeroBased index) =
53+{-# INLINE indexedMap #-}
54+indexedMap :: (ZeroBased -> a -> b) -> [a] -> [b]
55+indexedMap func list =
56+ zipWith func (map ZeroBased [0 .. length list]) list
59+{-# INLINE indexedTraverse #-}
60+indexedTraverse :: (Applicative f) => (ZeroBased -> a -> f b) -> [a] -> f [b]
61+indexedTraverse func list =
62+ sequenceA (indexedMap func list)
66+-- VERIFIED/INDEXED ZIP
71+ | LengthMismatch Int Int
74+indexedZipWith :: (ZeroBased -> a -> b -> c) -> [a] -> [b] -> VerifiedList c
75+indexedZipWith func listX listY =
76+ indexedZipWithHelp func 0 listX listY []
79+indexedZipWithHelp :: (ZeroBased -> a -> b -> c) -> Int -> [a] -> [b] -> [c] -> VerifiedList c
80+indexedZipWithHelp func index listX listY revListZ =
81+ case (listX, listY) of
83+ LengthMatch (reverse revListZ)
86+ indexedZipWithHelp func (index + 1) xs ys $
87+ func (ZeroBased index) x y : revListZ
90+ LengthMismatch (index + length listX) (index + length listY)
93+indexedZipWithA :: (Applicative f) => (ZeroBased -> a -> b -> f c) -> [a] -> [b] -> f (VerifiedList c)
94+indexedZipWithA func listX listY =
95+ case indexedZipWith func listX listY of
97+ LengthMatch <$> sequenceA list
99+ LengthMismatch x y ->
100+ pure (LengthMismatch x y)