Swiftpack.co - Package - to4iki/LensKit

LensKit

Build Status Carthage compatible

a minimum Lens type, and code generation helper inspired by lens

Overview

Monocle.Lens - elm-monocle

A Lens is a functional common problem: how to easily update a complex immutable structure, for this purpose Lens acts as a zoom into a record.

example.

struct Street { let name: String }
struct Address { let street: Street }
struct Company { let address: Address }
struct Employee { let company: Company }

let employee = Employee(company: Company(address: Address(street: Street(name: "street"))))

use lens

let _name: Lens<Street, String> = Lens(get: { $0.name }, set: { Street(name: $1) })
let _street: Lens<Address, Street> = Lens(get: { $0.street }, set: { Address(street: $1) })
let _address: Lens<Company, Address> = Lens(get: { $0.address }, set: { Company(address: $1) })
let _company: Lens<Employee, Company> = Lens(get: { $0.company }, set: { Employee(company: $1) })

(_company >>> _address >>> _street >>> _name).modify(employee) { $0.capitalizedString } // Street

Code generation with Sourcery

By using Scripts/generate-auto-lens.sh, LensKit will support lens-implementation to auto-generate extension YourClass: AutoLens.

# Usage: ./generate-auto-lens.sh <source_dir> <code-generated-dir>
$ ./path/to/LensKit/Scripts/generate-auto-lens.sh ./Sources ./Sources/Genes/

output file: AutoLens.generated.swift

Installation

Carthage

Add following line into your Cartfile and run carthage update.

github "to4iki/LensKit"

SwiftPackage Manager

Add following line into your Package.swift and run swift build.

dependencies: [
    .Package(url: "https://github.com/to4iki/LensKit.git", majorVersion: 0)
]

Github

link
Stars: 10
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

0.1.0 - Feb 17, 2018

  • 710b31687e20220248335be72e5ccb1299b4316d

0.0.2 - Nov 2, 2017

  • #1 Topic/generate scripts

0.0.1 - Oct 23, 2017

  • minimum implementation of Lens type
  • code generation helper