On this page:
stream-first-lens
stream-rest-lens
stream-ref-lens
6.2.901.900

8 Stream Lenses

A lens for viewing the first element of a stream.

Examples:

> (lens-view stream-first-lens (stream 1 2 3))

1

> (stream->list (lens-set stream-first-lens (stream 1 2 3) 'a))

'(a 2 3)

A lens for viewing the rest of a stream after the first element.

Examples:

> (stream->list (lens-view stream-rest-lens (stream 1 2 3)))

'(2 3)

> (stream->list (lens-set stream-rest-lens (stream 1 2 3) (stream 200 300 400 500)))

'(1 200 300 400 500)

procedure

(stream-ref-lens i)  lens?

  i : exact-nonnegative-integer?
A lens for viewing the ith element of a stream.

Examples:

> (lens-view (stream-ref-lens 2) (stream 1 2 3 4 5 6))

3

> (stream->list (lens-set (stream-ref-lens 2) (stream 1 2 3 4 5 6) 'a))

'(1 2 a 4 5 6)