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

@typed-f/maybe

v0.3.8

Published

[![NPM Version][maybe-npm-version-badge]][maybe-npm] [repo-circleci-badge]: https://img.shields.io/circleci/project/github/Ailrun/typed-f/master.svg?logo=circleci [![Known Vulnerabilities][maybe-snyk-badge]][maybe-snyk] [![Supported TypeScript Version][re

Downloads

1,019

Readme

@typed-f/maybe

NPM Version repo-circleci-badge: https://img.shields.io/circleci/project/github/Ailrun/typed-f/master.svg?logo=circleci Known Vulnerabilities Supported TypeScript Version PRs Welcome

Watch on GitHub Star on GitHub

Partial type for Typed-F

Installation

# for NPM>=5
npm install @typed-f/maybe
# or
npm i @typed-f/maybe
# for NPM<5
npm install --save @typed-f/maybe
# or
npm i -S @typed-f/maybe

APIs

This package includes type definition for Maybe type, which is an union type of Just and Nothing. This package also includes their methods and some utility functions for them.

Types

  • Maybe<T>
  • Just<T>
  • Nothing<T>

Methods only for Maybe

  • isJust(this: Maybe<T>): this is Just<T> Checks whether this is Just or not. You can use this with if statement like following code.
    declare const m: Maybe<number>;
      
    if (m.isJust()) {
      // Now `m` is `Just<number>`
      console.log(m.value.toFixed(4));
    }
  • isNothing(this: Maybe<T>): this is Nothing<any> Counterpart of isJust. You can use this with if statement.
  • valueOr(this: Maybe<T>, def: T): T If this is Just, this function returns the inner value of this. If not, this returns def (default value) you passed.
  • valueOrThrow(this: Maybe<T>, err: Error): T If this is Just, this function returns the inner value of this. If not, this throws err you passed.
  • valueOrCompute(this: Maybe<T>, f: Fun<[], T>): T If this is Just, this function returns the inner value of this. If not, this invoke f with inner value of current this, and return the result.

Implemented Typeclasses

  • Monad
    • bind<U>(this: Maybe<T>, f: Fun<[T], Maybe<U>>): Maybe<U> If this is Just, applies f to its inner value and return the result. If this is Nothing, returns this.
  • Applicative
    • unit<U>(v: U): Maybe<any, U> Return Just of v.
    • ap<U>(this: Maybe<T>, f: Maybe<Fun<[T], U>>): Maybe<U> If this is Just and f is Just, applies the inner value of f to the inner value of this and returns Just of the result. If this is Just but f is Nothing, returns f. If this is Nothing, returns this.
  • Functor
    • map<U>(this: Maybe<T>, f: Fun<[R], U>): Maybe<U> If this is Just, applies f to the inner value of this and returns Just of the result. If this is Nothing, returns this.
  • Matchable
    • matchWith<U>(this: Maybe<T>, cases: MaybePatterns<T, U>): U If this is Just, applies cases.just to the inner value of this and returns the result. If this is Nothing, invoke cases.nothing and returns the result.
  • Setoid
    • equals(other: Maybe<any>): boolean If this equals to other, return true. If this does not equal to other, return false. When both this and other are Justs and have complex inner values (object), this function tries equals method of inner value of this. In other words, this.equals(other) === this.value.equals(other.value)
    • notEquals(other: Maybe<any>): boolean Returns true if and only if this.equals(other) returns false.

Utility Functions

You can use these functions like Maybe.<function name>, for example, in case of map, you can access it with Maybe.map.

  • unit<T>(value: T): Maybe<T> Returns Just of value.
  • of Alias of unit
  • from<T>(value?: null): Nothing<T>
  • from<T>(value: T): Just<T> Returns Nothing for value that is null or undefined, and returns Just of value for other values.
  • maybe Alias of from
  • sequenceObject<O extends object>(obj: { [K in keyof O]: Maybe<O[K]> }): Maybe<O> Takes an obj of Maybes and returns an Maybe of object. If for all keys of obj, correspoding values are Just, then this will return a Just of object whose keys are original keys and correspoding values are inner value of original values (Justs). If for one or more keys of obj, values are Nothing, then this will return Nothing.
  • sequenceArray<T>(array: Maybe<T>[]): Maybe<T[]> Takes an array of Maybes and returns an Maybe of array. If all entries of array are Just, this will return a Just of array whose entries are inner values of original entries. Corresponding entries will have same indices. If one or more entries of array are Nothing, this will return a Nothing.
  • map<T, U>(f: Fun<[T], U>): Fun<[Maybe<T>], Maybe<U>> Returns a function that takes Maybe<T> and maps its inner value using f. map(f)(a) is same with a.map(f).