Tag: totalfunction

  • Pure Function vs. Total Function

    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.

    (more…)