From 3c2db6c1a9037102c855cb2e424ac3f91a0e3b09 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Fri, 17 Jul 2015 18:13:28 -0400 Subject: [PATCH] provide and document string lenses --- unstable/lens/main.rkt | 2 ++ unstable/lens/main.scrbl | 1 + unstable/lens/string.scrbl | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 unstable/lens/string.scrbl diff --git a/unstable/lens/main.rkt b/unstable/lens/main.rkt index 93a61f5..63b4650 100644 --- a/unstable/lens/main.rkt +++ b/unstable/lens/main.rkt @@ -4,6 +4,7 @@ "join.rkt" "list.rkt" "hash.rkt" + "string.rkt" "view-set.rkt" "sublist.rkt" "struct.rkt" @@ -15,6 +16,7 @@ "join.rkt" "list.rkt" "hash.rkt" + "string.rkt" "view-set.rkt" "sublist.rkt" "struct.rkt" diff --git a/unstable/lens/main.scrbl b/unstable/lens/main.scrbl index 2800730..b675413 100644 --- a/unstable/lens/main.scrbl +++ b/unstable/lens/main.scrbl @@ -13,6 +13,7 @@ this library being backwards-compatible. @include-section["join.scrbl"] @include-section["list.scrbl"] @include-section["hash.scrbl"] +@include-section["string.scrbl"] @include-section["syntax.scrbl"] @include-section["sublist.scrbl"] @include-section["struct.scrbl"] diff --git a/unstable/lens/string.scrbl b/unstable/lens/string.scrbl new file mode 100644 index 0000000..e4fe2f8 --- /dev/null +++ b/unstable/lens/string.scrbl @@ -0,0 +1,23 @@ +#lang scribble/manual + +@(require lens/doc-util/main) + +@title{String Lenses} + +@defproc[(string-ref-lens [i exact-nonnegative-integer?]) lens?]{ +Returns a lens for viewing the @racket[i]th character of a string. +@lenses-unstable-examples[ + (lens-view (string-ref-lens 2) "abcdef") + (lens-set (string-ref-lens 2) "abcdef" #\C) +]} + +@defproc[(string-pluck-lens [i exact-nonnegative-integer?]) lens?]{ +Like @racket[list-refs-lens], but for strings. +Equivalent to @racket[(lens-join/string (string-ref-lens i) ...)]. +@lenses-unstable-examples[ + (define 1-5-6-lens (string-pluck-lens 1 5 6)) + (check-equal? (lens-view 1-5-6-lens "abcdefg") + "bfg") + (check-equal? (lens-set 1-5-6-lens "abcdefg" "BFG") + "aBcdeFG") +]}