How to understand curry and function composition using Lodash flow?

Silver Spoon Evaluation We’ll just start with tracing the evaluation of addSquare(3, 1) // … Ok, here goes = flow([add, trace(‘after add’), square]) (3, 1) add(3,1) 4 trace(‘after add’) (4) tap(x => console.log(`== ${ ‘after add’ }: ${ x }`)) (4) curry((interceptor, n) => { interceptor(n); return n; }) (x => console.log(`== ${ ‘after add’ … Read more

“Closures are poor man’s objects and vice versa” – What does this mean?

Objects are poor man’s closures. Consider Java. Java is an object-oriented programming language with no language level support for real lexical closures. As a work-around Java programmers use anonymous inner classes that can close over the variables available in lexical scope (provided they’re final). In this sense, objects are poor man’s closures. Closures are poor … Read more

What is ‘Pattern Matching’ in functional languages?

Understanding pattern matching requires explaining three parts: Algebraic data types. What pattern matching is Why its awesome. Algebraic data types in a nutshell ML-like functional languages allow you define simple data types called “disjoint unions” or “algebraic data types”. These data structures are simple containers, and can be recursively defined. For example: type ‘a list … Read more

What is the difference between procedural programming and functional programming? [closed]

A functional language (ideally) allows you to write a mathematical function, i.e. a function that takes n arguments and returns a value. If the program is executed, this function is logically evaluated as needed.1 A procedural language, on the other hand, performs a series of sequential steps. (There’s a way of transforming sequential logic into … Read more

Advantages of stateless programming?

Read Functional Programming in a Nutshell. There are lots of advantages to stateless programming, not least of which is dramatically multithreaded and concurrent code. To put it bluntly, mutable state is enemy of multithreaded code. If values are immutable by default, programmers don’t need to worry about one thread mutating the value of shared state … Read more