| 35 | | |
| 36 | | getMapIndex :: Int -> Maybe a -> Eval (IntMap a) -> Maybe (Eval b) -> Eval a |
| 37 | | getMapIndex idx def doList _ | idx < 0 = do |
| 38 | | -- first, check if the list is at least abs(idx) long. |
| 39 | | list <- doList |
| 40 | | if IntMap.member (abs (idx+1)) list |
| 41 | | then return . fromJust |
| 42 | | $ IntMap.lookup (idx `mod` (IntMap.size list)) list |
| 43 | | else errIndex def idx |
| 44 | | -- now we are all positive; either extend or return |
| 45 | | getMapIndex idx def doList ext = do |
| 46 | | list <- doList |
| 47 | | case IntMap.lookup idx list of |
| 48 | | Just a -> return a |
| 49 | | Nothing -> case ext of |
| 50 | | Just doExt -> do { doExt ; getMapIndex idx def doList Nothing } |
| 51 | | Nothing -> errIndex def idx |