functional programming: defining a function

2021-09-22

 | 

~1 min read

 | 

179 words

What is a function?

Brian Lonsdorf’s definition of a function from Hardcore Functional Programming in Javascript, v2 is three legged:

  1. Total
  2. Deterministic
  3. No (observable) side-effects

Total

Total Functions1 contrast with Partial Functions. The former terminates in a value for all possible inputs whereas the former does not.

That is, for the entire domain, the range is defined. The domain being the set of inputs and the range the set of outputs.

Deterministic

Another word for deterministic is reliable. A deterministic function is one that reliably returns the same output.

No (observable) side-effects

In this context, a side-effect is something that changes the state of the world or application that can be readily observed.

Of course, this can be taken “too far”. For example, my understanding is pure functions can still result in outputs that are written to STDOUT.

Footnotes


Related Posts
  • Functional Programming Notes


  • Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!