Functional Programming: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Created page with "=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 Funct..."
 
Line 2: Line 2:
This page is meant to give an overview of terms associated with functional programming and used with other languages like scala, kotlin, javascript.
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=
=Pure Functions=
==Introduction==
*They will always produce the same answer with the same input.
*They will not produce side effects
<syntaxhighlight lang="js">
function plus(a, b) {
  return a + b;
}
</syntaxhighlight>
==Impure and Side Effect==
Given
<syntaxhighlight lang="js">
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
}
</syntaxhighlight>
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=
=Higher Order Functions=

Revision as of 03:17, 24 June 2021

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