Functional Programming With JavaScript

My name is Luke

And I like JavaScript

lwestby@alumni.nd.edu

@luke_dot_js

What do I mean by Functional Programming?

f: X \rightarrow Y
f:XY

In functional programming, functions act like this

They represent transformations on values

Functions can both transform values and be transformed as values

(first-class functions)

This allows us to consider sets of higher-order functions which apply transformations to data

Let me propose a definition

A Collection is

  • A grouping of stuff
  • Always defined
  • Iterable
  • Possibly (but not always) empty
  • Possibly (but not always) infinite

Challenge #1:

Start thinking about values in terms of collections

What JavaScript values are collections?

  • Arrays
  • Objects
  • Maps and Sets

What JavaScript values are not collections?

  • Numbers, Booleans, and Symbols
  • undefined
  • null

Any questions so far?

Challenge #2:

Start thinking about everything in terms of collections

Collections can be expressed over time

  • mousemove events can be expressed as a collection of mouse positions over time

  • XHRs can be expressed as a collection of server side values that arrive over time

  • Many, many, many more possibilities

This perspective allows us to approach UI events, XHR, etc. the same way we approach arrays and objects

Functional Programming with JavaScript

By lukewestby

Functional Programming with JavaScript

  • 876