0.0.3-1 • Published 6 years ago

nullable2 v0.0.3-1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

nullable2

A nullable(Null safety) implementation. Inspired by Kotlin.

npm npm

Install

yarn add nullable2

Usage

Basic

Before

const item = items.findOrNull(id);
const child = item && item.getChildOrNull();
const value = child && child.values && child.values.getValue(param)

After

const nullable = require('nullable2')

const value = nullable(items, v => v
  .findOrNull(id)
  .getChildOrNull()
  .values
  .getValue(param))

Currying

const items$$ = nullable(items)

const child = items$$(v => v
  .findOrNull(id)
  .getChildOrNull())

const otherTitle = items$$(v => v
  .findOrNull(otherId)
  .title)

Related

License

MIT