SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
Lightning Talk by
presented by Naoki Aoyama (@aoiroaoino)
in ScalaMatsuri 2016
> whoami
• Naoki Aoyama
• Twitter: @AoiroAoino
• GitHub: @aoiroaoino
• Scala Exp: about 4 years
• committer
Product:
広告主
Audience
It'swe!
DSP SSP Media
広
告
出
稿
広
告
閲
覧
1. 広告リクエスト
2. bid request
3. 入札判断
4. bid response
5. 落札通知
6. 広告配信
afewsecs
100 ms or die!
※画像は http://jp.yamaha.com/products/network/downloads/tools/ より
Product: FSS
Web管理画面から
紙広告を配信!
try {
Tour of Lens

in 3 minutes
Simple data structure
case class Player(name: String, age: Int)
val player = Player("aoino", 25)
scala> player.name
res0: String = aoino
scala> player.copy(age = 26)
res1: Player = Player(aoino,26)
Nested data structure
case class Game(stageId: Int, player: Player)
val game = Game(999, player)
// get
scala> game.player.name
res6: String = aoino
// set
scala> game.copy(
| player = game.player.copy(
| name = "Aoyama"
| )
| )
res7: Game = Game(999,Player(Aoyama,25))
Copy method hell ...
aaa.copy (
bbb = aaa.bbb.copy (
ccc = aaa.bbb.ccc.copy (
ddd = aaa.bbb.ccc.ddd.copy (
eee = aaa.bbb.ccc.ddd.eee.copy (
fff = aaa.bbb.ccc.ddd.eee.fff.copy (
ggg =
)
)
)
)
)
)
Motivation
• We need the simple syntax like updating
mutable objects

-> want to avoid the copy method hell
• We always want a "composability" and
"reusability"

-> compose of a getter/settter defined in

the class is difficult
_人人人人_
> Lens <
 ̄Y^Y^Y ̄
What s the Lens?
• something like a getter/setter such as Java
• functional reference
What s the Lens?
getter: S => A
e.g. player.name
// => "aoino"
setter: A => S => S
e.g. player.copy(age = 26)
// => Player("aoino",26)
What s the Lens?
case class Lens[S, A](get: S => A, set: A => S => S)
Let s define some Lenses
case class Lens[S, A](get: S => A, set: A => S => S)
case class Player(name: String, age: Int)
val _name: Lens[Player, String] =
Lens(
_.name,
str => player => player.copy(name = str)
)
val _age: Lens[Player, Int] =
Lens(
_.age,
num => player => player.copy(age = num)
)
Give it a try
scala> _name.get(player)
res2: String = aoino
scala> _name.set("Aoyama")(player)
res3: Player = Player(Aoyama,25)
scala> _age.get(player)
res4: Int = 25
scala> _age.set(26)(player)
res5: Player = Player(aoino,26)
We need `composability`
// in Function
f: A => B
g: B => C
g compose f : A => C
// in Lens
sa: Lens[S, A]
ab: Lens[A, B]
sa compose ab : Lens[S, B]
Note: Typically, Lenses `compose` is reverse compared to function.
Let s define `compose` method
case class Lens[S, A](get: S => A, set: A => S => S){
def compose[B](other: Lens[A, B]): Lens[S, B] =
Lens(
s => other.get(this.get(s)),
b => s => this.set(
other.set(b)(this.get(s))
)(s)
)
}
Give it a try
val _player: Lens[Game, Player] = ...
scala> (_player compose _name).get(game)
res8: String = aoino
scala> (_player compose _name).set("Aoyama")(game)
res9: Game = Game(999,Player(Aoyama,25))
(_bbb compose _ccc
compose _ddd
compose _eee
compose _fff
compose _ggg).set( )(aaa)
Lens for the win!!
Example in Maverick
• We use Monocle in test codes.
} finally {
–Naoki Aoyama
Lens is Awesome!
}

Weitere ähnliche Inhalte

Ähnlich wie Maverick sponsor LT

Tame cloud complexity with F# powered DSLs (build stuff)
Tame cloud complexity with F# powered DSLs (build stuff)Tame cloud complexity with F# powered DSLs (build stuff)
Tame cloud complexity with F# powered DSLs (build stuff)Yan Cui
 
