Skip to main content

\

Project description

oculist

Statically typed, purely functional lenses for Python.

Features

Quickstart

from dataclasses import dataclass

from oculist import Lens


@dataclass(frozen=True)
def Address:
    street: Lens[str] = Lens()


@dataclass(frozen=True)
def User:
    name: Lens[str] = Lens()  # 'Lens' is a descriptor
    address: Lens[Address] = Lens()


bob = User('bob', Address("Some st."))

alice = (
    bob
    > User.name << 'alice'  # Define transformations using << and apply using >
    | User.address * Address.street << 'Other st.' # Compose transformations with | and chain lenses with *
)

assert bob.name == 'bob' and alice.name == 'alice'  # original target is left untouched

Concepts

Lenses, Attributes and Setters

Special Lenses

List

Tuple

Dict

Set

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oculist-0.0.0.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

oculist-0.0.0-py3-none-any.whl (2.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page