Socket
Book a DemoInstallSign in
Socket

lenses

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lenses

Kmett style lenses in js.

0.1.0
latest
Source
npmnpm
Version published
Weekly downloads
76
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

lenses.js

Functional lenses that compose and stuff

require('./src/lenses').expose(global);
var compose = require('./src/lib/pointfree').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'}]}

ROADMAP:

  • remove dependency on identity and const from pointfree and use fantasy ones
  • update the browser file for amd as well
  • add traverses and folds
  • more combinators
  • prisms
  • this list is getting long...

Keywords

functional

FAQs

Package last updated on 30 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.