| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Non-empty lists where all elements satisfy a given property |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.List.NonEmpty.Relation.Unary.All where |
| 10 |
|
| 11 |
import Data.List.Relation.Unary.All as List |
| 12 |
open import Data.List.Relation.Unary.All using ([]; _∷_) |
| 13 |
open import Data.List.Base using ([]; _∷_) |
| 14 |
open import Data.List.NonEmpty.Base using (List⁺; _∷_; toList) |
| 15 |
open import Level using (Level; _⊔_) |
| 16 |
open import Relation.Unary using (Pred) |
| 17 |
|
| 18 |
private |
| 19 |
variable |
| 20 |
a p : Level |
| 21 |
A : Set a |
| 22 |
P : Pred A p |
| 23 |
|
| 24 |
------------------------------------------------------------------------ |
| 25 |
-- Definition |
| 26 |
|
| 27 |
-- Given a predicate P, then All P xs means that every element in xs |
| 28 |
-- satisfies P. See `Relation.Unary` for an explanation of predicates. |
| 29 |
|
| 30 |
infixr 5 _∷_ |
| 31 |
|
| 32 |
data All {A : Set a} (P : Pred A p) : Pred (List⁺ A) (a ⊔ p) where |
| 33 |
_∷_ : ∀ {x xs} (px : P x) (pxs : List.All P xs) → All P (x ∷ xs) |
| 34 |
|
| 35 |
------------------------------------------------------------------------ |
| 36 |
-- Functions |
| 37 |
|
| 38 |
toList⁺ : ∀ {xs : List⁺ A} → All P xs → List.All P (toList xs) |
| 39 |
toList⁺ (px ∷ pxs) = px ∷ pxs |