Slide 1

Slide 1 text

PABLO GUARDIOLA Building a DSL… In Kotlin

Slide 2

Slide 2 text

PABLO GUARDIOLA Building a DSL… In Kotlin

Slide 3

Slide 3 text

Building a DSL… In Kotlin With KΛTEGORY PABLO GUARDIOLA

Slide 4

Slide 4 text

key concepts @Guardiola31337

Slide 5

Slide 5 text

key concepts @Guardiola31337 Composable

Slide 6

Slide 6 text

key concepts @Guardiola31337 Composable Extensible

Slide 7

Slide 7 text

key concepts @Guardiola31337 Composable Extensible Testable

Slide 8

Slide 8 text

Composable Extensible Testable Integration w/ current frameworks key concepts @Guardiola31337

Slide 9

Slide 9 text

dsl @Guardiola31337

Slide 10

Slide 10 text

dsl (noun) “A computer programming language of limited expressiveness focused on a particular domain.” @Guardiola31337

Slide 11

Slide 11 text

dsl @Guardiola31337 Programming language

Slide 12

Slide 12 text

dsl @Guardiola31337 Programming language Language nature

Slide 13

Slide 13 text

dsl @Guardiola31337 Programming language Language nature Limited expressiveness

Slide 14

Slide 14 text

Programming language Language nature Limited expressiveness Domain focus dsl @Guardiola31337

Slide 15

Slide 15 text

uiagesturegen @Guardiola31337

Slide 16

Slide 16 text

uiagesturegen KΛTEGORY @Guardiola31337

Slide 17

Slide 17 text

usage @Guardiola31337

Slide 18

Slide 18 text

usage private fun composing(element: UiObject): Boolean { val actions = pinchOut(100, 50) .swipeDown(30) .swipeRight(30) .pinchOut(100, 50) .swipeUp(100) return actions.validate(element).hasCompletedCorrectly() } @Guardiola31337

Slide 19

Slide 19 text

@Guardiola31337

Slide 20

Slide 20 text

free dsl @Guardiola31337

Slide 21

Slide 21 text

free dsl @Guardiola31337 Define your algebra (a.k.a. operations)

Slide 26

Slide 26 text

free dsl @Guardiola31337 Define your algebra (a.k.a. operations) Lift everything to the context of free

Slide 29

Slide 29 text

lift fun ActionDSL.doubleTap(): ActionDSL = combine(this, com.pguardiola.uigesturegen.dsl.doubleTap()) fun doubleTap(): ActionDSL = FreeApplicative.liftF(GesturesDSL.DoubleTap) fun ActionDSL.pinchIn(percent: Int, steps: Int): ActionDSL = combine(this, com.pguardiola.uigesturegen.dsl.pinchIn(percent, steps)) fun pinchIn(percent: Int, steps: Int): ActionDSL = FreeApplicative.liftF(GesturesDSL.PinchOut(percent, steps)) // ... @Guardiola31337

Slide 30

Slide 30 text

lift fun ActionDSL.doubleTap(): ActionDSL = combine(this, com.pguardiola.uigesturegen.dsl.doubleTap()) fun doubleTap(): ActionDSL = FreeApplicative.liftF(GesturesDSL.DoubleTap) fun ActionDSL.pinchIn(percent: Int, steps: Int): ActionDSL = combine(this, com.pguardiola.uigesturegen.dsl.pinchIn(percent, steps)) fun pinchIn(percent: Int, steps: Int): ActionDSL = FreeApplicative.liftF(GesturesDSL.PinchOut(percent, steps)) // ... @Guardiola31337

Slide 31

Slide 31 text

free dsl @Guardiola31337 Define your algebra (a.k.a. operations) Lift everything to the context of free Provide semantics with the interpreter

Slide 33

Slide 33 text

interpreter fun loggingInterpreter(view: UiObject): FunctionK> = object : FunctionK> { override fun invoke(fa: GesturesDSLKind): EitherKind { println(fa) return safeInterpreterEither(view) as EitherKind } } @Guardiola31337

Slide 34

Slide 34 text

Define your algebra (a.k.a. operations) Lift everything to the context of free Provide semantics with the interpreter Execute the AST using the interpreter free dsl @Guardiola31337

Slide 38

Slide 38 text

usage private fun composingWithPlus(element: UiObject, pointers: List>): Boolean { val actions = pinchOut(75, 30) + swipeDown(30) + multiTouch(pointers) return actions.failFast(element).hasCompletedCorrectly() } @Guardiola31337

Slide 39

Slide 39 text

@Guardiola31337

Slide 40

Slide 40 text

takeaways @Guardiola31337

Slide 41

Slide 41 text

takeaways @Guardiola31337 Composable

Slide 42

Slide 42 text

takeaways @Guardiola31337 Composable Extensible

Slide 43

Slide 43 text

takeaways @Guardiola31337 Composable Extensible Reusable using different interpreters

Slide 44

Slide 44 text

Composable Extensible Reusable using different interpreters Integration w/ your current stack takeaways @Guardiola31337

Slide 45

Slide 45 text

thank you! PABLO GUARDIOLA

Slide 46

Slide 46 text

questions? PABLO GUARDIOLA

Slide 47

Slide 47 text

we’re hiring! mapbox.com/jobs PABLO GUARDIOLA

Slide 48

Slide 48 text

kategory.io https://github.com/Guardiola31337/uiagesturegen https://github.com/Kotlin/KEEP/pull/87 https://github.com/JorgeCastilloPrz/KotlinAndroidFunctional Domain-Specific Languages. Martin Fowler. Special shout out to Raúl Raja, Paco Estévez and Jorge Castillo references @Guardiola31337