Appendix B. Exercise solutions
B.1 Before you proceed to the solutions
This appendix contains all the solutions to the exercises in the book. Please make the best attempt possible to do the exercises prior to skipping here to get the answers. The book is written in such a way that doing the exercises is a crucial part of your learning experience. Each exercise builds on the knowledge gained from the previous one. Please only use this appendix to verify your answers or to help you if you are absolutely stuck.
B.2 Getting started with functional programming
Exercise 2.1
fun fib(i: Int): Int { tailrec fun go(cnt: Int, curr: Int, nxt: Int): Int = if (cnt == 0) curr else go(cnt - 1, nxt, curr + nxt) return go(i, 0, 1) }
Exercise 2.2
val <T> ...
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.