Skip to content

Simple package to get the first defined result of you inputs.

License

Notifications You must be signed in to change notification settings

lrecknagel/getorelse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Simple package to get the first defined result of you inputs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published