|
| 1 | +------------------------------------------------------------------------ |
| 2 | +-- The Agda standard library |
| 3 | +-- |
| 4 | +-- Non-empty lists where at least one element satisfies a given property |
| 5 | +------------------------------------------------------------------------ |
| 6 | + |
| 7 | +{-# OPTIONS --cubical-compatible --safe #-} |
| 8 | + |
| 9 | +module Data.List.NonEmpty.Relation.Unary.Any where |
| 10 | + |
| 11 | +open import Data.List.NonEmpty.Base using (List⁺; _∷_; toList) |
| 12 | +open import Data.List.Relation.Unary.Any as List using (here; there) |
| 13 | +open import Data.List.Base using ([]; _∷_) |
| 14 | +open import Data.Product.Base using (_,_) |
| 15 | +open import Level using (Level; _⊔_) |
| 16 | +open import Relation.Unary using (Pred; Satisfiable; _⊆_) |
| 17 | + |
| 18 | +private |
| 19 | + variable |
| 20 | + a p : Level |
| 21 | + A : Set a |
| 22 | + P Q : Pred A p |
| 23 | + xs : List⁺ A |
| 24 | + |
| 25 | +------------------------------------------------------------------------ |
| 26 | +-- Definition |
| 27 | + |
| 28 | +-- Given a predicate P, then Any P xs means that every element in xs |
| 29 | +-- satisfies P. See `Relation.Unary` for an explanation of predicates. |
| 30 | + |
| 31 | +data Any {A : Set a} (P : Pred A p) : Pred (List⁺ A) (a ⊔ p) where |
| 32 | + here : ∀ {x xs} (px : P x) → Any P (x ∷ xs) |
| 33 | + there : ∀ {x xs} (pxs : List.Any P xs) → Any P (x ∷ xs) |
| 34 | + |
| 35 | +------------------------------------------------------------------------ |
| 36 | +-- Operations |
| 37 | + |
| 38 | +map : P ⊆ Q → Any P ⊆ Any Q |
| 39 | +map g (here px) = here (g px) |
| 40 | +map g (there pxs) = there (List.map g pxs) |
| 41 | + |
| 42 | +------------------------------------------------------------------------ |
| 43 | +-- Predicates |
| 44 | + |
| 45 | +satisfied : Any P xs → Satisfiable P |
| 46 | +satisfied (here px) = _ , px |
| 47 | +satisfied (there pxs) = List.satisfied pxs |
0 commit comments