Hands-On Functional Programming with TypeScript

Book description

Discover the power of functional programming, lazy evaluation, monads, concurrency, and immutability to create succinct and expressive implementations

Key Features

  • Get a solid understanding of how to apply functional programming concepts in TypeScript
  • Explore TypeScript runtime features such as event loop, closures, and Prototypes
  • Gain deeper knowledge on the pros and cons of TypeScript

Book Description

Functional programming is a powerful programming paradigm that can help you to write better code. However, learning functional programming can be complicated, and the existing literature is often too complex for beginners. This book is an approachable introduction to functional programming and reactive programming with TypeScript for readers without previous experience in functional programming with JavaScript, TypeScript , or any other programming language.

The book will help you understand the pros, cons, and core principles of functional programming in TypeScript. It will explain higher order functions, referential transparency, functional composition, and monads with the help of effective code examples. Using TypeScript as a functional programming language, you'll also be able to brush up on your knowledge of applying functional programming techniques, including currying, laziness, and immutability, to real-world scenarios.

By the end of this book, you will be confident when it comes to using core functional and reactive programming techniques to help you build effective applications with TypeScript.

What you will learn

  • Understand the pros and cons of functional programming
  • Delve into the principles, patterns, and best practices of functional and reactive programming
  • Use lazy evaluation to improve the performance of applications
  • Explore functional optics with Ramda
  • Gain insights into category theory functional data structures such as Functors and Monads
  • Use functions as values, so that they can be passed as arguments to other functions

Who this book is for

This book is designed for readers with no prior experience of functional programming with JavaScript, TypeScript or any other programming language. Some familiarity with TypeScript and web development is a must to grasp the concepts in the book easily.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Functional Programming with TypeScript
  3. Dedication
  4. About Packt
    1. Why subscribe?
    2. Packt.com
  5. Foreword
  6. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  8. Functional Programming Fundamentals
    1. Is TypeScript a functional programming language?
    2. The benefits of functional programming
    3. Introducing functional programming
    4. Pure functions
    5. side-effects
    6. Referential transparency
    7. Stateless versus stateful
    8. Declarative versus imperative programming
    9. Immutability
    10. Functions as first-class citizens
    11. Lambda expressions
    12. Function arity
    13. Higher-order functions
    14. Laziness
    15. Summary
  9. Mastering Functions
    1. Function types
      1. Named and anonymous functions
      2. Function declarations and function expressions
    2. Working with function parameters
      1. Trailing commas in function arguments
      2. Functions with optional parameters
      3. Functions with default parameters
      4. Functions with rest parameters
      5. Function overloading
      6. Specialized overloading signature
    3. Function scope and hoisting
    4. Immediately-invoked functions
    5. Tag functions and tagged templates
    6. Summary
  10. Mastering Asynchronous Programming
    1. Callbacks and higher-order functions
      1. Arrow functions
    2. Callback hell
      1. Promises
      2. Covariant checking in callback parameters
    3. Generators
    4. Asynchronous functions – async and await
      1. Asynchronous generators
      2. Asynchronous iteration (for await…of)
      3. Delegating to another generator (yield*)
    5. Summary
  11. The Runtime – The Event Loop and the this Operator
    1. The environment
    2. Understanding the event loop
      1. Frames
      2. Stack
      3. Queue
      4. Heap
      5. The event loop
    3. The this operator
      1. The this operator in the global context
      2. The this operator in the function context
      3. The call, apply, and bind methods
    4. Summary
  12. The Runtime – Closures and Prototypes
    1. Prototypes
      1. Instance properties versus class properties
      2. Prototypal inheritance
      3. Prototype chains and property shadowing
      4. Accessing the prototype of an object
    2. Closures
      1. Static variables powered by closures
      2. Private members powered by closures
    3. Summary
  13. Functional Programming Techniques
    1. Composition techniques
      1. Composition
      2. Partial application
      3. Currying
      4. strictBindCallApply
      5. Pipes
    2. Other techniques
      1. Point-free style
      2. Recursion
      3. Pattern matching
    3. Summary
  14. Category Theory
    1. Category theory
    2. Functors
      1. Applicative
      2. Maybe
      3. Either
      4. Monads
    3. Summary
  15. Immutability, Optics, and Laziness
    1. Immutability
    2. Optics
      1. Lenses
      2. Prisms
    3. Laziness
    4. Summary
  16. Functional-Reactive Programming
    1. Reactive programming
      1. Functional programming versus functional-reactive programming
      2. The benefits of functional-reactive programming
    2. Working with observables
      1. The observer pattern
      2. The iterator pattern
      3. Creating observables
        1. Creating observables from a value
        2. Creating observables from arrays
        3. Creating observables from events
        4. Creating observables from callbacks
        5. Creating observables from promises
      4. Cold and hot observables
    3. Working with operators
      1. Pipe
      2. Max
      3. Every
      4. Find
      5. Filter
      6. Map
      7. Reduce
      8. Throttle
      9. Merge
      10. Zip
    4. Summary
  17. Real-World Functional Programming
    1. Working with Ramda
      1. Composition
      2. Partial application and currying
      3. Lenses
    2. Working with Immutable.js
    3. Working with Immer
    4. Working with Funfix
    5. Summary
  18. Functional Programming Learning Road Map
    1. Beginner
    2. Advanced beginner
    3. Intermediate
    4. Proficient
    5. Expert
    6. Summary
  19. Directory of TypeScript Functional Programming Libraries
    1. Functional programming
    2. Category theory
    3. Laziness
    4. Immutability
    5. Optics and lenses
    6. Functional-reactive programming
    7. Others
    8. Summary
  20. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On Functional Programming with TypeScript
  • Author(s): Remo H. Jansen
  • Release date: January 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781788831437