Submit Search
Upload
Lenses
•
Download as PPTX, PDF
•
2 likes
•
827 views
Brian Lonsdorf
Follow
Lenses quick and dirty. Implementation and use. https://vimeo.com/104804647
Read less
Read more
Technology
Report
Share
Report
Share
1 of 23
Download now
Recommended
Fact, Fiction, and FP
Fact, Fiction, and FP
Brian Lonsdorf
Ricky Bobby's World
Ricky Bobby's World
Brian Lonsdorf
Elm: give it a try
Elm: give it a try
Eugene Zharkov
Cycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
Eugene Zharkov
Super Advanced Python –act1
Super Advanced Python –act1
Ke Wei Louis
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
Bongwon Lee
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내
Jung Kim
Recommended
Fact, Fiction, and FP
Fact, Fiction, and FP
Brian Lonsdorf
Ricky Bobby's World
Ricky Bobby's World
Brian Lonsdorf
Elm: give it a try
Elm: give it a try
Eugene Zharkov
Cycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
Eugene Zharkov
Super Advanced Python –act1
Super Advanced Python –act1
Ke Wei Louis
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
Bongwon Lee
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내
Jung Kim
Functional programming using underscorejs
Functional programming using underscorejs
偉格 高
this
this
偉格 高
Javascript essential-pattern
Javascript essential-pattern
偉格 高
The jQuery Divide
The jQuery Divide
Rebecca Murphey
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
Vic Metcalfe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
MongoDB
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
MongoDB
Coscup2021-rust-toturial
Coscup2021-rust-toturial
Wayne Tsai
Malli: inside data-driven schemas
Malli: inside data-driven schemas
Metosin Oy
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
Tomasz Dziuda
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
Caridy Patino
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
Laurence Svekis ✔
Coscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usage
Wayne Tsai
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим Талдыкин
Юрий Сыровецкий
Designing with malli
Designing with malli
Metosin Oy
Opp compile
Opp compile
Muhammad Faiz
Naked Performance With Clojure
Naked Performance With Clojure
Metosin Oy
ES6 Overview
ES6 Overview
Bruno Scopelliti
Beyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS Apps
Rebecca Murphey
Js for learning
Js for learning
Brian Lonsdorf
Functional js class
Functional js class
Brian Lonsdorf
More Related Content
What's hot
Functional programming using underscorejs
Functional programming using underscorejs
偉格 高
this
this
偉格 高
Javascript essential-pattern
Javascript essential-pattern
偉格 高
The jQuery Divide
The jQuery Divide
Rebecca Murphey
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
Vic Metcalfe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
MongoDB
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
MongoDB
Coscup2021-rust-toturial
Coscup2021-rust-toturial
Wayne Tsai
Malli: inside data-driven schemas
Malli: inside data-driven schemas
Metosin Oy
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
Tomasz Dziuda
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
Caridy Patino
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
Laurence Svekis ✔
Coscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usage
Wayne Tsai
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим Талдыкин
Юрий Сыровецкий
Designing with malli
Designing with malli
Metosin Oy
Opp compile
Opp compile
Muhammad Faiz
Naked Performance With Clojure
Naked Performance With Clojure
Metosin Oy
ES6 Overview
ES6 Overview
Bruno Scopelliti
Beyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS Apps
Rebecca Murphey
What's hot
(20)
Functional programming using underscorejs
Functional programming using underscorejs
this
this
Javascript essential-pattern
Javascript essential-pattern
The jQuery Divide
The jQuery Divide
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Coscup2021-rust-toturial
Coscup2021-rust-toturial
Malli: inside data-driven schemas
Malli: inside data-driven schemas
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
Coscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usage
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим Талдыкин
Designing with malli
Designing with malli
Opp compile
Opp compile
Naked Performance With Clojure
Naked Performance With Clojure
ES6 Overview
ES6 Overview
Beyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS Apps
Viewers also liked
Js for learning
Js for learning
Brian Lonsdorf
Functional js class
Functional js class
Brian Lonsdorf
Liftin every day
Liftin every day
Brian Lonsdorf
Underscore
Underscore
Brian Lonsdorf
Millionways
Millionways
Brian Lonsdorf
Functional Patterns for the non-mathematician
Functional Patterns for the non-mathematician
Brian Lonsdorf
Functional Reactive Programming in Javascript
Functional Reactive Programming in Javascript
Brian Lonsdorf
Viewers also liked
(7)
Js for learning
Js for learning
Functional js class
Functional js class
Liftin every day
Liftin every day
Underscore
Underscore
Millionways
Millionways
Functional Patterns for the non-mathematician
Functional Patterns for the non-mathematician
Functional Reactive Programming in Javascript
Functional Reactive Programming in Javascript
Similar to Lenses
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
Howard Lewis Ship
Javascript
Javascript
Vlad Ifrim
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
osfameron
ECMAScript 6 and beyond
ECMAScript 6 and beyond
Francis Johny
Academy PRO: ES2015
Academy PRO: ES2015
Binary Studio
ECMAScript 6
ECMAScript 6
Piotr Lewandowski
ES6: Features + Rails
ES6: Features + Rails
Santosh Wadghule
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Doris Chen
EcmaScript 6
EcmaScript 6
Manoj Kumar
ES6 is Nigh
ES6 is Nigh
Domenic Denicola
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
Sunghyouk Bae
ES6 and AngularAMD
ES6 and AngularAMD
dhaval10690
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
Nova Patch
Go Says WAT?
Go Says WAT?
jonbodner
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜
Takahiro Inoue
Ruby - Uma Introdução
Ruby - Uma Introdução
Ígor Bonadio
ECMAScript 6 new features
ECMAScript 6 new features
GephenSG
An Intro To ES6
An Intro To ES6
FITC
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
Similar to Lenses
(20)
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
Javascript
Javascript
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
ECMAScript 6 and beyond
ECMAScript 6 and beyond
Academy PRO: ES2015
Academy PRO: ES2015
ECMAScript 6
ECMAScript 6
ES6: Features + Rails
ES6: Features + Rails
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
EcmaScript 6
EcmaScript 6
ES6 is Nigh
ES6 is Nigh
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
ES6 and AngularAMD
ES6 and AngularAMD
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
Go Says WAT?
Go Says WAT?
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜
Ruby - Uma Introdução
Ruby - Uma Introdução
ECMAScript 6 new features
ECMAScript 6 new features
An Intro To ES6
An Intro To ES6
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
Recently uploaded
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Principled Technologies
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Radu Cotescu
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
UK Journal
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Khushali Kathiriya
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Juan lago vázquez
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Remote DBA Services
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Miguel Araújo
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Rafal Los
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc
🐬 The future of MySQL is Postgres 🐘
🐬 The future of MySQL is Postgres 🐘
RTylerCroy
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Gabriella Davis
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
The Digital Insurer
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
apidays
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
debabhi2
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Anna Loughnan Colquhoun
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
apidays
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
wesley chun
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
Recently uploaded
(20)
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
🐬 The future of MySQL is Postgres 🐘
🐬 The future of MySQL is Postgres 🐘
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Lenses
1.
Lenses Quick n’
Dirty
2.
Agenda • Review
(Functors) • Ideas behind lenses • Neat Uses • Demo
3.
Functor Review
4.
map(add(1), [1, 2,
3]) //=> [2, 3, 4] map(add(1), {a: 1, b: 2}) //=> {a: 2, b: 3}
5.
map(map(add(1)), Future.of(Maybe(2))) //=>
Future(Maybe(3)) map(map(add(1)), [Maybe(1), Maybe(2), Maybe(3)]) //=> [Maybe(2), Maybe(3), Maybe(4)]
6.
Getters/Setters
7.
map(f, Identity(x)) //
Identity(f(x)) map(f, Const(x)) // Const(x) !noop
8.
map(add(1), Identity(2)) //=>
Identity(3) map(add(1), Const(2)) //=> Const(2)
9.
compose(runIdentity, map(add(1)), Identity)(2)
//=> 3 compose(getConst, map(add(1)), Const)(2) //=> 2
10.
var getter =
function(f, x){ return compose(getConst, map(f), Const)(x) } var setter = function(f, x){ return compose(runIdentity, map(f), Identity)(x) } getter(reverse, [1,2,3]) //=> [1,2,3] setter(reverse, [1,2,3]) //=> [3,2,1]
11.
Lenses
12.
LENS A function
that acts as both a getter and setter
13.
var objectLens =
function(key) { return function(f, obj) { return map(set(key, obj), f(obj[key])) } }
14.
var objectLens =
function(key) { return function(f, obj) { return map(set(key, obj), f(obj[key])) } }
15.
var objectLens =
function(key) { return function(f, obj) { return map(set(key, obj), f(obj[key])) } }
16.
var view =
function(lens, x) { return compose(getConst, lens(Const))(x) } var over = function(lens, f, x) { return compose(runIdentity, lens(compose(Identity, f)))(x) } var set = function(lens, v, x) { return over(lens, K(v), x) }
17.
Uses
18.
var L =
makeLenses(['friends', ‘email’, ‘name’]) var user = {name: "Emily", friends: [{email: "bob@ross.net"}, {email: "kendra@spacehog.org"}] } view(L.name, user) //=> "Emily" view(L.friends, user) //=> [{email: "bob@ross.net"}, {email: "kendra@spacehog.org}] over(L.name, replace("E", "***"), user) //=> {name: "***mily", friends: [{email: "bob@ross.net"}, {email: "kendra@spacehog.org}] }
19.
set(L.name, “Esmeralda”, user)
//=> {name: "Esmeralda", friends: [{email: "bob@ross.net"}, {email: "kendra@spacehog.org}] } set(L.friends, [], user) //=> //=> {name: "Emily", friends: [] }
20.
var user =
{name: "Emily", friends: [undefined, {email: "bob@ross.net"}, undefined, {email: "kendra@spacehog.var getUser = compose(sendJSON, filter(isDefined), _.get(‘friends')) getUser(user) //=> [{email: "bob@ross.net"}, {email: “kendra@spacehog.org}]
21.
var user =
{name: "Emily", friends: [undefined, {email: "bob@ross.net"}, undefined, {email: "kendra@spacehog.var getUser = compose(sendJSON, over(L.friends, filter(isDefined))) getUser(user) //=> {name: "Esmeralda", friends: [{email: "bob@ross.net"}, {email: "kendra@spacehog.org}] }
22.
L.firstFriend = compose(L.friends,
L.num(0)); set(L.firstFriend, {email:"kelly@kapowski.net"}, user) //=> {name: "Emily", friends: [{email: "kelly@kapowski.net"}, {email: "kendra@spacehog.org}] } L.firstFriendsEmail = compose(L.firstFriend, L.email); over(L.firstFriendsEmail, toUpperCase, user) //=> {name: "Emily", friends: [{email: “KELLY@KAPOWSKI.NET"}, {email: "kendra@spacehog.org}]
23.
L.friendsEmails = compose(L.friends,
L.mapped, L.email) var emailFriends = compose( concat("Emailed friends of ") , view(L.name) , over(L.friendsEmails, sendEmail) ) emailFriends(user) //=> emailing bob@ross.net //=> emailing kendra@spacehog.org //=> Emailed friends of Emily
Download now