| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Bounded vectors |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Vec.Bounded where |
| 10 |
|
| 11 |
open import Level using (Level) |
| 12 |
open import Data.Nat.Base using (_≤_) |
| 13 |
open import Data.Vec.Base using (Vec) |
| 14 |
import Data.Vec as Vec using (filter; takeWhile; dropWhile) |
| 15 |
open import Function.Base using (id) |
| 16 |
open import Relation.Binary.Core using (_Preserves_⟶_) |
| 17 |
open import Relation.Unary using (Pred; Decidable) |
| 18 |
|
| 19 |
private |
| 20 |
variable |
| 21 |
a p : Level |
| 22 |
A : Set a |
| 23 |
|
| 24 |
------------------------------------------------------------------------ |
| 25 |
-- Publicly re-export the contents of the base module |
| 26 |
|
| 27 |
open import Data.Vec.Bounded.Base public |
| 28 |
|
| 29 |
------------------------------------------------------------------------ |
| 30 |
-- Additional operations |
| 31 |
|
| 32 |
lift : ∀ {f} → f Preserves _≤_ ⟶ _≤_ → |
| 33 |
(∀ {n} → Vec A n → Vec≤ A (f n)) → |
| 34 |
∀ {n} → Vec≤ A n → Vec≤ A (f n) |
| 35 |
lift incr f (as , p) = ≤-cast (incr p) (f as) |
| 36 |
|
| 37 |
lift′ : (∀ {n} → Vec A n → Vec≤ A n) → |
| 38 |
(∀ {n} → Vec≤ A n → Vec≤ A n) |
| 39 |
lift′ = lift id |
| 40 |
|
| 41 |
------------------------------------------------------------------------ |
| 42 |
-- Additional operations |
| 43 |
|
| 44 |
module _ {P : Pred A p} (P? : Decidable P) where |
| 45 |
|
| 46 |
filter : ∀ {n} → Vec≤ A n → Vec≤ A n |
| 47 |
filter = lift′ (Vec.filter P?) |
| 48 |
|
| 49 |
takeWhile : ∀ {n} → Vec≤ A n → Vec≤ A n |
| 50 |
takeWhile = lift′ (Vec.takeWhile P?) |
| 51 |
|
| 52 |
dropWhile : ∀ {n} → Vec≤ A n → Vec≤ A n |
| 53 |
dropWhile = lift′ (Vec.dropWhile P?) |