Understand functional programming concepts and the functional nature of the JavaScript language. Starting with an introduction to functional programming concepts, you will learn the key differences between imperative and functional programming. Diving straight into JavaScript functions, you will learn to write them with ES8. Followed by this you will move to higher order functions and learn how 'Function as Data' opens up a world of possibilities.You will then build higher order functions with closures. Arrays will then be introduced, followed by a set of APIs you can use with them. You will learn how to transform one function to another using currying and partial application. The compose function will be discussed in detail, followed by functors and monads. After having an in-depth look at applicative functors, you will learn the new features offered in ES8.The concluding chapters of Beginning Functional JavaScript will show you how to use a functional toolkit to build a small library that allows you to develop web applications, followed by tips on testing your functional code.You will:• Discover functional programming concepts such as string padding and async functions• Identify how functions are treated in JavaScript• Create a functional library that mimics Underscore.JS• Deep dive into ES8 functional features such as spread operators and generators• Create a library that works like the react-redux pattern by following the functional paradigm Brief Contents 3 Contents 4 1 Functional Programming in simple Terms 10 What Is Functional Programming? Why It Matters? 10 Referential Transparency 13 Imperative, Declarative, Abstraction 14 Functional Programming Benefits 15 Pure Functions 15 Pure Functions Lead to Testable Code 15 Reasonable Code 17 Parallel Code 18 Cachable 19 Pipelines and Composable 20 Pure Function Is a Mathematical Function 20 What We Are Going to Build 21 Is JavaScript a Functional Programming Language? 22 Summary 22 2 Fundamentals of JavaScript Functions 23 ECMAScript A Bit of History 24 Creating and Executing Functions 24 First Function 25 Strict Mode 26 Return Statement Is Optional 27 Multiple Statement Functions 28 Function Arguments 29 ES5 Functions Are Valid in ES6 29 Setting Up Our Project 29 Initial Setup 30 Our First Functional Approach to the Loop Problem 31 Gist on Exports 33 Gist on Imports 33 Running the Code Using Babel-Node 34 Creating Script in Npm 34 Running the Source Code from Git 35 Summary 36 3 Higher-Order Functions 37 Understanding Data 38 Understanding JavaScript Data Types 38 Storing a Function 38 Passing a Function 39 Returning a Function 40 Abstraction and Higher-Order Functions 41 Abstraction Definitions 41 Abstraction via Higher-Order Functions 42 Higher-Order Functions in the Real World 45 every Function 45 some Function 46 sort Function 47 Summary 51 4 Closures & Higher-Order Functions 52 Understanding Closures 53 What Are Closures? 53 Remembering Where It Is Born 54 Revisiting sortBy Function 56 Higher-Order Functions in the Real World (Continued) 57 tap Function 57 unary Function 58 once Function 59 Memoize Function 60 Summary 62 5 Functional Arrays 63 Working Functionally on Arrays 64 map 64 filter 67 Chaining Operations 68 concatAll 69 Reducing Function 72 reduce Function 73 Zipping Arrays 78 zip Function 79 Summary 81 6 Currying & Partial Application 83 A Few Terminologies 83 unary Function 84 Binary Function 84 variadic Functions 84 Currying 85 Currying Use Cases 87 A logger Function - Using Currying 88 Revisit Curry 89 Back to logger Function 92 Currying in Action 93 Finding number in Array Contents 93 squaring an Array 94 Data Flow 94 Partial Application 95 Implementing partial Function 95 Currying vs. Partial Application 98 Summary 98 7 Composition & Pipelines 99 Composition in General Terms 99 Unix Philosophy 100 Functional Composition 102 Revisiting map,filter 102 compose Function 103 Playing with compose function 104 curry and partial to the Rescue 105 compose many function 108 Pipelines / Sequence 109 Implementing pipe 110 Odds on Composition 110 Composition is associative 110 Debugging Using tap Function 111 Summary 112 8 Functors 113 What Is a Functor? 113 Functor Is a Container 114 Functor Implements Method Called map 115 MayBe 117 Implementing MayBe 117 Simple Use Cases 118 Real-World Use Cases 120 Either Functor 124 Implementing Either 124 Reddit Example Either Version 126 Word of Caution - Pointed Functor 129 Summary 129 9 Monads in depth 130 Getting Reddit Comments for Our Search Query 130 The Problem 131 Implementation of the First Step 133 Problem of So Many maps 139 Solving the Problem via join 140 join Implementation 140 chain Implementation 142 So What Is a Monad? 144 Summary 145 10 Pause, Resume with Generators 146 Async Code and Its Problem 147 Callback Hell 147 Generators 101 149 Creating Generators 149 Caveats of Generators 150 yield New Keyword 151 done Property of Generator 153 Passing Data to Generators 154 Using Generators to Handle Async Calls 156 Generators for Async - A Simple Case 156 Generators for Async - A Real-World Case 161 Summary 163 Install Node 164 Index 165 Learn functional programming concepts using JavaScript ES6. You will learn concepts such as currying, partial functions, higher-order functions, and monads. Programming languages have evolved from focusing on procedures to objects and now on function. JavaScript supports functional programming and allows developers to write well-crafted code. What You Will Learn: Master functional programming concepts Identify how functions are treated in JavaScript Understand real-world functional libraries and create a functional library that mimics underscore.js Perform pure-error handling techniques such as functors and monads Discover ES6 functional features such as spread operators and generators Who This Book Is For: JavaScript developers (or beginners) who want to understand functional programming concepts and the functional nature of the language. The only functional JavaScript book using EcmaScript 6 Simple, concise, ready-to-run code samples that explain functional library concepts Shows how functional APIs can be built