19import Control.Monad (liftM)
27newtype ZeroBased = ZeroBased Int
47next :: ZeroBased -> ZeroBased
56toMachine :: ZeroBased -> Int
57toMachine (ZeroBased index) =
61toHuman :: ZeroBased -> Int
62toHuman (ZeroBased index) =
70{-# INLINE indexedMap #-}
71indexedMap :: (ZeroBased -> a -> b) -> [a] -> [b]
73 zipWith func (map ZeroBased [0 .. length xs]) xs
76{-# INLINE indexedTraverse #-}
77indexedTraverse :: (Applicative f) => (ZeroBased -> a -> f b) -> [a] -> f [b]
78indexedTraverse func xs =
79 sequenceA (indexedMap func xs)
82{-# INLINE indexedForA #-}
83indexedForA :: (Applicative f) => [a] -> (ZeroBased -> a -> f b) -> f [b]
85 sequenceA (indexedMap func xs)
89-- VERIFIED/INDEXED ZIP
94 | LengthMismatch Int Int
97indexedZipWith :: (ZeroBased -> a -> b -> c) -> [a] -> [b] -> VerifiedList c
98indexedZipWith func listX listY =
99 indexedZipWithHelp func 0 listX listY []
102indexedZipWithHelp :: (ZeroBased -> a -> b -> c) -> Int -> [a] -> [b] -> [c] -> VerifiedList c
103indexedZipWithHelp func index listX listY revListZ =
104 case (listX, listY) of
106 LengthMatch (reverse revListZ)
109 indexedZipWithHelp func (index + 1) xs ys $
110 func (ZeroBased index) x y : revListZ
113 LengthMismatch (index + length listX) (index + length listY)
116indexedZipWithA :: (Applicative f) => (ZeroBased -> a -> b -> f c) -> [a] -> [b] -> f (VerifiedList c)
117indexedZipWithA func listX listY =
118 case indexedZipWith func listX listY of
120 LengthMatch <$> sequenceA xs
122 LengthMismatch x y ->
123 pure (LengthMismatch x y)
130instance Binary ZeroBased where
131 get = liftM ZeroBased get
132 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