-
Notifications
You must be signed in to change notification settings - Fork 253
More list properties about catMaybes/mapMaybe
#2389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/Data/List/Relation/Binary/Permutation/Setoid/Properties/Maybe.agda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Properties of permutations using setoid equality (on Maybe elements) | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
module Data.List.Relation.Binary.Permutation.Setoid.Properties.Maybe where | ||
|
||
open import Relation.Binary.Core using (_Preserves_⟶_) | ||
open import Relation.Binary.Bundles using (Setoid) | ||
|
||
open import Level using (Level) | ||
open import Function.Base using (_∘_; _$_) | ||
|
||
open import Data.List.Base using (catMaybes; mapMaybe) | ||
open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_) | ||
import Data.List.Relation.Binary.Permutation.Setoid as Permutation | ||
open import Data.List.Relation.Binary.Permutation.Setoid.Properties | ||
|
||
open import Data.Maybe using (Maybe; nothing; just) | ||
open import Data.Maybe.Relation.Binary.Pointwise using (nothing; just) | ||
renaming (setoid to setoidᴹ) | ||
|
||
private | ||
variable | ||
a b ℓ ℓ′ : Level | ||
|
||
------------------------------------------------------------------------ | ||
-- catMaybes | ||
|
||
module _ (sᴬ : Setoid a ℓ) where | ||
open Setoid sᴬ using (_≈_) | ||
open Permutation sᴬ | ||
|
||
private sᴹ = setoidᴹ sᴬ | ||
open Setoid sᴹ using () renaming (_≈_ to _≈ᴹ_) | ||
open Permutation sᴹ using () renaming (_↭_ to _↭ᴹ_) | ||
|
||
catMaybes-↭ : ∀ {xs ys} → xs ↭ᴹ ys → catMaybes xs ↭ catMaybes ys | ||
catMaybes-↭ (refl p) = refl (pointwise p) | ||
where | ||
pointwise : ∀ {xs ys} → Pointwise _≈ᴹ_ xs ys → | ||
Pointwise _≈_ (catMaybes xs) (catMaybes ys) | ||
pointwise [] = [] | ||
pointwise (just p ∷ ps) = p ∷ pointwise ps | ||
pointwise (nothing ∷ ps) = pointwise ps | ||
catMaybes-↭ (trans xs↭ ↭ys) = trans (catMaybes-↭ xs↭) (catMaybes-↭ ↭ys) | ||
catMaybes-↭ (prep nothing xs↭) = catMaybes-↭ xs↭ | ||
catMaybes-↭ (prep (just x~y) xs↭) = prep x~y $ catMaybes-↭ xs↭ | ||
catMaybes-↭ (swap nothing nothing xs↭) = catMaybes-↭ xs↭ | ||
catMaybes-↭ (swap nothing (just y) xs↭) = prep y $ catMaybes-↭ xs↭ | ||
catMaybes-↭ (swap (just x) nothing xs↭) = prep x $ catMaybes-↭ xs↭ | ||
catMaybes-↭ (swap (just x) (just y) xs↭) = swap x y $ catMaybes-↭ xs↭ | ||
|
||
------------------------------------------------------------------------ | ||
-- mapMaybe | ||
|
||
module _ (sᴬ : Setoid a ℓ) (sᴮ : Setoid b ℓ′) where | ||
open Setoid sᴬ using () renaming (_≈_ to _≈ᴬ_) | ||
open Permutation sᴬ using () renaming (_↭_ to _↭ᴬ_) | ||
open Permutation sᴮ using () renaming (_↭_ to _↭ᴮ_) | ||
|
||
private sᴹᴮ = setoidᴹ sᴮ | ||
open Setoid sᴹᴮ using () renaming (_≈_ to _≈ᴹᴮ_) | ||
|
||
mapMaybe-↭ : ∀ {f} → f Preserves _≈ᴬ_ ⟶ _≈ᴹᴮ_ → | ||
∀ {xs ys} → xs ↭ᴬ ys → mapMaybe f xs ↭ᴮ mapMaybe f ys | ||
mapMaybe-↭ pres = catMaybes-↭ sᴮ ∘ map⁺ sᴬ sᴹᴮ pres |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.