Baseball Prediction Model on Tensorflow
Baseball Prediction Model on TensorflowBaseball Prediction Model on Tensorflow
Baseball Prediction Model on TensorflowJay Ryu
 
The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30Mahmoud Samir Fayed
 
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsTips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsMongoDB
 
A look at the CQL changes in 3.x (Benjamin Lerer, Datastax) | Cassandra Summi...
A look at the CQL changes in 3.x (Benjamin Lerer, Datastax) | Cassandra Summi...A look at the CQL changes in 3.x (Benjamin Lerer, Datastax) | Cassandra Summi...
A look at the CQL changes in 3.x (Benjamin Lerer, Datastax) | Cassandra Summi...DataStax
 
A look at the cql changes in 3.x
A look at the cql changes in 3.xA look at the cql changes in 3.x
A look at the cql changes in 3.xBenjamin Lerer
 
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfrozakashif85
 
Ropossum: A Game That Generates Itself
Ropossum: A Game That Generates ItselfRopossum: A Game That Generates Itself
Ropossum: A Game That Generates ItselfMohammad Shaker
 
The Ring programming language version 1.5.4 book - Part 53 of 185
The Ring programming language version 1.5.4 book - Part 53 of 185The Ring programming language version 1.5.4 book - Part 53 of 185
The Ring programming language version 1.5.4 book - Part 53 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 47 of 184
The Ring programming language version 1.5.3 book - Part 47 of 184The Ring programming language version 1.5.3 book - Part 47 of 184
The Ring programming language version 1.5.3 book - Part 47 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88Mahmoud Samir Fayed
 
Chainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereportChainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereportPreferred Networks
 
Casting for not so strange actors
Casting for not so strange actorsCasting for not so strange actors
Casting for not so strange actorszucaritask
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorNick Pruehs
 
Chapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdfChapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdfMekiyaShigute1
 

Ähnlich wie Maverick sponsor LT (20)

Tame cloud complexity with F# powered DSLs (build stuff)
Tame cloud complexity with F# powered DSLs (build stuff)Tame cloud complexity with F# powered DSLs (build stuff)
Tame cloud complexity with F# powered DSLs (build stuff)
 
Baseball Prediction Model on Tensorflow
Baseball Prediction Model on TensorflowBaseball Prediction Model on Tensorflow
Baseball Prediction Model on Tensorflow
 
The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.7 book - Part 53 of 196
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30
 
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsTips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query Pitfalls
 
A look at the CQL changes in 3.x (Benjamin Lerer, Datastax) | Cassandra Summi...
A look at the CQL changes in 3.x (Benjamin Lerer, Datastax) | Cassandra Summi...A look at the CQL changes in 3.x (Benjamin Lerer, Datastax) | Cassandra Summi...
A look at the CQL changes in 3.x (Benjamin Lerer, Datastax) | Cassandra Summi...
 
A look at the cql changes in 3.x
A look at the cql changes in 3.xA look at the cql changes in 3.x
A look at the cql changes in 3.x
 
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
 
Ropossum: A Game That Generates Itself
Ropossum: A Game That Generates ItselfRopossum: A Game That Generates Itself
Ropossum: A Game That Generates Itself
 
The Ring programming language version 1.5.4 book - Part 53 of 185
The Ring programming language version 1.5.4 book - Part 53 of 185The Ring programming language version 1.5.4 book - Part 53 of 185
The Ring programming language version 1.5.4 book - Part 53 of 185
 
The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 57 of 184
 
The Ring programming language version 1.5.3 book - Part 47 of 184
The Ring programming language version 1.5.3 book - Part 47 of 184The Ring programming language version 1.5.3 book - Part 47 of 184
The Ring programming language version 1.5.3 book - Part 47 of 184
 
League of Graphs
League of GraphsLeague of Graphs
League of Graphs
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88
 
Chainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereportChainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereport
 
Casting for not so strange actors
Casting for not so strange actorsCasting for not so strange actors
Casting for not so strange actors
 
