Home > Store

Functional and Concurrent Programming: Core Concepts and Features

Register your product to gain access to bonus material or receive a coupon.

Functional and Concurrent Programming: Core Concepts and Features

Best Value Purchase

Book + eBook Bundle

  • Your Price: $68.29
  • List Price: $117.98
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

More Purchase Options

Book

  • Your Price: $47.99
  • List Price: $59.99
  • Usually ships in 24 hours.

eBook

  • Your Price: $46.39
  • List Price: $57.99
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

Description

  • Copyright 2023
  • Dimensions: 7" x 9-1/8"
  • Pages: 528
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-746654-4
  • ISBN-13: 978-0-13-746654-2

Leverage Modern Language Constructs to Write High-Quality Code Faster

The functional and concurrent programming language features supported by modern languages can be challenging, even for experienced developers. These features may appear intimidating to OOP programmers because of a misunderstanding of how they work. Programmers first need to become familiar with the abstract concepts that underlie these powerful features.

In Functional and Concurrent Programming, Michel Charpentier introduces a core set of programming language constructs that will help you be productive in a variety of programming languages—now and in the future. Charpentier illustrates key concepts with numerous small, focused code examples, written in Scala, and with case studies that provide a thorough grounding in functional and concurrent programming skills. These skills will carry from language to language—including the most recent incarnations of Java. Using these features will enable developers and programmers to write high-quality code that is easier to understand, debug, optimize, and evolve.

Key topics covered include:

  • Recursion and tail recursion
  • Pattern matching and algebraic datatypes
  • Persistent structures and immutability
  • Higher-order functions and lambda expressions
  • Lazy evaluation and streams
  • Threads and thread pools
  • Atomicity and locking
  • Synchronization and thread-safe objects
  • Lock-free, non-blocking patterns
  • Futures, promises, and functional-concurrent programming


As a bonus, the book includes a discussion of common typing strategies used in modern programming languages, including type inference, subtyping, polymorphism, type classes, type bounds, and type variance.

Most of the code examples are in Scala, which includes many of the standard features of functional and concurrent programming; however, no prior knowledge of Scala is assumed. You should be familiar with concepts such as classes, methods, objects, types, variables, loops, and conditionals and have enough programming experience to not be distracted by simple matters of syntax.

Sample Content

Online Sample Chapters

Functional-Concurrent Programming

Higher-Order Functions

Sample Pages

Download the sample pages (includes Chapters 9 and 26)

Table of Contents

Foreword by Cay Horstmann   xxiii

Preface    xxv

Acknowledgments    xxxv

About the Author    xxxvii

Part I. Functional Programming    1

Chapter 1: Concepts of Functional Programming    3

     1.1 What Is Functional Programming?     3

     1.2 Functions    4

     1.3 From Functions to Functional Programming Concepts    6

     1.4 Summary    7

Chapter 2: Functions in Programming Languages     9

     2.1 Defining Functions     9

     2.2 Composing Functions     10

     2.3 Functions Defined as Methods     12

     2.4 Operators Defined as Methods     12

     2.5 Extension Methods   13

     2.6 Local Functions     14

     2.7 Repeated Arguments     15

     2.8 Optional Arguments     16

     2.9 Named Arguments     16

     2.10 Type Parameters     17

     2.11 Summary     19

Chapter 3: Immutability     21

     3.1 Pure and Impure Functions     21

     3.2 Actions     23

     3.3 Expressions Versus Statements     25

     3.4 Functional Variables     26

     3.5 Immutable Objects     28

     3.6 Implementation of Mutable State     29

     3.7 Functional Lists     31

     3.8 Hybrid Designs     32

     3.9 Updating Collections of Mutable/Immutable Objects     35

     3.10 Summary     36

Chapter 4: Case Study: ActivePassive Sets     39

     4.1 Object-Oriented Design     39

     4.2 Functional Values     41

     4.3 Functional Objects     43

     4.4 Summary     44

Chapter 5: Pattern Matching and Algebraic Data Types     47

     5.1 Functional Switch     47

     5.2 Tuples     48

     5.3 Options     50

     5.4 Revisiting Functional Lists     51

     5.5 Trees     53

     5.6 Illustration: List Zipper     56

     5.7 Extractors     59

     5.8 Summary     60

Chapter 6: Recursive Programming     63

     6.1 The Need for Recursion     63

     6.2 Recursive Algorithms     65

     6.3 Key Principles of Recursive Algorithms     67

     6.4 Recursive Structures     69

     6.5 Tail Recursion     71

     6.6 Examples of Tail Recursive Functions     73

     6.7 Summary     77

