Giter VIP home page Giter VIP logo

lenses's Introduction

lenses.js

Functional lenses that compose and stuff

require('./src/lenses').expose(global);
var compose = require('pointfree-fantasy').compose;

// setup an easy test fn
var toUpperCase = function(x) { return x.toUpperCase(); };

// here's the data structure
var user = {name: "Bob", addresses: [{street: '99 Maple', zip: 94004, type: 'home'}, {street: '2302 Powell', zip: 94001, type: 'work'}]}

// make some lenses
var L = makeLenses(['name', 'addresses', 'street']);

// compose the lenses
var secondAddressesStreet = compose(L.addresses, L._num(2), L.street)

// mess with the user
over(secondAddressesStreet, toUpperCase, user) // { name: 'Bob', addresses: [ { street: '99 Maple', zip: 94004, type: 'home' }, { street: '2302 POWELL', zip: 94001, type: 'work' } ] }

view(L.name, user) // 'Bob'

set(L.name, 'Kelly', user) // {name: "Kelly", addresses: [{street: '99 Maple', zip: 94004, type: 'home'}, {street: '2302 Powell', zip: 94001, type: 'work'}]}

For those not already familiar with lenses, a brief introduction can be found here

ROADMAP:

  • add traverses and folds
  • more combinators
  • prisms
  • this list is getting long...

lenses's People

Contributors

nodename avatar nsluss avatar vendethiel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lenses's Issues

Still recommended?

This looks great! I'm about to use it... but then, would you still recommend it, or would you recommend rambda-lens, or any of these others?

lenses - Composable kmett style lenses
optics - profunctor optics (Lens, Prism, iso)
ramda-lens - :ram: :mag_right: Lens library built on ramda
fantasy-lenses - Composable, immutable getters and setters. (profunctor lenses WIP)
nanoscope - Lenses with dotty support

Explanation

Hey dude, I saw this and wanted to better understand how lenses work. The code was pretty confusing to me, so I thought I'd start with what does this mean?

/*
* type Lens s t a b = ∀f. Functor f => (a -> f b) -> s -> f t
* type Setter s t a b = (a -> Identity b) -> s -> Identity t
* type Getting r s t a b = (a -> Const r b) -> s -> Const r t
* type Getter s a = ∀r. (a -> Const r a) -> s -> Const r s
* type Traversal s t a b = ∀f. Applicative f => (a -> f b) -> s -> f t
* type Fold s a = ∀m. Monoid m => (a -> Const m a) -> s -> Const m s
*/

I have a math background so I understand for-all. But other than that, I'm lost. Any online books or classes you'd recommend?

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.