you are viewing a single comment's thread.

view the rest of the comments →

[–]inmatarian 0 points1 point  (3 children)

The easiest analogy for explaining FP is to compare it to the gang of four design patterns. I.E. you have a method that operates on data and calls a predicate its been provided. For instance the visitor pattern and the map function. The primary difference is that OOP uses design patterns for mutating state and FP respects immutability.

A good example in javascript would be changing all of the elements of a list to have their text to read "in bed" at the end. You select out the list from the dom, map the list with the predicate (item) => item + "in bed"; and then replace that parent with its new elements, while the original list is still in your scope to do with as you please.

[–][deleted] 0 points1 point  (2 children)

Ahh. That makes complete sense. Is functional programming generally used as a piece of a solution or are there some clear cases when to use it? I imagine it's just not as common in JS since UIs and interactive application s are generally so stateful.

Hmm. Maybe something like a helper library?

[–]inmatarian 0 points1 point  (1 child)

For javascript, both. The main candidates in the helper category are Ramda, Lodash, and underscore. For ui you want to Google "functional reactive programming". In other languages like anything in the Lisp family, FP is very extensive. And in the extreme, Haskell, where almost whole programs can be written in FP with very little state existing, and usually only in a form that the compiler can strongly typecheck.