SlideShare a Scribd company logo
1 of 31
Download to read offline
HERDING {TYPES} WITH
SCALA #MACROS
Marina Sigaeva
Typelevel Summit
Copenhagen
besselfunction@mail.ru
@besseifunction
DATA => AEROSPIKE
//TODO FOR DRIVER
THE TYPE SAFE SOLUTION
.roadMap {
}
PEOPLE
(id,“Bob”)Key1
Key2 Bin1 Bin2 BinN
Int String Map
PEOPLE
(id,1234)Key1
Key3 Bin1 Bin2 BinN
Int Int Int
DS
DS DS
DS DS DS
data storing
package ru.tinkoff.example





object DBConnector {

…



database.put(new WritePolicy,

new Key("namespace", "setName", new StringValue("key1")),

Seq(new Bin("binName1", new StringValue("binValue"))):_*)



database.put(new WritePolicy,

new Key("namespace", "setName", new StringValue("key2")),

Seq(new Bin("binName2", new IntegerValue(2))):_*)



database.put(new WritePolicy,

new Key("namespace", "setName", new StringValue("key3")),

Seq(new Bin("binName3", new BooleanValue(true))):_*)



}
7 Key types
12 Bin types
Java
Byte
Int
Long
HList
Case
class
Map
Short Boolean
Aerospike
val hList = 123 :: "abc" :: true :: HNil
+———————————————————————-+
| hList |
+———————————————————————-+
| MAP('{"0":123, "1":"abc", "2":1}') |
+———————————————————————-+
val bunny = Bunny("Max", 1)
+—————————————————————-—-+
| bunny |
+———————————————————————+
| MAP('{"name":"Max", "age":1}') |
+———————————————————————+
getting data
get(policy: BatchPolicy, listener: BatchSequenceListener, records: util.List[Ba
get(policy: BatchPolicy, listener: RecordSequenceListener, keys: Array[Key], b
get(policy: BatchPolicy, listener: RecordArrayListener, keys: Array[Key], binN
get(policy: BatchPolicy, listener: RecordSequenceListener, keys: Array[Key])
get(policy: BatchPolicy, listener: RecordArrayListener, keys: Array[Key])

get(policy: Policy, listener: RecordListener, key: Key, binNames: String *)

get(policy: Policy, listener: RecordListener, key: Key)

get(policy: BatchPolicy, listener: BatchListListener, records: util.List[BatchRe
get(policy: BatchPolicy, records: util.List[BatchRead])

get(policy: BatchPolicy, keys: Array[Key], binNames: String *)

get(policy: BatchPolicy, keys: Array[Key])

get(policy: Policy, key: Key, binNames: String *)

get(policy: Policy, key: Key)
m
m
m
m
m
m
m
m
m
m
m
m
m
public final class Record {



public final Map<String,Object> bins;



public final int generation;

	 

public final int expiration;



…



}
DS
db.get[List[Bunny]](List("Max", "Peter", "Ruby"))
WHAT DOES THE DRIVER
HAVE TO DO?
MORE CONCISE API
TAKE CARE OF SERIALIZATION
TO WORK OUT OF THE BOX
implementation
def call[K, B](action: Action, key: K, bin: B)

(implicit kw: KeyWrapper[K],

bw: BinWrapper[B],

pw: Option[WritePolicy] = None) = ???
call(Put, "key", "abcd")
def call[K, B](action: Action, key: K, bin: B)

(implicit kw: KeyWrapper[K],

bw: BinWrapper[B],

pw: Option[WritePolicy] = None) = ???
call(Put, "key", "abcd")(
new KeyWrapper[String]{},

new BinWrapper[String]{}, None)
trait BinWrapper[B] {
def apply(v: B): Bin = new Bin("name", toValue(v))
def toValue(v: B): Value = v match {
case s: String => new StringValue(s)
case h: HList => new MapValue(toMap(h))
case _ => throw new Exception("Wrong type")
}
def apply(r: Record): Map[String, B] =
r.bins.collect {
case (name, something) =>
name -> fetch(something)
}.toMap
def fetch(donkey: Any): B
}
new BinWrapper[String] {

def apply(v: String): Bin = ???

} 



new BinWrapper[Int] {

def apply(v: Int): Bin = ???

}
new BinWrapper[ ] {

def apply(v: ): Bin = ???

}
Macros
Context
Symbol Type Tree
import c.universe._



Apply(

Select(Literal(Constant(1)), TermName("$plus")), 

List(Literal(Constant(1)))

)
q"1 + 1"
1 + 1
object BinWrapper {



implicit def materialize[B]: BinWrapper[B] = macro matBin[B]



def matBin[B: c.WeakTypeTag](c: blackbox.Context): c.Expr[BinWrapper[B]] = {

import c.universe._



val tpe = weakTypeOf[B]



val imports = q""" import …"""
val fetchValue = ???


c.Expr[BinWrapper[B]] {

q""" $imports

new BinWrapper[$tpe] { 

$fetchValue 

}""" 

}

}

}
val tpe = weakTypeOf[B]



val fetchValue = tpe match {
case t if t =:= weakTypeOf[String] =>
q""" def fetch(any: Any): $tpe = any match {
case v: String => v
case _ => throw new Exception("Wrong type")
} """
case t if isHList(t) =>
q""" def fetch(any: Any): $tpe = any match {
case mv: MapValue => mv.getObject match {
case m: Map[String, Any] =>
parse(m).toHList[$tpe].getOrElse{}
case _ => throw new Exception("Wrong type")
}
case _ => throw new Exception("Wrong type")
} """

...
}
object Usage {

insertData(materialize[Int::Boolean::HNil])

}
import com.aerospike.client.{Bin, Value};
import shapeless._;
{
final class $anon extends BinWrapper[shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]]] {
def <init>() = {
super.<init>();
()
};
def fetch(any: Any): shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]] = any match {
case (mv @ (_: MapValue)) => mv.getObject match {
case (m @ (_: Map[String, Any])) =>
parse(m).toHList[shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]]].getOrElse{}
case _ => throw new Exception("Wrong type")
}
case _ => throw new Exception("Wrong type")
}
};
new $anon()
}
object Usage {



insertData({
})
}
import com.aerospike.client.{Bin, Value};
import shapeless._;
{
final class $anon extends BinWrapper[shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]]] {
def <init>() = {
super.<init>();
()
};
def fetch(any: Any): shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]] = any match {
case (mv @ (_: MapValue)) => mv.getObject match {
case (m @ (_: Map[String, Any])) =>
parse(m).toHList[shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]]].getOrElse{}
case _ => throw new Exception("Wrong type")
}
case _ => throw new Exception("Wrong type")
}
};
new $anon()
}
} imports
def fetch: Any => HL
type HL = Int::Boolean::HNil
object Usage {



insertData({
})
}
BinWrapper[String]
BinWrapper[Int]
BinWrapper[HList]
BinWrapper[Bunny]
def writeBin[B](b: B)

