File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -288,3 +288,15 @@ Other minor additions
288
288
```
289
289
290
290
* Added infix declarations to ` Data.Product.∃-syntax ` and ` Data.Product.∄-syntax ` .
291
+
292
+ * Added new functions to ` Data.String.Base ` :
293
+ ```
294
+ uncons : String → Maybe (Char × String)
295
+ head : String → Maybe Char
296
+ tail : String → Maybe String
297
+ ```
298
+
299
+ * Added new property to ` Data.String.Unsafe ` :
300
+ ``` agda
301
+ length-tail : length s ≡ maybe′ (suc ∘′ length) zero (tail s)
302
+ ```
Original file line number Diff line number Diff line change @@ -11,7 +11,9 @@ module Data.String.Base where
11
11
open import Level using (zero)
12
12
open import Data.Bool.Base using (true; false)
13
13
open import Data.Bool.Properties using (T?)
14
+ open import Data.Maybe.Base as Maybe using (Maybe)
14
15
open import Data.Nat.Base as ℕ using (ℕ; _∸_; ⌊_/2⌋; ⌈_/2⌉; _⊔_)
16
+ open import Data.Product using (proj₁; proj₂)
15
17
open import Data.List.Base as List using (List; [_])
16
18
open import Data.List.NonEmpty as NE using (List⁺)
17
19
open import Data.List.Relation.Binary.Pointwise using (Pointwise)
@@ -60,6 +62,14 @@ _<_ = Lex-< Char._≈_ Char._<_ on toList
60
62
------------------------------------------------------------------------
61
63
-- Operations
62
64
65
+ -- List-like operations
66
+
67
+ head : String → Maybe Char
68
+ head = Maybe.map proj₁ ∘′ uncons
69
+
70
+ tail : String → Maybe String
71
+ tail = Maybe.map proj₂ ∘′ uncons
72
+
63
73
-- Additional conversion functions
64
74
65
75
fromChar : Char → String
Original file line number Diff line number Diff line change @@ -10,12 +10,21 @@ module Data.String.Unsafe where
10
10
11
11
import Data.List.Base as List
12
12
import Data.List.Properties as Listₚ
13
- open import Data.Nat.Base using (_+_)
13
+ open import Data.Maybe.Base using (maybe′)
14
+ open import Data.Nat.Base using (zero; suc; _+_)
15
+ open import Data.Product using (proj₂)
14
16
open import Data.String.Base
17
+ open import Function.Base using (_∘′_)
15
18
16
19
open import Relation.Binary.PropositionalEquality ; open ≡-Reasoning
17
20
open import Relation.Binary.PropositionalEquality.TrustMe using (trustMe)
18
21
22
+ ------------------------------------------------------------------------
23
+ -- Properties of tail
24
+
25
+ length-tail : ∀ s → length s ≡ maybe′ (suc ∘′ length) zero (tail s)
26
+ length-tail s = trustMe
27
+
19
28
------------------------------------------------------------------------
20
29
-- Properties of conversion functions
21
30
You can’t perform that action at this time.
0 commit comments