Chapter 7: Recursion on Lists     79

     7.1 Recursive Algorithms as Equalities     79

     7.2 Traversing Lists     80

     7.3 Returning Lists     82

     7.4 Building Lists from the Execution Stack     84

     7.5 Recursion on Multiple/Nested Lists     85

     7.6 Recursion on Sublists Other Than the Tail     88

     7.7 Building Lists in Reverse Order     90

     7.8 Illustration: Sorting     92

     7.9 Building Lists Efficiently     94

     7.10 Summary     96

Chapter 8: Case Study: Binary Search Trees     99

     8.1 Binary Search Trees     99

     8.2 Sets of Integers as Binary Search Trees     100

     8.3 Implementation Without Rebalancing     102

     8.4 Self-Balancing Trees     107

     8.5 Summary     113

Chapter 9: Higher-Order Functions     115

     9.1 Functions as Values     115

     9.2 Currying     118

     9.3 Function Literals     120

     9.4 Functions Versus Methods     123

     9.5 Single-Abstract-Method Interfaces     124

     9.6 Partial Application     125

     9.7 Closures     130

     9.8 Inversion of Control     133

     9.9 Summary     133

Chapter 10: Standard Higher-Order Functions     137

     10.1 Functions with Predicate Arguments     137

     10.2 map and foreach     140

     10.3 atMap     141

     10.4 fold and reduce     146

     10.5 iterate, tabulate, and unfold     148

     10.6 sortWith, sortBy, maxBy, and minBy     149

     10.7 groupBy and groupMap     150

     10.8 Implementing Standard Higher-Order Functions     152

     10.9 foreach, map, atMap, and for-Comprehensions     152

     10.10 Summary     155

Chapter 11: Case Study: File Systems as Trees     157

     11.1 Design Overview     157

     11.2 A Node-Searching Helper Function     158

     11.3 String Representation     158

     11.4 Building Trees     160

     11.5 Querying     164

     11.6 Navigation     168

     11.7 Tree Zipper     169

     11.8 Summary     172

Chapter 12: Lazy Evaluation     173

     12.1 Delayed Evaluation of Arguments     173

     12.2 By-Name Arguments     174

     12.3 Control Abstraction     176

     12.4 Internal Domain-Specifc Languages     179

     12.5 Streams as Lazily Evaluated Lists     180

     12.6 Streams as Pipelines     182

     12.7 Streams as Infinite Data Structures     184

     12.8 Iterators     184

     12.9 Lists, Streams, Iterators, and Views     187

     12.10 Delayed Evaluation of Fields and Local Variables     190

     12.11 Illustration: Subset-Sum     191

     12.12 Summary     193

Chapter 13: Handling Failures     195

     13.1 Exceptions and Special Values     195

     13.2 Using Option     197

     13.3 Using Try     198

     13.4 Using Either     199

     13.5 Higher-Order Functions and Pipelines     201

     13.6 Summary     204

Chapter 14: Case Study: Trampolines     205

     14.1 Tail-Call Optimization     205

     14.2 Trampolines for Tail-Calls     206

     14.3 Tail-Call Optimization in Java     207

     14.4 Dealing with Non-Tail-Calls     209

     14.5 Summary     213

A Brief Interlude     215

Chapter 15: Types (and Related Concepts)      217

     15.1 Typing Strategies     217

     15.2 Types as Sets     222

     15.3 Types as Services     223

     15.4 Abstract Data Types     224

     15.5 Type Inference     225

     15.6 Subtypes     229

     15.7 Polymorphism     232

     15.8 Type Variance     235

     15.9 Type Bounds     241

     15.10 Type Classes     245

     15.11 Summary     250

Part II. Concurrent Programming     253

Chapter 16: Concepts of Concurrent Programming     255

     16.1 Non-sequential Programs     255

     16.2 Concurrent Programming Concepts     258

     16.3 Summary     259

Chapter 17: Threads and Nondeterminism     261

     17.1 Threads of Execution     261

     17.2 Creating Threads Using Lambda Expressions     263

     17.3 Nondeterministic Behavior of Multithreaded Programs     263

     17.4 Thread Termination     264

     17.5 Testing and Debugging Multithreaded Programs     266

     17.6 Summary     268

