Skip to content

Commit

Permalink
Merge pull request #109 from AlexKnauth/sublist
Browse files Browse the repository at this point in the history
add sublist-lens
  • Loading branch information
jackfirth committed Jul 11, 2015
2 parents 91de3c7 + 9382b73 commit 8c969db
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
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))
]}

0 comments on commit 8c969db

Please sign in to comment.