Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Lens introduction
Search
to4iki
February 18, 2018
Programming
580
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Lens introduction
in `swift` implementation
see:
https://github.com/to4iki/LensKit
to4iki
February 18, 2018
More Decks by to4iki
See All by to4iki
Claude Code の活用事例
to4iki
0
190
Swift Concurrencyを利用したUIViewController表示の排他制御の実装
to4iki
0
3.8k
ケースに応じたUICollectionViewのレイアウト実装パターン
to4iki
1
5.8k
ビューインプレッションの計測方法
to4iki
1
1.2k
秘伝の `gitconfig`
to4iki
1
470
Abema iOS Architecture
to4iki
12
3.6k
timetable-bot
to4iki
0
15k
BLoC Pattern Introduction with Swift
to4iki
2
1.4k
nel
to4iki
0
200
Other Decks in Programming
See All in Programming
Press start. Python's next generation.
willingc
PRO
3
330
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
500
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
270
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
AIの中の人になってみる
htkym
0
170
Deep dive into the select statement (GopherCon UK)
jespino
0
170
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
110
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
120
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
270
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
910
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2.1k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.9k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Darren the Foodie - Storyboard
khoart
PRO
3
3.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Six Lessons from altMBA
skipperchong
29
4.5k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
520
Transcript
Lens Shinjuku.LT#17 @to4iki 1
Me • Takezawa • • ! • ☕ •
♨ 2
what Lens? 3
Def. / Feature • getter/setterͷநԽɾম͖͠(൚༻Խ) • ༷ʑͳσʔλΛڞ௨ͷI/FͰૢ࡞Ͱ͖Δ • ಛఆͷݴޠʹґଘ͠ͳ͍֓೦/ܕ •
functional • ෆมߏ / ߹Մೳ • Lens Laws 4
ekmett/lens 5
• Monocle.Lens - elm-monocle • julien-truffaut/Monocle 6
https://github.com/julien-truffaut/Monocle/blob/master/image/class- diagram.png 7
getter setter 8
getter • ΦϒδΣΫτS͔ΒAΛऔΓग़͢ • get: (S) -> A setter •
ΦϒδΣΫτSͷҙͷΛAʹมߋ͢Δ • set: (S, A) -> S == set: (S) -> A -> S 9
͜ΕΒͷ͍͢͝ getter/setter1Λ ҙͷΦϒδΣΫτͷ ҙͷϝϯόʹద༻͢Δͷ͕ Lens 1 https://qiita.com/to4iki/items/f0cc28e1102cf53be85d 10
࣮ͯ͠ΈΔ 11
struct Lens<S, T> { private let _get: (S) -> T
private let _set: (S, T) -> S init(get: @escaping (S) -> T, set: @escaping (S, T) -> S) func get(_ source: S) -> T func set(_ source: S, value: T) -> S } 12
͜Μ͚ͩ 13
struct User { let name: String } let user =
User(name: "hoge") let nameLens = Lens<User, String>( get: { $0.name }, set: { User(name: $1) } ) nameLens.get(user) // "hoge" nameLens.set("fuga") // User(name:"fuga)" 14
Usecase? 15
ωετͨ͠σʔλͷ͋ΔҰ෦ ͚ͩΛมߋ͍ͨ͠ 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")))) 16
! let updatedEmployee = Employee(company: Company(address: Address(street: Street(name: employee.company.address.street.name.capitalizedString) )
) ) 17
Lens߹Λ͍ɺ ෆมߏΛอͪͳ͕Β ΞΫηεग़དྷΔ 18
struct Lens<S, T> { ... func compose<U>(_ other: Lens<T, U>)
-> Lens<S, U> { return Lens<S, U>( get: { (source: S) -> U in other.get(self.get((source))) }, set: { (source: S, value: U) -> S in self.set(source, value: other.set(self.get(source), value: value)) } ) } } 19
(operatorఆٛ͠ͱ͘) /// Left-to-Right Composition infix operator >>> : MultiplicationPrecedence func
>>> <S, T, U>(lhs: Lens<S, T>, rhs: Lens<T, U>) -> Lens<S, U> { return lhs.compose(rhs) } 20
Demo 21
! let nameLens = Lens<Street, String>(get: { $0.name }, set:
{ Street(name: $1) } ) let streetLens = Lens<Address, Street> ... let addressLens = Lens<Company, Address> ... let companyLens = Lens<Employee, Company> ... let lens: Lens<Employee, String> = companyLens >>> addressLens >>> streetLens >>> nameLens let employee = Employee(company: Company(address: Address(street: Street(name: "street")))) let updatedEmployee = lens.modify(employee) { $0.capitalized } // Employee(Company(Address(Street(name: "Street") 22
https://github.com/ to4iki/LensKit 23
Conclusion • Lens ͍͢͝getter/setter • ෆมߏΛอͪͳ͕Β • ਂ͍ߏͰ •
ʹΞΫηεग़དྷΔ • Ϣʔεέʔεਖ਼͍͠ • ςετ࣌ͷαϙʔτͱͯ͠͏? 24
See also • ࠓ͔Β࢝ΊΔ Lens/Prism 25