Skip to content

Commit 23bb381

Browse files
buzdengallais
authored andcommitted
[ cleanup ] Small code cleanup, less mutual block and one \case use
1 parent 940f588 commit 23bb381

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

libs/base/Data/Either.idr

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,16 @@ isRight (Right _) = True
3434
--------------------------------------------------------------------------------
3535
-- Grouping values
3636

37-
mutual
38-
39-
||| Compress the list of Lefts and Rights by accumulating
40-
||| all of the lefts and rights into non-empty blocks.
41-
export
42-
compress : List (Either a b) -> List (Either (List1 a) (List1 b))
43-
compress [] = []
44-
compress (Left a :: abs) = compressLefts (singleton a) abs
45-
compress (Right b :: abs) = compressRights (singleton b) abs
46-
37+
||| Compress the list of Lefts and Rights by accumulating
38+
||| all of the lefts and rights into non-empty blocks.
39+
export
40+
compress : List (Either a b) -> List (Either (List1 a) (List1 b))
41+
compress [] = []
42+
compress (Left x :: abs) = compressLefts (singleton x) abs where
4743
compressLefts : List1 a -> List (Either a b) -> List (Either (List1 a) (List1 b))
4844
compressLefts acc (Left a :: abs) = compressLefts (cons a acc) abs
4945
compressLefts acc abs = Left (reverse acc) :: compress abs
50-
46+
compress (Right y :: abs) = compressRights (singleton y) abs where
5147
compressRights : List1 b -> List (Either a b) -> List (Either (List1 a) (List1 b))
5248
compressRights acc (Right b :: abs) = compressRights (cons b acc) abs
5349
compressRights acc abs = Right (reverse acc) :: compress abs
@@ -56,8 +52,8 @@ mutual
5652
||| right inverse because nothing forces the input to be maximally compressed!
5753
export
5854
decompress : List (Either (List1 a) (List1 b)) -> List (Either a b)
59-
decompress = concatMap $ \ abs => case abs of
60-
Left as => map Left $ forget as
55+
decompress = concatMap $ \case
56+
Left as => map Left $ forget as
6157
Right bs => map Right $ forget bs
6258

6359
||| Keep the payloads of all Left constructors in a list of Eithers

0 commit comments

Comments
 (0)