1.0.0 • Published 7 years ago

getorelse v1.0.0

Weekly downloads
2
License
THE UNLICENSE
Repository
github
Last release
7 years ago

getOrElse

Synopsis

The getOrElse module implements a simple function which returns the first defined argument or if all are undefined a provided default return value.

Motivation

I started to look at famous functional js libs like: Folktale or RamdaFantasy which worked perfectly but was really slow for my usecase where I'have iterated thousands of items. So I created this little module which gives me same functionality with less performance decrease.

Installation

yarn add getOrElse
# OR
npm i -S getOrElse

API Reference

const getOrElse = require('getOrElse')

// DEFAULT_VALUE can be any js object you like to return (a string, object, array, function ...)
// argument1 - argumentN can be as many arguments as you like to pass. Like plain variables or function results
getOrElse(DEFAULT_VALUE, argument1, argument2, ..., argumentN)

Code Example

  getOrElse(
    "defaultValue",
    returnIfEveryLower2([10, 15]),
    returnIfEveryLower2([1000, 8]),
    returnIfEveryLower2([89, 999]),
    returnIfEveryLower2([0.5, 0.7]),
    returnIfEveryLower2([0.1, 0.3])
  )
  // will return [0.5, 0.7]

Tests

yarn test
# OR
npm run test

Contributors

Create a issue if you like to discuss some of your ideas :)

License

The UNLICENSE