Git Product home page Git Product logo

lenskit's Introduction

LensKit

Swift 4.2 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

Add following line into your Cartfile and run carthage update.

github "to4iki/LensKit"

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

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

lenskit's People

Contributors

to4iki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.