(implicit bw: BinWrapper[B]): Bin = bw(b)





val asMap = new BinWrapper[Bunny] { }

val asJson = new BinWrapper[Bunny] { … }



writeBin("b1", Bunny("Max", 4))(asMap)

writeBin("b2", Bunny("Ruby", 2))(asJson)
aerospike-scala-dsl
github.com/DanyMariaLee/aerospike-scala
"aerospike-scala"

"aerospike-scala-proto"
"aerospike-scala-example"
"ru.tinkoff"
"1.1.14"%% %{ }
aerospike.com/launchpad/

More Related Content

What's hot

Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemWprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemSages
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境とTakeshi Arabiki
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeMongoDB
 
Rデバッグあれこれ
RデバッグあれこれRデバッグあれこれ
RデバッグあれこれTakeshi Arabiki
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveEugene Zharkov
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Tsuyoshi Yamamoto
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲームNoritada Shimizu
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot Nidhi Chauhan
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots DeepAnshu Sharma
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4Jan Berdajs
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programsKaruppaiyaa123
 

What's hot (20)

Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemWprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境と
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Rデバッグあれこれ
RデバッグあれこれRデバッグあれこれ
Rデバッグあれこれ
 
Angular Refactoring in Real World
Angular Refactoring in Real WorldAngular Refactoring in Real World
Angular Refactoring in Real World
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
ECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScriptECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScript
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
Python GC
Python GCPython GC
Python GC
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 

Similar to Typelevel summit

TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Un dsl pour ma base de données
Un dsl pour ma base de donnéesUn dsl pour ma base de données
Un dsl pour ma base de donnéesRomain Lecomte
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyYasuharu Nakano
 
Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Evgeny Borisov
 
Что нам готовит грядущий C#7?
Что нам готовит грядущий C#7?Что нам готовит грядущий C#7?
Что нам готовит грядущий C#7?Andrey Akinshin
 
Lecture 4: Data Types
Lecture 4: Data TypesLecture 4: Data Types
Lecture 4: Data TypesEelco Visser
 
Data Types and Processing in ES6
Data Types and Processing in ES6Data Types and Processing in ES6
Data Types and Processing in ES6m0bz
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. StreamsDEVTYPE
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systemsleague
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapHoward Lewis Ship
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in HaskellHiromi Ishii
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala LanguageAshal aka JOKER
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montageKris Kowal
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kirill Rozov
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objectsHusain Dalal
 

Similar to Typelevel summit (20)

Scala best practices
Scala best practicesScala best practices
Scala best practices
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Un dsl pour ma base de données
Un dsl pour ma base de donnéesUn dsl pour ma base de données
Un dsl pour ma base de données
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
 
Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2
 
Что нам готовит грядущий C#7?
Что нам готовит грядущий C#7?Что нам готовит грядущий C#7?
Что нам готовит грядущий C#7?
 
Lecture 4: Data Types
Lecture 4: Data TypesLecture 4: Data Types
Lecture 4: Data Types
 
Data Types and Processing in ES6
Data Types and Processing in ES6Data Types and Processing in ES6
Data Types and Processing in ES6
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in Haskell
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language
 
ddd+scala
ddd+scaladdd+scala
ddd+scala
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 

Recently uploaded

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniquesugginaramesh
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 

Recently uploaded (20)

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniques
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 

