@@ -34,20 +34,16 @@ isRight (Right _) = True
34
34
-- ------------------------------------------------------------------------------
35
35
-- Grouping values
36
36
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
47
43
compressLefts : List1 a -> List (Either a b) -> List (Either (List1 a) (List1 b))
48
44
compressLefts acc (Left a :: abs ) = compressLefts (cons a acc) abs
49
45
compressLefts acc abs = Left (reverse acc) :: compress abs
50
-
46
+ compress ( Right y :: abs ) = compressRights (singleton y) abs where
51
47
compressRights : List1 b -> List (Either a b) -> List (Either (List1 a) (List1 b))
52
48
compressRights acc (Right b :: abs ) = compressRights (cons b acc) abs
53
49
compressRights acc abs = Right (reverse acc) :: compress abs
56
52
||| right inverse because nothing forces the input to be maximally compressed!
57
53
export
58
54
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
61
57
Right bs => map Right $ forget bs
62
58
63
59
||| Keep the payloads of all Left constructors in a list of Eithers
0 commit comments