From Objects to Functions: Build Your Software Faster and Safer with Functional Programming and Kotlin

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Build applications quicker and with less effort using functional programming and Kotlin. Learn by building a complete application, from gathering requirements to delivering a microservice architecture following functional programming principles. Learn how to implement CQRS and EventSourcing in a functional way to map the domain into code better and to keep the cost of change low for the whole application life cycle. If you're curious about functional programming or you are struggling with how to put it into practice, this guide will help you increase your productivity composing small functions together instead of creating fat objects. Switching to the functional paradigm isn't easy when you're used to object-oriented programming. You need more than just lambdas and mapping over collections to get a declarative style and disentangle the state from the computations. Use transformations and compositions to help you write less code with better results. Boost your productivity and harness the power of functional programming by creating real-world applications rather than focusing on theoretical concepts. Work through a series of short exercises to find and compose pure functions, and create data structures that work like algebra. Get rid of mutable state in your software to eliminate the main source of bugs. Apply CQRS and EventSourcing patterns to translate stakeholder requirements into functional design and then into code. See how Kotlin's easy-to-learn syntax and functional-friendly approach make it a great option for a pragmatic language that integrates well with existing Java code and libraries. Leverage functional programming to build and deliver robust applications in less time and with fewer defects. What You Need: The code in this book is designed to allow you to build your application from scratch on Windows, Mac and Linux. You will need a recent IDE, we recommend IntelliJ Community Edition, and Kotlin 1.3.x or later.

Author(s): Uberto Barbini
Edition: 1
Publisher: Pragmatic Bookshelf
Year: 2023

Language: English
Commentary: Publisher's PDF
Pages: 468
City: Raleigh, NC
Tags: Functional Programming; Monitoring; Application Development; Monads; Functors; Unit Testing; Error Handling; Event-Driven Programming; Testing; Kotlin; Data Validation

Cover
Table of Contents
Acknowledgments
Preface
About This Book
Introduction: Why Functional Programming?
Why Kotlin?
What Functional Programming Is Really About
Unlearning Object-Oriented Programming
Recap
1. Preparing a New Application
Defining the Sample Application
Zettai: An Innovative To-Do List Application
Letting Tests Guide Development
Setting Up the Project
Making Unit Tests Functional
Recap
Exercises
2. Handling HTTP Using Functions
Kicking Off the Project
Serving HTML Pages Functionally
Starting Zettai
Designing with Arrows
Serving Lists from a Map
Recap
Exercises
3. Defining the Domain and Testing It
Improving the Acceptance Tests
Using Higher-Order Functions
Separating the Domain from the Infrastructure
Driving the Tests from the Domain
Converting DDT to Pesticide
Recap
Exercises
4. Modeling the Domain and the Adapters
Starting a New Story to Modify a List
Using Functional Dependency Injection
Debugging Functional Code
Functional Domain Modeling
Recap
Exercises
5. Using Events to Modify the State
Creating and Displaying To-Do Lists
Storing the State Changes
Unleashing the Power of Recursion
Folding Events
Discovering the Monoid
Recap
Exercises
6. Executing Commands to Generate Events
Creating a New List
Using Commands to Change the State
Modeling the Domain with States and Events
Writing Functional State Machines
Connecting the Hub
Understanding Commands and Events Better
Recap
Exercises
7. Handling Errors Functionally
Handling Errors Better
Learning Functors and Categories
Using Functors to Handle Errors
Working with Outcomes
Recap
Exercises
8. Using Functors to Project Events
Projecting Our Events
Running Queries on Functors
Thinking in Terms of Functors
Command and Query Responsibility Segregation (CQRS)
Recap
Exercises
9. Using Monads to Persist Data Safely
Persisting Safely
Connecting to the Database with Kotlin
Accessing Remote Data in a Functional Way
Exploring the Power of Monads
Recap
Exercises
10. Reading Context to Handle Commands
Accessing the Database with Monads
Handling Commands with Context Reader
Querying Projections from Database
Modeling the Domain with Event Sourcing
Recap
Exercises
11. Validating Data with Applicatives
Renaming a List
Transforming Functions with Two Parameters
Validating with Validations
Combining Applicative Functors
Improving the User Interface
Recap
Exercises
12. Monitoring and Functional JSON
Monitoring Our Application
Structured Logging
Making JSON Functional
Meeting Profunctors
Logging Database Calls
Recap
Exercises
13. Designing a Functional Architecture
Chasing Simplicity
Designing a Whole System
Translating to Code
Final Considerations
Exercises
A1. What Is Functional Programming?
The Origins
Achieving Referential Transparency
Think in Morphisms
Recap
A2. About Functional Kotlin
Setting Up Kotlin
Kotlin 101
Exploring the Kotlin Type System
A3. A Pinch of Theory
Category Theory
It’s All About Morphisms
Types over Types
Functors Are Mappers
The Mysterious Monad
Connecting Everything with Yoneda
Conclusion
A4. Additional Resources
Programming
Category Theory
Bibliography
Index
– SYMBOLS –
– A –
– B –
– C –
– D –
– E –
– F –
– G –
– H –
– I –
– J –
– K –
– L –
– M –
– N –
– O –
– P –
– Q –
– R –
– S –
– T –
– U –
– V –
– W –
– Y –
– Z –