@@ -10,9 +10,11 @@ module Data.List.Relation.Unary.AllPairs.Properties where
1010
1111open import Data.List.Base hiding (any)
1212open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
13- import Data.List.Relation.Unary.All.Properties as All
13+ open import Data.List.Relation.Unary.All.Properties as All using (Any-catMaybes⁺)
1414open import Data.List.Relation.Unary.AllPairs as AllPairs using (AllPairs; []; _∷_)
1515open import Data.Bool.Base using (true; false)
16+ open import Data.Maybe using (Maybe; nothing; just)
17+ open import Data.Maybe.Relation.Binary.Pointwise using (pointwise⊆any; Pointwise)
1618open import Data.Fin.Base as F using (Fin)
1719open import Data.Fin.Properties using (suc-injective; <⇒≢)
1820open import Data.Nat.Base using (zero; suc; _<_; z≤n; s≤s; z<s; s<s)
@@ -22,7 +24,7 @@ open import Level using (Level)
2224open import Relation.Binary.Core using (Rel)
2325open import Relation.Binary.Bundles using (DecSetoid)
2426open import Relation.Binary.PropositionalEquality.Core using (_≢_)
25- open import Relation.Unary using (Pred; Decidable)
27+ open import Relation.Unary using (Pred; Decidable; _⊆_ )
2628open import Relation.Nullary.Decidable using (does)
2729
2830private
@@ -136,3 +138,13 @@ module _ {R : Rel A ℓ} {P : Pred A p} (P? : Decidable P) where
136138 filter⁺ {x ∷ xs} (x∉xs ∷ xs!) with does (P? x)
137139 ... | false = filter⁺ xs!
138140 ... | true = All.filter⁺ P? x∉xs ∷ filter⁺ xs!
141+
142+ ------------------------------------------------------------------------
143+ -- catMaybes
144+
145+ module _ {R : Rel A ℓ} where
146+
147+ catMaybes⁺ : {xs : List (Maybe A)} → AllPairs (Pointwise R) xs → AllPairs R (catMaybes xs)
148+ catMaybes⁺ {xs = []} [] = []
149+ catMaybes⁺ {xs = nothing ∷ _} (x∼xs ∷ pxs) = catMaybes⁺ pxs
150+ catMaybes⁺ {xs = just x ∷ xs} (x∼xs ∷ pxs) = Any-catMaybes⁺ (All.map pointwise⊆any x∼xs) ∷ catMaybes⁺ pxs
0 commit comments