3 Functional data structures

This chapter covers

  • Defining functional data structures using algebraic data types
  • Writing branching logic in a single expression
  • Sharing data using functional data structures
  • Using list recursion and generalizing to HOFs
  • Writing and generalizing pure functions
  • Implementing List and Tree

We said in chapter 1 that functional programs don’t update variables or modify mutable data structures. The emphasis on keeping variables immutable raises pressing questions: what sort of data structures can we use in functional programming, how do we define them in Kotlin, and how do we operate on them?

This chapter teaches the concept of functional data structures by writing our own implementations of a singly linked list and ...

Get Functional Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.