On this page:


Jack Firth <jackhfirth@gmail.com>
and Alex Knauth <alexander@knauth.org>

 (require lens) package: lens-lib

This library includes functions and forms for working with lenses. A lens is a value that operates on some small piece of a larger structure. Think of them as a more general representation of getters and setters in object-oriented languages.

source code: https://github.com/jackfirth/lens

This library is stable, backwards compatibility will be maintained. For experimental features see unstable/lens.

    1 The Lens Guide

      1.1 Introduction to Lenses

        1.1.1 What are lenses?

        1.1.2 Why use lenses?

      1.2 Lenses on Built-In Datatypes

        1.2.1 Lenses on Ordered Data

 Pairs and Lists

 Vectors and Strings


        1.2.2 Lenses on Key-Value Data

 Hash Tables


      1.3 Lenses on User-Defined Datatypes

        1.3.1 Structures

        1.3.2 Constructing Entirely New Lenses

    2 The Lens Reference

      2.1 Lens Operations

        2.1.1 Core Lens Forms

 Lens Construction

 Viewing and Setting

 Lens Laws

 Transforming Values With Lenses

 Lens Contracts

        2.1.2 Joining and Composing Lenses

      2.2 Lenses for different types of data

        2.2.1 Pair and List Lenses

 Pair lenses

 List lenses

 Joining lenses to view lists

 Association List Lenses

        2.2.2 Hash Lenses

        2.2.3 Struct Lenses

        2.2.4 Vector lenses

        2.2.5 String Lenses

        2.2.6 Stream Lenses

        2.2.7 Dict lenses

      2.3 Applicable lenses

    3 Unstable Lenses

      3.1 lens-view/thrush, lens-set/thrush, and lens-transform/thrush

      3.2 Lenses for nested data

      3.3 Lenses for nested dictionaries

      3.4 Flattening and unflattening lists

      3.5 Filtering hash-tables

      3.6 Conditional Lenses

      3.7 Isomorphisms

      3.8 Joining lenses with an association list

      3.9 Lazy lenses and recursive lenses

      3.10 Lenses that map over lists and vectors

      3.11 Lenses based on match patterns

      3.12 Filtering sets

      3.13 Lenses for membership of a set

      3.14 Splitting Strings

      3.15 Joining lenses with structs

      3.16 Converting between structs and lists

      3.17 Nested struct lenses

      3.18 Struct-lens provide forms

      3.19 Sublist lenses

      3.20 Substring Lenses

      3.21 Syntax Lenses

      3.22 Syntax object lenses based on syntax/stx

      3.23 Syntax object source locations

      3.24 More Viewing and Setting

      3.25 Lenses that transform subpieces