Exploring Kotlin Functional Programming
With chapters selected by John Guthrie
  • April 2019
  • ISBN 9781617297090
  • 116 pages
Exploring Kotlin Functional Programming
With chapters selected by John Guthrie
Functional programming is a reliable method for delivering what every developer wants to see: bug free code. Built around the same tenets as calculus, functional programming creates code that’s more stable, more consistent and easier to test. The new JVM language Kotlin has caught the attention of Java and Scala developers, in part because it embraces functional-style programming more naturally than standard Java. Google even supports Kotlin as a first-class Android language because of the simplicity it brings to mobile development. There’s never been a better time to take a close look at this hot new language for functional programming!

Exploring Kotlin Functional Programming is a fast, four-chapter introduction designed to give Java programmers a head-start on Kotlin and functional programming. The book sheds light on how functions work in both Kotlin and Java, and how to start implementing them in your code. When you’re done, you’ll have a leg-up on solving programming problems with functional techniques.
Table of Contents detailed table of contents

Introduction

Thinking functionally

18.1 Implementing and maintaining systems

18.1.1 Shared mutable data

18.1.2 Declarative programming

18.1.3 Why functional programming?

18.2 What’s functional programming?

18.2 What’s functional programming?

18.2.1 Functional-style Java

18.2.2 Referential transparency

18.2.3 Object-oriented vs. functional-style programming

18.2.4 Functional style in practice

18.3 Recursion vs. iteration

Summary

Programming with functions

3.1 What’s a function?

3.1.1 Understanding the relationship between two function sets

3.1.2 An overview of inverse functions in Kotlin

3.1.3 Working with partial functions

3.1.4 Understanding function composition

3.1.5 Using functions of several arguments

3.1.6 Currying functions

3.1.7 Using partially-applied functions

3.1.8 Functions have no effects

3.2 Functions in Kotlin

3.2.1 Understanding functions as data

3.2.2 Understanding data as functions

3.2.3 Using object constructors as functions

3.2.4 Using Kotlin’s fun functions

3.2.5 Using object notation versus functional notation

3.2.6 Using value functions

3.2.7 Using function references

3.2.8 Composing functions

3.2.9 Reusing functions

3.3 Advanced function features

3.3.1 What about functions of several arguments?

3.3.2 Applying curried functions

3.3.3 Implementing higher-order functions

3.3.4 Creating polymorphic HOFs

3.3.5 Using anonymous functions

3.3.6 Defining local functions

3.3.7 Implementing closures

3.3.8 Applying functions partially and automatic currying

3.3.9 Switching arguments of partially-applied functions

3.3.10 Declaring the identity function

3.3.11 Using the right types

Summary

Defining and calling functions

3.1 Creating collections in Kotlin

3.2 Making functions easier to call

3.2.1 Named arguments

3.2.2 Default parameter values

3.2.3 Getting rid of static utility classes: top-level functions and properties

3.3 Adding methods to other people’s classes: extension functions and properties

3.3.1 Imports and extension functions

3.3.2 Calling extension functions from Java

3.3.3 Utility functions as extensions

3.3.4 No overriding for extension functions

3.3.5 Extension properties

3.4 Working with collections: varargs, infix calls, and library support

3.4.1 Extending the Java Collections API

3.4.2 Varargs: functions that accept an arbitrary number of arguments

3.4.3 Working with pairs: infix calls and destructuring declarations

3.5 Working with strings and regular expressions

3.6 Making your code tidy: local functions and extensions

Summary

Solving common problems functionally

14.1 Assertions and data validation

14.1.1 Retries for functions and effects

14.2 Reading properties from a file

14.3 Loading the property file

14.3.1 Reading properties as strings

14.3.2 Producing better error messages

14.3.3 Reading properties as lists

14.3.4 Reading enum values

14.3.5 Reading properties of arbitrary types

14.4 Converting an imperative program: The XML reader

14.4.1 Step 1: The imperative solution

14.4.2 Step 2: Making an imperative program more functional

14.4.3 Step 3: Making the program even more functional

14.4.4 Step 4: Fixing the argument type problem

14.4.5 Step 5: Making the element-processing function a parameter

14.4.6 Step 6: Handling errors on element names

14.4.7 Step 7: Additional improvements to the formerly imperative code

What's inside

  • Thinking Functionally from Modern Java in Action by Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft
  • Programming with Functions from The Joy of Kotlin by Pierre-Yves Saumont
  • Defining and Calling Functions from Kotlin in Action by Dmitry Jemerov and Svetlana Isakova
  • Solving Common Problems Functionally from The Joy of Kotlin by Pierre-Yves Saumont

About the author

John Guthrie is an Advisory Solutions Architect with Pivotal Software, where he advises on transitioning from legacy applications to cloud native architectures. John has been working in software for decades across numerous countries; he currently resides in the Washington DC suburbs.

eBook $0.00 PDF only
Prices displayed in rupees will be charged in USD when you check out.

placing your order...

Don't refresh or navigate away from the page.

FREE domestic shipping on three or more pBooks