Chapter 18: Atomicity and Locking     271

     18.1 Atomicity     271

     18.2 Non-atomic Operations     273

     18.3 Atomic Operations and Non-atomic Composition     274

     18.4 Locking     278

     18.5 Intrinsic Locks     279

     18.6 Choosing Locking Targets     281

     18.7 Summary     283

Chapter 19: Thread-Safe Objects     285

     19.1 Immutable Objects     285

     19.2 Encapsulating Synchronization Policies     286

     19.3 Avoiding Reference Escape     288

     19.4 Public and Private Locks     289

     19.5 Leveraging Immutable Types     290

     19.6 Thread-Safety     293

     19.7 Summary     295

Chapter 20: Case Study: Thread-Safe Queue     297

     20.1 Queues as Pairs of Lists     297

     20.2 Single Public Lock Implementation     298

     20.3 Single Private Lock Implementation     301

     20.4 Applying Lock Splitting     303

     20.5 Summary     305

Chapter 21: Thread Pools     307

     21.1 Fire-and-Forget Asynchronous Execution     307

     21.2 Illustration: Parallel Server     309

     21.3 Different Types of Thread Pools     312

     21.4 Parallel Collections     314

     21.5 Summary     318

Chapter 22: Synchronization     321

     22.1 Illustration of the Need for Synchronization     321

     22.2 Synchronizers     324

     22.3 Deadlocks     325

     22.4 Debugging Deadlocks with Thread Dumps     328

     22.5 The Java Memory Model     330

     22.6 Summary     335

Chapter 23: Common Synchronizers     337

     23.1 Locks     337

     23.2 Latches and Barriers     339

     23.3 Semaphores     341

     23.4 Conditions     343

     23.5 Blocking Queues     349

     23.6 Summary     353

Chapter 24: Case Study: Parallel Execution     355

     24.1 Sequential Reference Implementation     355

     24.2 One New Thread per Task     356

     24.3 Bounded Number of Threads     357

     24.4 Dedicated Thread Pool     359

     24.5 Shared Thread Pool     360

     24.6 Bounded Thread Pool     361

     24.7 Parallel Collections     362

     24.8 Asynchronous Task Submission Using Conditions     362

     24.9 Two-Semaphore Implementation     367

     24.10 Summary     368

Chapter 25: Futures and Promises     369

     25.1 Functional Tasks     369

     25.2 Futures as Synchronizers     371

     25.3 Timeouts, Failures, and Cancellation     374

     25.4 Future Variants     375

     25.5 Promises     375

     25.6 Illustration: Thread-Safe Caching     377

     25.7 Summary     379

Chapter 26: Functional-Concurrent Programming     381

     26.1 Correctness and Performance Issues with Blocking     381

     26.2 Callbacks     384

     26.3 Higher-Order Functions on Futures     385

     26.4 Function atMap on Futures     388

     26.5 Illustration: Parallel Server Revisited     390

     26.6 Functional-Concurrent Programming Patterns     393

     26.7 Summary     397

Chapter 27: Minimizing Thread Blocking     399

     27.1 Atomic Operations     399

     27.2 Lock-Free Data Structures     402

     27.3 Fork/Join Pools     405

     27.4 Asynchronous Programming     406

     27.5 Actors     407

     27.6 Reactive Streams     411

     27.7 Non-blocking Synchronization     412

     27.8 Summary     414

Chapter 28: Case Study: Parallel Strategies     417

     28.1 Problem Definition     417

     28.2 Sequential Implementation with Timeout     419

     28.3 Parallel Implementation Using invokeAny     420

     28.4 Parallel Implementation Using CompletionService     421

     28.5 Asynchronous Implementation with Scala Futures     422

     28.6 Asynchronous Implementation with CompletableFuture     426

     28.7 Caching Results from Strategies     427

     28.8 Summary     431

Appendix A. Features of Java and Kotlin     433

     A.1 Functions in Java and Kotlin     433

     A.2 Immutability     436

     A.3 Pattern Matching and Algebraic Data Types     437

     A.4 Recursive Programming     439

     A.5 Higher-Order Functions     440

     A.6 Lazy Evaluation     446

     A.7 Handling Failures     449

     A.8 Types     451

     A.9 Threads     453

     A.10 Atomicity and Locking     454

     A.11 Thread-Safe Objects     455

     A.12 Thread Pools     457

     A.13 Synchronization     459

     A.14 Futures and Functional-Concurrent Programming     460

     A.15 Minimizing Thread Blocking     461

Glossary     463

Index    465

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020