03 objects
03 objects03 objects
03 objects
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
 
Chapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdfChapter3_Visualizations2.pdf
Chapter3_Visualizations2.pdf
 
360|iDev
360|iDev360|iDev
360|iDev
 

Kürzlich hochgeladen

Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 

Kürzlich hochgeladen (20)

Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 

Maverick sponsor LT

  • 1. Lightning Talk by presented by Naoki Aoyama (@aoiroaoino) in ScalaMatsuri 2016
  • 2. > whoami • Naoki Aoyama • Twitter: @AoiroAoino • GitHub: @aoiroaoino • Scala Exp: about 4 years • committer
  • 3. Product: 広告主 Audience It'swe! DSP SSP Media 広 告 出 稿 広 告 閲 覧 1. 広告リクエスト 2. bid request 3. 入札判断 4. bid response 5. 落札通知 6. 広告配信 afewsecs 100 ms or die! ※画像は http://jp.yamaha.com/products/network/downloads/tools/ より
  • 5.
  • 6. try { Tour of Lens
 in 3 minutes
  • 7. Simple data structure case class Player(name: String, age: Int) val player = Player("aoino", 25) scala> player.name res0: String = aoino scala> player.copy(age = 26) res1: Player = Player(aoino,26)
  • 8. Nested data structure case class Game(stageId: Int, player: Player) val game = Game(999, player) // get scala> game.player.name res6: String = aoino // set scala> game.copy( | player = game.player.copy( | name = "Aoyama" | ) | ) res7: Game = Game(999,Player(Aoyama,25))
  • 9. Copy method hell ... aaa.copy ( bbb = aaa.bbb.copy ( ccc = aaa.bbb.ccc.copy ( ddd = aaa.bbb.ccc.ddd.copy ( eee = aaa.bbb.ccc.ddd.eee.copy ( fff = aaa.bbb.ccc.ddd.eee.fff.copy ( ggg = ) ) ) ) ) )
  • 10. Motivation • We need the simple syntax like updating mutable objects
 -> want to avoid the copy method hell • We always want a "composability" and "reusability"
 -> compose of a getter/settter defined in
 the class is difficult
  • 12. What s the Lens? • something like a getter/setter such as Java • functional reference
  • 13. What s the Lens? getter: S => A e.g. player.name // => "aoino" setter: A => S => S e.g. player.copy(age = 26) // => Player("aoino",26)
  • 14. What s the Lens? case class Lens[S, A](get: S => A, set: A => S => S)
  • 15. Let s define some Lenses case class Lens[S, A](get: S => A, set: A => S => S) case class Player(name: String, age: Int) val _name: Lens[Player, String] = Lens( _.name, str => player => player.copy(name = str) ) val _age: Lens[Player, Int] = Lens( _.age, num => player => player.copy(age = num) )
  • 16. Give it a try scala> _name.get(player) res2: String = aoino scala> _name.set("Aoyama")(player) res3: Player = Player(Aoyama,25) scala> _age.get(player) res4: Int = 25 scala> _age.set(26)(player) res5: Player = Player(aoino,26)
  • 17. We need `composability` // in Function f: A => B g: B => C g compose f : A => C // in Lens sa: Lens[S, A] ab: Lens[A, B] sa compose ab : Lens[S, B] Note: Typically, Lenses `compose` is reverse compared to function.
  • 18. Let s define `compose` method case class Lens[S, A](get: S => A, set: A => S => S){ def compose[B](other: Lens[A, B]): Lens[S, B] = Lens( s => other.get(this.get(s)), b => s => this.set( other.set(b)(this.get(s)) )(s) ) }
  • 19. Give it a try val _player: Lens[Game, Player] = ... scala> (_player compose _name).get(game) res8: String = aoino scala> (_player compose _name).set("Aoyama")(game) res9: Game = Game(999,Player(Aoyama,25))
  • 20. (_bbb compose _ccc compose _ddd compose _eee compose _fff compose _ggg).set( )(aaa) Lens for the win!!
  • 21. Example in Maverick • We use Monocle in test codes.
  • 22. } finally { –Naoki Aoyama Lens is Awesome! }