Typelevel summit

  • 1. HERDING {TYPES} WITH SCALA #MACROS Marina Sigaeva Typelevel Summit Copenhagen besselfunction@mail.ru @besseifunction
  • 2. DATA => AEROSPIKE //TODO FOR DRIVER THE TYPE SAFE SOLUTION .roadMap { }
  • 5. DS
  • 9. package ru.tinkoff.example
 
 
 object DBConnector {
 …
 
 database.put(new WritePolicy,
 new Key("namespace", "setName", new StringValue("key1")),
 Seq(new Bin("binName1", new StringValue("binValue"))):_*)
 
 database.put(new WritePolicy,
 new Key("namespace", "setName", new StringValue("key2")),
 Seq(new Bin("binName2", new IntegerValue(2))):_*)
 
 database.put(new WritePolicy,
 new Key("namespace", "setName", new StringValue("key3")),
 Seq(new Bin("binName3", new BooleanValue(true))):_*)
 
 } 7 Key types 12 Bin types Java
  • 11. val hList = 123 :: "abc" :: true :: HNil +———————————————————————-+ | hList | +———————————————————————-+ | MAP('{"0":123, "1":"abc", "2":1}') | +———————————————————————-+ val bunny = Bunny("Max", 1) +—————————————————————-—-+ | bunny | +———————————————————————+ | MAP('{"name":"Max", "age":1}') | +———————————————————————+
  • 13. get(policy: BatchPolicy, listener: BatchSequenceListener, records: util.List[Ba get(policy: BatchPolicy, listener: RecordSequenceListener, keys: Array[Key], b get(policy: BatchPolicy, listener: RecordArrayListener, keys: Array[Key], binN get(policy: BatchPolicy, listener: RecordSequenceListener, keys: Array[Key]) get(policy: BatchPolicy, listener: RecordArrayListener, keys: Array[Key])
 get(policy: Policy, listener: RecordListener, key: Key, binNames: String *)
 get(policy: Policy, listener: RecordListener, key: Key)
 get(policy: BatchPolicy, listener: BatchListListener, records: util.List[BatchRe get(policy: BatchPolicy, records: util.List[BatchRead])
 get(policy: BatchPolicy, keys: Array[Key], binNames: String *)
 get(policy: BatchPolicy, keys: Array[Key])
 get(policy: Policy, key: Key, binNames: String *)
 get(policy: Policy, key: Key) m m m m m m m m m m m m m
  • 14. public final class Record {
 
 public final Map<String,Object> bins;
 
 public final int generation;
 
 public final int expiration;
 
 …
 
 } DS
  • 16. WHAT DOES THE DRIVER HAVE TO DO? MORE CONCISE API TAKE CARE OF SERIALIZATION TO WORK OUT OF THE BOX
  • 18. def call[K, B](action: Action, key: K, bin: B)
 (implicit kw: KeyWrapper[K],
 bw: BinWrapper[B],
 pw: Option[WritePolicy] = None) = ??? call(Put, "key", "abcd")
  • 19. def call[K, B](action: Action, key: K, bin: B)
 (implicit kw: KeyWrapper[K],
 bw: BinWrapper[B],
 pw: Option[WritePolicy] = None) = ??? call(Put, "key", "abcd")( new KeyWrapper[String]{},
 new BinWrapper[String]{}, None)
  • 20. trait BinWrapper[B] { def apply(v: B): Bin = new Bin("name", toValue(v)) def toValue(v: B): Value = v match { case s: String => new StringValue(s) case h: HList => new MapValue(toMap(h)) case _ => throw new Exception("Wrong type") } def apply(r: Record): Map[String, B] = r.bins.collect { case (name, something) => name -> fetch(something) }.toMap def fetch(donkey: Any): B }
  • 21. new BinWrapper[String] {
 def apply(v: String): Bin = ???
 } 
 
 new BinWrapper[Int] {
 def apply(v: Int): Bin = ???
 } new BinWrapper[ ] {
 def apply(v: ): Bin = ???
 }
  • 24. object BinWrapper {
 
 implicit def materialize[B]: BinWrapper[B] = macro matBin[B]
 
 def matBin[B: c.WeakTypeTag](c: blackbox.Context): c.Expr[BinWrapper[B]] = {
 import c.universe._
 
 val tpe = weakTypeOf[B]
 
 val imports = q""" import …""" val fetchValue = ??? 
 c.Expr[BinWrapper[B]] {
 q""" $imports
 new BinWrapper[$tpe] { 
 $fetchValue 
 }""" 
 }
 }
 }
  • 25. val tpe = weakTypeOf[B]
 
 val fetchValue = tpe match { case t if t =:= weakTypeOf[String] => q""" def fetch(any: Any): $tpe = any match { case v: String => v case _ => throw new Exception("Wrong type") } """ case t if isHList(t) => q""" def fetch(any: Any): $tpe = any match { case mv: MapValue => mv.getObject match { case m: Map[String, Any] => parse(m).toHList[$tpe].getOrElse{} case _ => throw new Exception("Wrong type") } case _ => throw new Exception("Wrong type") } """
 ... }
  • 27. import com.aerospike.client.{Bin, Value}; import shapeless._; { final class $anon extends BinWrapper[shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]]] { def <init>() = { super.<init>(); () }; def fetch(any: Any): shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]] = any match { case (mv @ (_: MapValue)) => mv.getObject match { case (m @ (_: Map[String, Any])) => parse(m).toHList[shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]]].getOrElse{} case _ => throw new Exception("Wrong type") } case _ => throw new Exception("Wrong type") } }; new $anon() } object Usage {
 
 insertData({ }) }
  • 28. import com.aerospike.client.{Bin, Value}; import shapeless._; { final class $anon extends BinWrapper[shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]]] { def <init>() = { super.<init>(); () }; def fetch(any: Any): shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]] = any match { case (mv @ (_: MapValue)) => mv.getObject match { case (m @ (_: Map[String, Any])) => parse(m).toHList[shapeless.::[Int,shapeless.::[Boolean,shapeless.HNil]]].getOrElse{} case _ => throw new Exception("Wrong type") } case _ => throw new Exception("Wrong type") } }; new $anon() } } imports def fetch: Any => HL type HL = Int::Boolean::HNil object Usage {
 
 insertData({ }) }
  • 30. def writeBin[B](b: B)
 (implicit bw: BinWrapper[B]): Bin = bw(b)
 
 
 val asMap = new BinWrapper[Bunny] { }
 val asJson = new BinWrapper[Bunny] { … }
 
 writeBin("b1", Bunny("Max", 4))(asMap)
 writeBin("b2", Bunny("Ruby", 2))(asJson)