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 🙏

© 2026 – Pkg Stats / Ryan Hefner

bl-js-monads

v0.1.0

Published

Some monads for javascript

Downloads

26

Readme

Monads for javascript

Option

Usage:


import { Option } from 'bl-js-monads';;

// Basic value

const opt1 = Option.of ('BOE')

console.log (opt1.isSome)   // true
console.log (opt1.isNone)   // false
console.log (opt1.value())  // BOE

// Basic none (no value)

const opt2 = Option.none

console.log (opt2.isSome)   // false
console.log (opt2.isNone)   // true
opt2.value()                // throws error 'Option has no value'

// Setting null leads to none and is factual Option.none

const opt3 = Option.of (null)

console.log (opt3.isSome)   // false
console.log (opt3.isNone)   // true
opt3.value()                // throws error 'Option has no value'

// Mapping

const opt4 = Option.of ('BOE')
    .map (v => `${v}-BA`)

console.log (opt4.isSome)   // true
console.log (opt4.isNone)   // false
console.log (opt4.value())  // BOE-BA

// Flatmapping (aka mapping to another Option)

const opt5 = Option.of ('BOE')
    .flatMap (v => Option.of (`${v}-BA`))

console.log (opt5.isSome)   // true
console.log (opt5.isNone)   // false
console.log (opt5.value())  // BOE-BA

// Mapping of none

const opt6 = Option.none
    .map (v => `${v}-BA`)

console.log (opt6.isSome)   // false
console.log (opt6.isNone)   // true

// Chaining

const opt7 = opt5.flatMap (v => opt4)

console.log (opt7.isSome)   // true
console.log (opt7.isNone)   // false
console.log (opt7.value())  // BOE-BA

Try

Usage:


import { Try } from 'bl-js-monads';

// Basic value

const try1 = Try.succesfull ('BOE')

console.log (try1.get())  // BOE

// Basic failure

const try2 = Try.failure ('Some error')

try {
    try2.get()
} catch (e) {
    console.error (e)  // Result: Some error
}

// Basic

const try3 = Try.ofFailable (() => 'BA')

console.log (try3.get())  // BA


const try4 = Try.ofFailable (() => { throw 'Some error' })

try {
    try4.get()
} catch (e) {
    console.error (e)  // Result: Some error
}

// Side-FX

const try5 = Try.ofFailable (() => 'BA')
    .onSuccess (v => console.log (`Success: ${v}`))  // Feedbacks Success: BA
    .ofFailure (e => console.log (`Error: ${e}`))

console.log (try5.get())  // BA

const try6 = Try.ofFailable (() => { throw 'Some error' })
    .onSuccess (v => console.log (`Success: ${v}`))  
    .ofFailure (e => console.log (`Error: ${e}`))    // Feedbacks Error: Some error

try {
    try6.get()
} catch (e) {
    console.error (e)  // Result: Some error
}

// Mapping

const try7 = Try.succesfull('BOE')
    .map (v => `${v}-BA`)

console.log (try7.get())  // BOE-BA

// Flatmapping (aka mapping to another Try)

const try8 = Try.succesfull('BOE')
    .flatMap (v => Try.succesfull(`${v}-BA`))

console.log (try8.get())  // BOE-BA

// Map to option

const try9 = Try.succesfull('BOE')
    .toOption ()

console.log (try9.isSome)  // true
console.log (try9.value())  // BOE

const try10 = Try.failure('BOE')
    .toOption ()

console.log (try10.isNone)  // true