Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DroidJam India '18 Arrow and functional programming for Kotlin developers

DroidJam India '18 Arrow and functional programming for Kotlin developers

In this talk, I’ll be describing Functional Programming in Kotlin, and Arrow library for Android Developers, taking some extracts from my book Functional Kotlin. Functional Programming is the most trendy thing nowadays as well as the most evolved paradigm.

Rivu Chakraborty

July 13, 2018
Tweet

More Decks by Rivu Chakraborty

Other Decks in Programming

Transcript

  1. Functional Programming in Kotlin -
    Android
    DroidJam India 2018
    Rivu Chakraborty

    View full-size slide

  2. Rivu Chakraborty
    • A learner
    • Sr. Software Engineer (Android) @ Indus Net Technologies Pvt. Ltd.
    • Community Lead: GDG Kolkata, Kotlin Kolkata
    • Instructor @ Caster.io
    • Author – Reactive Programming in Kotlin
    • Author – Functional Kotlin
    • Author – Coroutines for Android Developers (WIP)
    • Author – Hands on Data Structures & Algorithms in Kotlin (WIP)
    @rivuchakraborty

    View full-size slide

  3. 50% off on EBook
    15% off on Print Book
    RPKFK50
    RPKFK15
    https://www.packtpub.com/application-
    development/reactive-programming-kotlin
    https://www.packtpub.com/application-
    development/functional-kotlin

    View full-size slide

  4. What is Functional Programming?
    • Representation of Mathematical Function
    State
    Traditional / Imperative / Von
    Neuman Style
    Input Output

    View full-size slide

  5. Why Functional Programming
    • Modulation of code
    • FP encourages safe ways of programming through Immutability &
    Pure Functions
    • Testing becomes easier
    • Programs are easier to read.

    View full-size slide

  6. What are Functional Languages?
    • Any language that gives support to Functions as first class citizens
    are called Functional Language.

    View full-size slide

  7. Pure Functions
    • Same return value for same input, can be cached
    • Doesn’t modify anything outside function scope (No side effects)
    fun square(n:Int):Int {
    return n*n
    }

    View full-size slide

  8. Immutability
    • Immutability != Read Only
    • Kotlin doesn’t force Immutability, it encourages Immutability
    • The val keyword doesn’t guarantees immutability

    View full-size slide

  9. Lambda
    • To be generic, lambda or lambda expressions generally means anonymous functions,
    that is, functions without names, which can be assigned to variables, passed as
    arguments, or returned from another function
    fun invokeSomeStuff(doSomeStuff:()->Unit) {
    doSomeStuff()
    }
    fun main(args: Array) {
    invokeSomeStuff {
    println("doSomeStuff called");
    }
    }

    View full-size slide

  10. Arrow
    • Functional companion to Kotlin’s Standard Library

    View full-size slide

  11. Type Constructors
    • Type Constructors are mainly theoretical concept. It’s not a Kotlin
    class constructor building a type.
    • We can reference Generic Parameterised Types as Type
    Constructors
    List
    Map
    Option
    Either

    View full-size slide

  12. Type Constructors
    • Option
    • Either
    • Try

    View full-size slide

  13. Type Classes
    • Type classes encode behaviour
    • You can use typeclasses as a DSL to access new free functionality
    for an existing type, or treat them as an abstraction placeholder
    for any one type that can implement the typeclass. The extension
    functions are scoped within the typeclass so they do not pollute
    the global namespace!
    • Example: Monads, Functors, Applicatives

    View full-size slide

  14. Monads, Functors, Applicatives

    View full-size slide

  15. This Photo by Unknown Author is licensed under CC BY-NC-ND
    @rivuchakraborty
    Rivu Chakraborty

    View full-size slide