0.6.3 • Published 7 months ago

storable-functions v0.6.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 months ago

Storable functions

GitHub npm npm npm.io

Storable and executable functions using array based simple syntax and functional programming.

Getting Started

Installation

  npm install storable-functions

Run tests

  npm run-script test

Example usage

Basic sample

  const { resolve } = require('storable-functions')

  const operation = [ '+', 3, 4 ] // (3 + 4)

  console.log(resolve(operation))
  // output: 7

Nested sample

  const operation = [ 'mod', ['+', 3, 7], 3 ] // (3 + 7) % 3
  console.log(resolve(operation))
  // output: 1

Higher order sample

  const operation = [
    'map', // map function
    'num', // argument variable name
    [ '+', 3, [ 'arg', 'num' ] ], // lambda
    ['array', 1, 2, 3] // data
  ]

  /* In js:
    [1, 2, 3].map(num => num + 3)
  */

  console.log(resolve(operation))

  // output: [4, 5, 6]

Operations

Math module

OperationTokenParamsSampleOutput
Sum+x: Number, y: Number"+", 3, 47
Subtraction-x: Number, y: Number"-", 9, 45
Multiplication*x: Number, y: Number"*", 2, 714
Division/x: Number, y: Number"/", 6, 32
Modulemodx: Number, y: Number"mod", 4, 31
Absolute valueabsx: Number"abs", -44
Floorfloorx: Number"floor", 7.27
Ceilceilx: Number"ceil", 7.28
Trunctruncx: Number"trunc", 7.27
Roundroundx: Number"round", 7.98
Square rootsqrtx: Number"sqrt", 42
Cubic rootcbrtx: Number"cbrt", 82
Arithmetic meanavgf: Function<Number[]>["avg", "array", 4, 6, 5]5
Power^x: Number, y: Number"^", 2, 24
Hypotenusehypotx: Number, y: Number"hypot", 1, 2, 23
Maximummaxf: Function<Number[]>["max", "array", 2, 3, 4]4
Minimumminf: Function<Number[]>["min", "array", 2, 3, 4]2

Logic module

OperationTokenParamsSampleOutput
Andandx: Boolean, y: Boolean"and", true, falsefalse
Ororx: Boolean, y: Boolean"or", true, falsetrue
Notnotx: Boolean"not", truefalse
Equals==x: any, y: any"==", 1, 1true
Conditional 1iff1: Function, x: any["if", "==", 1, 1, 4]4
Conditional 2elseiff1: Function, x: any["if", "==", 1, 2, 4, "elseif", "==", 1, 1, 5]5
Conditional 3elsex: any["if", "==", 1, 2, 4, "else", 7]7

Higher order functions

OperationTokenParamsSampleOutput
MapmapargName: string, f: Function, l: Function<[]>["map", "num", ["+", "arg", "num", 1], "array", 1, 2, 3]2, 3, 4
FoldlfoldlargName: string, accumulatorName: string, f: Function, l: Function<[]>["foldl", "num", 3, "acc", ["^", "arg", "acc", "arg", "num"], "array", 1, 2, 3]19683
FoldrfoldrargName: string, accumulatorName: string, f: Function, l: Function<[]>["foldr", "num", 3, "acc", ["^", "arg", "acc", "arg", "num"], "array", 1, 2, 3]6561
FilterfilterargName: string, f: Function, l: Function<[]>["filter", "num", ["==", "arg", "num", 0], "array", 0, 1, 2]0
FindfindargName: string, f: Function, l: Function<[]>["find", "num", ["==", "arg", "num", 1], "array", 0, 1, 2]1
EveryeveryargName: string, f: Function, l: Function<[]>["every", "num", ["==", "arg", "num", 0], "array", 0, 0, 0]true
SomesomeargName: string, f: Function, l: Function<[]>["some", "num", ["==", "arg", "num", 1], "array", 0, 1, 2]true
SortsortargName1: string, argName2: string, f: Function, l: Function<[]>["sort", "num1", "num2", ["-", "arg", "num2", "arg", "num1"], "array", 3, 2, 1]1, 2, 3

Contributors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.6.3

7 months ago

0.6.2

11 months ago

0.6.1

1 year ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.5

4 years ago

0.1.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago