Book Image

Hands-On Functional Programming with TypeScript

By : Remo H. Jansen
Book Image

Hands-On Functional Programming with TypeScript

By: Remo H. Jansen

Overview of this book

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.
Table of Contents (14 chapters)
5
The Runtime – Closures and Prototypes

To get the most out of this book

You don't need any additional material to follow this book. No prior knowledge of functional programming is required. However, a basic understanding of JavaScript and TypeScript is recommended to make the most use of this book.

It is recommended reading the chapters in order. However, if you are new to functional programming and already have advanced knowledge of functions, asynchronous programming, and the runtime, you could maybe skip chapters two to five.

You can refer to the TypeScript handbook at http://www.typescriptlang.org/docs/handbook/basic-types.html if you have some experience with JavaScript, but TypeScript is new to you. This resource might be especially useful if TypeScript is your first statically typed programming language. Alternatively, you can refer to the book Learning TypeScript 2.x, Second Edition, also by Remo H. Jansen and Packt Publishing.

If you need help installing Node.js, you can refer to the official documentation at https://nodejs.org/en/download/package-manager. If you need help installing TypeScript, you can refer to the official documentation at http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-Functional-Programming-with-Typescript. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

function find<T>(arr: T[], filter: (i: T) => boolean) {
return arr.filter(filter);
}

find(heroes, (h) => h.name === "Spiderman");

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

const valueOfThis = { name: "Anakin", surname: "Skywalker" };
const greet = person.greet.bind(valueOfThis);
greet.call(valueOfThis, "Mos espa", "Tatooine");
greet.apply(valueOfThis, ["Mos espa", "Tatooine"]);
// Hi, my name is Remo Jansen. I'm from Mos espa Tatooine.

Any command-line input or output is written as follows:

npm install ramda @types/ramda

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Warnings or important notes appear like this.
Tips and tricks appear like this.