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 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 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 Slide

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

    View 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 Slide

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

    View 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 Slide

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

    View 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 Slide

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

    View 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 Slide

  12. Type Constructors
    • Option
    • Either
    • Try

    View 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 Slide

  14. Monads, Functors, Applicatives

    View Slide

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

    View Slide