Skip to content

Improve Data.List.Base (fix #2359; deprecate use of with #2123) #2366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Data/List/Base.agda
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,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 @@ -448,9 +449,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
Loading