diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-09-25 18:00:47 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:21:53 +0200 |
| commit | a5ce95f40188c4525bc98307d09015a5dca93bb3 (patch) | |
| tree | cb364a95ba197eabad7d1e17b95905da9a2ebcd9 /src/Utils.hs | |
| parent | 6314bf6584f98c735f606155a76c809fd6de5d0b (diff) | |
Refactor Lib.hs
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" |
