diff options
Diffstat (limited to 'src/Utils.hs')
| -rw-r--r-- | src/Utils.hs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Utils.hs b/src/Utils.hs index fe0a9c2..e2c182b 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -113,3 +113,17 @@ evenElems (_:xs) = oddElems xs throwL :: String -> LContext a throwL s = throwError $ LException s + +asPairsM :: [a] -> LContext [(a, a)] +asPairsM [] = return [] +asPairsM (a:b:rest) = do + restPaired <- asPairsM rest + return $ (a, b) : restPaired +asPairsM _ = throwL "odd number of elements to pair up" + +asPairs :: [a] -> [(a, a)] +asPairs [] = [] +asPairs (a:b:rest) = + let restPaired = asPairs rest + in (a, b) : restPaired +asPairs _ = error "odd number of elements to pair up" |
