Frequently Asked Questions

What are the core tenets of functional programming?
A. Immutable Data Structures

A. Pure Functions

A. Composition through functions returning Values

When I don’t have an item to return from a function that is otherwise pure should I just return the last item set, put “return;”, or should I let it return undefined?

A. This is a stylistic choice but generally it’s best to just let it return undefined for consistency.

When would I actually use lazy evaluation?

A. There’s a few practical cases for lazy evaluation. One might be if you have a large set of data and you need to perform multiple actions on that data like filter or map. You might only really need to perform that action on a few items in the dataset. Lazy Evaluation means only when an item is needed is it computed.

var oddSquares = Immutable.Seq(1,2,3,4,5,6,7,8)
    .filter(x => x % 2).map(x => x * x);

Where should I have impure functions lower level or higher level?

A. Impure functions should generally be at the higher level as we can more easily reuse lower level functions. At the higher level we sometimes cannot return values but instead need to focus on assignment. The lower level functions should always return values or functions.

What is the difference between Declarative and Imperative?

A. Imperative is about manual orchestration of control flow. Telling the computer how you want something done.

Declarative about telling the computer what you want, its based around higher level abstractions to build things

What is referential transparency?

A. Functions that always map to the same solution

Why are promises considered functional?

A. Promises return something so they are a mapping of a value. There is always a physical representation within the system of the value

What is an example of continuous data versus discrete data?

A. Continuous usually means continuous over time. It means the data doesn't change at discreet points in time, but instead can change continuously to any degree of precision. The temperature of a room is continuously changing. There isn't a specific point in time where it changes from 70 degrees to 71 degrees, and instead it's a smooth continuous change from 70 to 71.

The current time, the temperature of a room, the position of a mouse cursor are all examples of continuous data. On the other hand, mouse clicks and key presses occur at discreet points in time and aren't continuous.

What is functional purity?

A. Pure Functions are ones in which there are no side effects. So whatever is returned is the only outcome of the function being called. The parameters define the inputs and the output is a value or a function. Think of a pure function as a black box that maps an input to an output.

Why do immutable data structures perform better than standard data structures?

A. When you have larger sets the immutable data set the items that are replaced are kept largely the same accept for the items that are new. There are pointers within the data structure looking to see if there was any changes

What is the difference between partial application and currying?

A. Partial Application is about reducing the number of arguments, whereas currying is reducing it to one argument

What should I read if I’m ready for more advance content?

A. If you feel you have a strong understanding of the basic concepts and are implementing them. The next logical step is to learn about Functional Reactive Programming or Functional Data Structures. Both will help you think in terms of Functional Programming.

Who writes on this topic?

A. James Hickey, James Coglan, John Resig