Skip to content

Commit

Permalink
Improve Data.List.Base (fix #2359; deprecate use of with #2123) (#2366
Browse files Browse the repository at this point in the history
)

* refactor towards `if_then_else_`

* layout

* `let` into `where`
  • Loading branch information
jamesmckinna authored Jun 5, 2024
1 parent 7306dff commit d970b78
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Data/List/Base.agda
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,10 @@ linesBy {A = A} P? = go nothing where

go : Maybe (List A) List A List (List A)
go acc [] = maybe′ ([_] ∘′ reverse) [] acc
go acc (c ∷ cs) with does (P? c)
... | true = reverse (Maybe.fromMaybe [] acc) ∷ go nothing cs
... | false = go (just (c ∷ Maybe.fromMaybe [] acc)) cs
go acc (c ∷ cs) = if does (P? c)
then reverse acc′ ∷ go nothing cs
else go (just (c ∷ acc′)) cs
where acc′ = Maybe.fromMaybe [] acc

linesByᵇ : (A Bool) List A List (List A)
linesByᵇ p = linesBy (T? ∘ p)
Expand All @@ -441,9 +442,9 @@ wordsBy {A = A} P? = go [] where

go : List A List A List (List A)
go acc [] = cons acc []
go acc (c ∷ cs) with does (P? c)
... | true = cons acc (go [] cs)
... | false = go (c ∷ acc) cs
go acc (c ∷ cs) = if does (P? c)
then cons acc (go [] cs)
else go (c ∷ acc) cs

wordsByᵇ : (A Bool) List A List (List A)
wordsByᵇ p = wordsBy (T? ∘ p)
Expand Down

0 comments on commit d970b78

Please sign in to comment.