Functional Programming

From bibbleWiki
Jump to navigation Jump to search

Introduction

This page is meant to give an overview of terms associated with functional programming and used with other languages like scala, kotlin, javascript.

Pure Functions

Introduction

  • They will always produce the same answer with the same input.
  • They will not produce side effects
function plus(a, b) {
  return a + b;
}

Impure and Side Effect

Given

let str = "some thing"

let f_pure = function(_input) {
  let _output = _input.toUpperCase()
  return _output
}

let f_impure = function(_input) {
  let _output = _input.toUpperCase()
  str = _output
  return _output
}

The f_pure will return what was passed in and modify no other data. However the f_impure does modify str outside of the scope of the function (side effect) and therefore is not considered to be a pure function.

Statics vs Pure

The difference between static and pure functions is that a static can be a void and can increment other static values.

Higher Order Functions