18import Control.Monad (liftM)
26newtype ZeroBased = ZeroBased Int
35unsafe :: Int -> ZeroBased
40 error "Compiler error, unacceptable call of Index.unsafe"
44next :: ZeroBased -> ZeroBased
53toZeroBased :: ZeroBased -> Int
54toZeroBased (ZeroBased index) =
58toOneBased :: ZeroBased -> Int
59toOneBased (ZeroBased index) =
67{-# INLINE indexedMap #-}
68indexedMap :: (ZeroBased -> a -> b) -> [a] -> [b]
70 zipWith func (map ZeroBased [0 .. length list]) list
73{-# INLINE indexedTraverse #-}
74indexedTraverse :: (Applicative f) => (ZeroBased -> a -> f b) -> [a] -> f [b]
75indexedTraverse func list =
76 sequenceA (indexedMap func list)
79{-# INLINE indexedForA #-}
80indexedForA :: (Applicative f) => [a] -> (ZeroBased -> a -> f b) -> f [b]
81indexedForA list func =
82 sequenceA (indexedMap func list)
86-- VERIFIED/INDEXED ZIP
91 | LengthMismatch Int Int
94indexedZipWith :: (ZeroBased -> a -> b -> c) -> [a] -> [b] -> VerifiedList c
95indexedZipWith func listX listY =
96 indexedZipWithHelp func 0 listX listY []
99indexedZipWithHelp :: (ZeroBased -> a -> b -> c) -> Int -> [a] -> [b] -> [c] -> VerifiedList c
100indexedZipWithHelp func index listX listY revListZ =
101 case (listX, listY) of
103 LengthMatch (reverse revListZ)
106 indexedZipWithHelp func (index + 1) xs ys $
107 func (ZeroBased index) x y : revListZ
110 LengthMismatch (index + length listX) (index + length listY)
113indexedZipWithA :: (Applicative f) => (ZeroBased -> a -> b -> f c) -> [a] -> [b] -> f (VerifiedList c)
114indexedZipWithA func listX listY =
115 case indexedZipWith func listX listY of
117 LengthMatch <$> sequenceA list
119 LengthMismatch x y ->
120 pure (LengthMismatch x y)
127instance Binary ZeroBased where
128 get = liftM ZeroBased get
129 put (ZeroBased n) = put n
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list