On this page:
Lenses
7.0

Lenses

Jack Firth <[email protected]>
and Alex Knauth <[email protected]>

 (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

          1.2.1.1 Pairs and Lists

          1.2.1.2 Vectors and Strings

          1.2.1.3 Streams

        1.2.2 Lenses on Key-Value Data

          1.2.2.1 Hash Tables

          1.2.2.2 Dictionaries

      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

          2.1.1.1 Lens Construction

          2.1.1.2 Viewing and Setting

          2.1.1.3 Lens Laws

          2.1.1.4 Transforming Values With Lenses

          2.1.1.5 Lens Contracts

        2.1.2 Joining and Composing Lenses

      2.2 Lenses for different types of data

        2.2.1 Pair and List Lenses

          2.2.1.1 Pair lenses

          2.2.1.2 List lenses

          2.2.1.3 Joining lenses to view lists

          2.2.1.4 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