Hands-On Functional Programming with TypeScript
eBook - ePub

Hands-On Functional Programming with TypeScript

Explore functional and reactive programming to create robust and testable TypeScript applications

Remo H. Jansen

Share book
  1. 210 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Hands-On Functional Programming with TypeScript

Explore functional and reactive programming to create robust and testable TypeScript applications

Remo H. Jansen

Book details
Book preview
Table of contents
Citations

About This Book

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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Hands-On Functional Programming with TypeScript an online PDF/ePUB?
Yes, you can access Hands-On Functional Programming with TypeScript by Remo H. Jansen in PDF and/or ePUB format, as well as other popular books in Informatik & Programmierung in JavaScript. We have over one million books available in our catalogue for you to explore.

Information

Year
2019
ISBN
9781788838184

Category Theory

In the previous chapter, we learned about functions, asynchronous programming, and the runtime and functional programming principles and techniques, including pure functions and functional composition.
In this chapter, we are going to focus on category theory and algebraic data types. We are going to learn about the following concepts:
  • Category theory
  • Algebraic data types
  • Functors
  • Applicative
  • Maybe
  • Either
  • Monads

Category theory

Functional programming has a reputation for being difficult to learn and understand due to its mathematical background. Functional programming languages and design patterns are influenced by concepts that originated in different mathematical fields. However, we can highlight category theory as one of the most significant influences. We can think about category theory as an alternative to set theory. It defines the theory behind a series of data structures or objects known as algebraic data types.
There are many algebraic data types, and understanding all the properties and rules that they must implement requires a significant amount of time and effort. The following diagram illustrates the relationships between some of the most common algebraic data types:
The arrows in the diagram indicate that a given algebraic data type must implement the specification of some other algebraic data types. For example, the Monad type must implement the specifications of the Applicative and Chain types.
The open source project, fantasy-land, declares a specification for some of these algebraic data types. The open source project, ramda-fantasy, implements these specifications in a way that is compatible with Ramda, which is a popular functional programming library that we will explore later in this book.
The algebraic data type specifications can be implemented in many ways. For example, the Functor specification can be implemented by a Maybe or an Either data type. Both types implement the Functor specification, but can also implement other specifications, such as the Monad or the Applicative specification.
The following table describes which specifications (listed in the top row) are implemented by one of the algebraic data type implementations (left row) in the fantasy-ramda project:
Name Setoid Semigroup Functor Applicative Monad Foldable ChainRec
Either
Future
Identity
IO
Maybe
Reader
Tuple
State
Understanding the field of category theory and all these data types and specifications is outside the scope of this book. However, in this chapter, we are going to learn the basics regarding two of the most common algebraic data types: Functors and Monads.
Please refer to the fantasy-land project at https://github.com/fantasyland/fantasy-land and the fantasy-ramda project at https://github.com/ramda/ramda-fantasy to learn more about algebraic data types.

Functors

The Functor type has two main characteristics:
  • It holds a...

Table of contents