Skip to content
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

add sublist-lens #109

Merged
merged 2 commits into from
Jul 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions unstable/lens/main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
"compound.rkt"
"list.rkt"
"hash.rkt"
"view-set.rkt")
"view-set.rkt"
"sublist.rkt"
)

(provide (all-from-out "syntax.rkt"
"compound.rkt"
"list.rkt"
"hash.rkt"
"view-set.rkt"))
"view-set.rkt"
"sublist.rkt"
))
1 change: 1 addition & 0 deletions unstable/lens/main.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ this library being backwards-compatible.
@include-section["list.scrbl"]
@include-section["hash.scrbl"]
@include-section["syntax.scrbl"]
@include-section["sublist.scrbl"]
19 changes: 19 additions & 0 deletions unstable/lens/sublist.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#lang racket/base

(provide sublist-lens)

(require lens/base/main
lens/list/main
)
(module+ test
(require rackunit))

(define (sublist-lens i j)
(lens-thrush (take-lens j) (drop-lens i)))

(module+ test
(check-equal? (lens-view (sublist-lens 1 4) '(0 1 2 3 4 5))
'(1 2 3))
(check-equal? (lens-set (sublist-lens 1 4) '(0 1 2 3 4 5) '(a b c))
'(0 a b c 4 5))
)
13 changes: 13 additions & 0 deletions unstable/lens/sublist.scrbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#lang scribble/manual

@(require lens/doc-util/main)

@title{Sublist lenses}

@defmodule[unstable/lens/sublist]

@defproc[(sublist-lens [i exact-nonnegative-integer?] [j exact-nonnegative-integer?]) lens?]{
@lenses-unstable-examples[
(lens-view (sublist-lens 1 4) '(0 1 2 3 4 5))
(lens-set (sublist-lens 1 4) '(0 1 2 3 4 5) '(a b c))
]}