Skip to content

Software, Fitness, and Gaming – Jesse Warden

Software | Fitness | Gaming

  • Home
  • About
  • Contact
  • Books
  • Helpful Tools

Tag: totalfunction

Posted on June 29, 2018June 29, 2018

Pure Function vs. Total Function

A pure function:

const add = (a, b) => a + b

vs. a total function:

const addNumbers = (a, b) =>
  ( isNumber(a) && isNumber(b) )
  ? {ok: true, data: a + b}
  : {ok: false, error: new Error(Either a or b aren't Numbers.)}

While same input, same output, no side effects sounds like the end all, be all… it’s not.

Continue reading “Pure Function vs. Total Function”

Search

Proudly powered by WordPress