npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

scala-like-option

v1.0.3

Published

Lib that exposes option with rich Api like Scala option, option monad lets you handle nulls in javascript in declarative way

Downloads

9

Readme

scala-like-option

Build Status

Option that covers all API functions from Scala Option monad in javascript for handling null in declarative way

install

npm install --save scala-like-option

usage

const optionFactory = require('scala-like-option')

var some = optionFactory.Some('some-content');
var transformation = optionFactory.map(content => 'other-content'); // == 'other-content'

var none = optionFactory.Option(null); // option from null == none
var none = optionFactory.None();
var some = optionFactory.Option('some-content'); // Some('some-content')
var some = some.getOrElse('other-content') // 'some-content'
var some = some.fold('empty', c => 'data') // returns 'data'

Api

getOrElse(elseObject)

Returns the item or the elseObject if None

Arguments:

  • elseObject: the object that returns of was None

get()

Returns the element or throws NoSuchElementException if was None

orElse(Else)

Returns current option if Some or the Else if None

Arguments:

  • Else: other option to return

orNull()

Returns the element or null if was None

isEmpty()

Return true if None and false if Some

isDefined()

Return false if None and true if Some

map(transformer)

Returns different option with the transformer predicate

Arguments:

  • transformer: function that gets the element and returns new object

fold(ifEmpty, applyNonEmpty)

Return value from supplied function, one for None and one For Some

Arguments:

  • ifEmpty: value returned from this function if is None
  • applyNonEmpty: value returned from this function if is Some

flatMap(transformer)

Returns different option for given transformer

Arguments:

  • transformer: function that gets the element and returns new option, it may be None

filter(predicate)

Returns the content if predicate returns true

Arguments:

  • predicate: function that gets the element and returns true/false

filterNot(predicate)

Returns the content if predicate returns false

Arguments:

  • predicate: function that gets the element and returns true/false

find(predicate)

Returns the content if predicate returns true

Arguments:

  • predicate: function that gets the element and returns true/false

forAll(predicate)

Returns true if give predicate on this element returns true, if None returns always true

Arguments:

  • predicate: function that gets the element and returns true/false

contains(containElement)

Returns true if the element is equal to give parameter, if none returns false

Arguments:

  • containElement: element to check equality

exists(predicate)

Checks if element exists for given predicate

Arguments:

  • predicate: function that return true/false and gets the element

forEach(executor)

Execute function with element, do nothing when None

Arguments:

  • executor: function that called with the element

toList()

Return array from option, if None it returns empty array

iterator()

Returns iterator from option, end iterator if none