My Account Log in

1 option

Grokking Functional Programming.

O'Reilly Online Learning: Academic/Public Library Edition Available online

View online
Format:
Book
Author/Creator:
Płachta, Michał.
Language:
English
Subjects (All):
Functional programming (Computer science).
Object-oriented programming (Computer science).
Physical Description:
1 online resource (430 pages)
Place of Publication:
New York : Manning Publications Co. LLC, 2022.
Summary:
There's no need to fear going functional! This friendly, lively, and engaging guide is perfect for any perplexed programmer. It lays out the principles of functional programming in a simple and concise way that will help you grok what FP is really all about. In Grokking Functional Programming you will learn: Designing with functions and types instead of objects Programming with pure functions and immutable values Writing concurrent programs using the functional style Testing functional programs Multiple learning approaches to help you grok each new concept If you've ever found yourself rolling your eyes at functional programming, this is the book for you. Open up Grokking Functional Programming and you'll find functional ideas mapped onto what you already know as an object-oriented programmer. The book focuses on practical aspects from page one. Hands-on examples apply functional principles to everyday programming tasks like concurrency, error handling, and improving readability. Plus, puzzles and exercises let you think and practice what you're learning. You'll soon reach an amazing "aha" moment and start seeing code in a completely new way. About the Technology Finally, there's an easy way to learn functional programming! This unique book starts with the familiar ideas of OOP and introduces FP step-by-step using relevant examples, engaging exercises, and lots of illustrations. You'll be amazed at how quickly you'll start seeing software tasks from this valuable new perspective. About the Book Grokking Functional Programming introduces functional programming to imperative developers. You'll start with small, comfortable coding tasks that expose basic concepts like writing pure functions and working with immutable data. Along the way, you'll learn how to write code that eliminates common bugs caused by complex distributed state. You'll also explore the FP approach to IO, concurrency, and data streaming. By the time you finish, you'll be writing clean functional code that's easy to understand, test, and maintain. What's Inside Designing with functions and types instead of objects Programming with pure functions and immutable values Writing concurrent programs using the functional style Testing functional programs About the Reader For developers who know an object-oriented language. Examples in Java and Scala. About the Author Michał Płachta is an experienced software developer who regularly speaks and writes about creating maintainable applications. He blogs at michalplachta.com. Quotes The go-to book for functional programming! - Srihari Sridharan, Thoughtworks The writing is imaginative and creative, so it's a fun reading experience. - Gianluigi Spagnuolo, Exein Perfect! A new way of thinking about how we code. - Gustavo Gomes, Troido A fresh way to grasp the core of functional programming! Practical and totally focused. - Ubaldo Pescatore, PagoPA I finally understand why functional programming matters and how I can adopt it in my daily practices. - Sander Rosel, JUUN Software.
Contents:
Intro
inside front cover
Grokking Functional Programming
Copyright
Dedication
contents
Front matter
preface
acknowledgments
about this book
about the author
Part 1. The functional toolkit
1 Learning functional programming
Perhaps you picked up this book because ...
What do you need to know before we start?
What do functions look like?
Meet the function
When the code lies ...
Imperative vs. declarative
Coffee break: Imperative vs. declarative
Coffee break explained: Imperative vs. declarative
How useful is learning functional programming?
Leaping into Scala
Practicing functions in Scala
Getting your tools ready
Getting to know the REPL
Writing your first functions!
How to use this book
Summary
2 Pure functions
Why do we need pure functions?
Coding imperatively
Breaking the code
Passing copies of the data
Breaking the code . . . again
Recalculating instead of storing
Focusing on the logic by passing the state
Where did the state go?
The difference between impure and pure functions
Coffee break: Refactoring to a pure function
Coffee break explained: Refactoring to a pure function
In pure functions we trust
Pure functions in programming languages
Difficulty of staying pure ...
Pure functions and clean code
Coffee break: Pure or impure?
Coffee break explained: Pure or impure?
Using Scala to write pure functions
Practicing pure functions in Scala
Testing pure functions
Coffee break: Testing pure functions
Coffee break explained: Testing pure functions
3 Immutable values
The fuel for the engine
Another case for immutability
Can you trust this function?
Mutability is dangerous
Functions that lie ... again
Fighting mutability by working with copies.
Coffee break: Getting burned by mutability
Coffee break explained: Getting burned by mutability
Introducing shared mutable state
State's impact on programming abilities
Dealing with the moving parts
Dealing with the moving parts using FP
Immutable values in Scala
Building our intuition about immutability
Coffee break: The immutable String API
Coffee break explained: The immutable String API
Hold on ... Isn't this bad?
Purely functional approach to shared mutable state
Practicing immutable slicing and appending
4 Functions as values
Implementing requirements as functions
Impure functions and mutable values strike back
Using Java Streams to sort the list
Function signatures should tell the whole story
Changing requirements
We just pass the code around!
Using Java's Function values
Using the Function syntax to deal with code duplication
Passing user-defined functions as arguments
Coffee break: Functions as parameters
Coffee break explained: Functions as parameters
Problems with reading functional Java
Passing functions in Scala
Deep dive into sortBy
Signatures with function parameters in Scala
Passing functions as arguments in Scala
Practicing function passing
Embracing declarative programming
Passing functions to custom-made functions
Small functions and their responsibilities
Passing functions inline
Coffee break: Passing functions in Scala
Coffee break explained: Passing functions in Scala
What else can we achieve just by passing functions?
Applying a function to each element of a list
Applying a function to each element of a list using map
Getting to know map
Practicing map
Learn once, use everywhere
Returning parts of the list based on a condition
Returning parts of the list using filter.
Getting to know filter
Practicing filter
Our journey so far ...
Don't repeat yourself?
Is my API easy to use?
Adding a new parameter is not enough
Functions can return functions
Using functions that can return functions
Functions are values
Coffee break: Returning functions
Coffee break explained: Returning functions
Designing functional APIs
Iterative design of functional APIs
Returning functions from returned functions *
How to return functions from returned functions *
Using the flexible API built with returned functions
Using multiple parameter lists in functions
We have been currying!
Practicing currying
Programming by passing function values
Reducing many values into a single value
Reducing many values into a single one using foldLeft
Getting to know foldLeft
foldLeft must-knows
Practicing foldLeft
Modeling immutable data
Using product types with higher-order functions
More concise syntax for inline functions
Part 2. Functional programs
5 Sequential programs
Writing pipeline-based algorithms
Composing larger programs from smaller pieces
The imperative approach
flatten and flatMap
Practical use case of using more flatMaps
flatMap and changing the size of the list
Coffee break: Dealing with lists of lists
Coffee break explained: Dealing with lists of lists
Chained flatMaps and maps
Nested flatMaps
Values that depend on other values
Practicing nested flatMaps
A better syntax for nested flatMaps
For comprehensions to the rescue!
Coffee break: flatMaps vs. for comprehensions
Coffee break explained: flatMaps vs. for comprehensions
Getting to know for comprehensions
It's not the for you are looking for!
Inside a for comprehension
More sophisticated for comprehensions.
Checking all combinations using a for comprehension
Filtering techniques
Coffee break: Filtering techniques
Coffee break explained: Filtering techniques
Looking for a greater abstraction
Comparing map, foldLeft, and flatMap
Using for comprehensions with Sets
Using for comprehensions with many types
Practicing for comprehensions
Defining for comprehensions ... again
Using for comprehensions with noncollection types
Avoiding nulls: Option type
Parsing as a pipeline
Coffee break: Parsing with Option
Coffee break explained: Parsing with Option
6 Error handling
Handling lots of different errors, gracefully
Is it even possible to handle them all?
Sort the list of TV shows by their running time
Implementing the sorting requirement
Dealing with data coming from the outside world
Functional design: Building from small blocks
Parsing Strings into immutable objects
Parsing a List is just parsing one element
Parsing a String into a TvShow
What about potential errors?
Is returning null a good idea?
How do we handle potential errors more gracefully?
Implementing a function that returns an Option
Option forces us to handle possible errors
Building from small blocks
Functional design is building from small blocks
Writing a small, safe function that returns an Option
Functions, values, and expressions
Practicing safe functions that return Options
How do errors propagate?
Values represent errors
Option, for comprehensions, and checked exceptions ...
What about checked exceptions?
Conditional recovery
Conditional recovery using the imperative style
Conditional recovery using the functional style
Checked exceptions don't compose-Options do!
How does orElse work?
Practicing functional error handling.
Functions compose, even in the presence of errors
Compiler reminds us that errors need to be covered
Compilation errors are good for us!
Transforming a List of Options into a flat List
Let the compiler be our guide ...
... but let's not trust the compiler too much!
Coffee break: Error-handling strategies
Coffee break explained: Error-handling strategies
Two different error-handling strategies
All-or-nothing error-handling strategy
Folding a List of Options into an Option of a List
We now know how to handle multiple possible errors!
How to know what failed
We need to convey error details in the return value
Conveying error details using Either
Refactoring to Either
Returning an Either instead of an Option
Practicing safe functions that return Either
What we learned about Option works with Either
Coffee break: Error handling using Either
Coffee break explained: Error handling using Either
Working with Option/Either
7 Requirements as types
Modeling data to minimize programmers' mistakes
Well-modeled data can't lie
Designing using what we know so far (which is primitive types)
Using data modeled as primitive types
Coffee break: The pain of primitive types
Coffee break explained: The pain of primitive types
Problems with the primitive type approach to modeling
Using primitive types makes our jobs harder!
Newtypes protect against misplaced parameters
Using newtypes in data models
Practicing newtypes
Making sure only valid data combinations are possible
Modeling possibility of absence in your data
Changes in the model force changes in the logic
Using data modeled as Options in your logic
Higher-order functions for the win!
There is probably a higher-order function for that!
Coffee break: forall/exists/contains.
Coffee break explained: forall/exists/contains.
Notes:
Includes index.
Description based on publisher supplied metadata and other sources.
ISBN:
9781638350071
1638350078
OCLC:
1363828225

The Penn Libraries is committed to describing library materials using current, accurate, and responsible language. If you discover outdated or inaccurate language, please fill out this feedback form to report it and suggest alternative language.

My Account

Shelf Request an item Bookmarks Fines and fees Settings

Guides

Using the Library Catalog Using Articles+ Library Account