document and provide string-split-lens

This commit is contained in:
AlexKnauth 2015-08-19 15:03:27 -04:00
parent 906ff420c6
commit 27117dd557
3 changed files with 29 additions and 0 deletions

View File

@ -6,6 +6,7 @@
"arrow.rkt"
"isomorphism.rkt"
"mapper.rkt"
"string-split.rkt"
)
(provide (all-from-out "syntax.rkt"
@ -14,4 +15,5 @@
"arrow.rkt"
"isomorphism.rkt"
"mapper.rkt"
"string-split.rkt"
))

View File

@ -15,3 +15,4 @@ this library being backwards-compatible.
@include-section["arrow.scrbl"]
@include-section["isomorphism.scrbl"]
@include-section["mapper.scrbl"]
@include-section["string-split.scrbl"]

View File

@ -0,0 +1,26 @@
#lang scribble/manual
@(require lens/doc-util/main)
@title{Splitting Strings}
@defmodule[unstable/lens/string-split]
@defproc[(string-split-lens [sep (or/c string? char? regexp?)]) lens?]{
Creates a lens that splits a string into multiple pieces like
@racket[regexp-split] or @racket[string-split].
@lenses-unstable-examples[
(lens-view (string-split-lens ",") "a,b,c")
(lens-set (string-split-lens ",") "a,b,c" '("1" "2" "3"))
]
Lenses created by @racket[string-split-lens] do not trim strings first, so that
when viewing a target that either starts or ends with something matching
@racket[sep], the view will include empty strings as the first or last element,
which is consistant with @racket[regexp-split] or @racket[string-split] with
@racket[#:trim? #f]. This is also more useful when using @racket[lens-set].
@lenses-unstable-examples[
(lens-view (string-split-lens ",") ",b,c")
(lens-set (string-split-lens ",") ",b,c" '("a" "b" "c"))
(lens-view (string-split-lens ",") "a,b,c,")
(lens-set (string-split-lens ",") "a,b,c," '("a" "b" "c" "d"))
]}