Skip to content

Commit 23a00fd

Browse files
Add partition-is-foldr to Data.List.Properties (#2505)
* Add partition-is-foldr * Update src/Data/List/Properties.agda Co-authored-by: jamesmckinna <[email protected]> --------- Co-authored-by: jamesmckinna <[email protected]>
1 parent f35135d commit 23a00fd

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ Additions to existing modules
186186
∈⇒≤product : All NonZero ns → n ∈ ns → n ≤ product ns
187187
concatMap-++ : concatMap f (xs ++ ys) ≡ concatMap f xs ++ concatMap f ys
188188
filter-≐ : P ≐ Q → filter P? ≗ filter Q?
189+
190+
partition-is-foldr : partition P? ≗ foldr (λ x → if does (P? x) then Product.map₁ (x ∷_)
191+
else Product.map₂ (x ∷_))
192+
([] , [])
189193
```
190194

191195
* In `Data.List.Relation.Unary.Any.Properties`:

src/Data/List/Properties.agda

+8
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,14 @@ module _ {P : Pred A p} (P? : Decidable P) where
12941294
... | true = Product.map s≤s m≤n⇒m≤1+n ih
12951295
... | false = Product.map m≤n⇒m≤1+n s≤s ih
12961296

1297+
partition-is-foldr : partition P? ≗ foldr
1298+
(λ x if does (P? x) then Product.map₁ (x ∷_) else Product.map₂ (x ∷_))
1299+
([] , [])
1300+
partition-is-foldr [] = refl
1301+
partition-is-foldr (x ∷ xs) with ih partition-is-foldr xs | does (P? x)
1302+
... | true = cong (Product.map₁ (x ∷_)) ih
1303+
... | false = cong (Product.map₂ (x ∷_)) ih
1304+
12971305
------------------------------------------------------------------------
12981306
-- _ʳ++_
12991307

0 commit comments

Comments
 (0)