Skip to content

Commit db205ce

Browse files
authored
Add IO.Base.untilRight (#1802)
1 parent f0b67e9 commit db205ce

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,7 @@ Other minor changes
17061706
17071707
whenJust : Maybe A → (A → IO ⊤) → IO ⊤
17081708
untilJust : IO (Maybe A) → IO A
1709+
untilRight : (A → IO (A ⊎ B)) → A → IO B
17091710
```
17101711

17111712
* Added new functions in `Reflection.AST.Term`:

src/IO/Base.agda

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ open import Level
1212
open import Codata.Musical.Notation
1313
open import Data.Bool.Base using (Bool; true; false; not)
1414
open import Agda.Builtin.Maybe using (Maybe; nothing; just)
15+
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
1516
import Agda.Builtin.Unit as Unit0
1617
open import Data.Unit.Polymorphic.Base
1718
open import Function.Base using (_∘′_; const; flip)
@@ -128,3 +129,8 @@ untilJust : IO (Maybe A) → IO A
128129
untilJust m = bind (♯ m) λ where
129130
nothing ♯ untilJust m
130131
(just a) ♯ return a
132+
133+
untilRight : {A B : Set a} (A IO (A ⊎ B)) A IO B
134+
untilRight f x = bind (♯ f x) λ where
135+
(inj₁ x′) ♯ untilRight f x′
136+
(inj₂ y) ♯ return y

0 commit comments

Comments
 (0)