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

future-either

v0.3.0

Published

An extension type of 'Future<L, R>' to support tri-state object

Downloads

8

Readme

future-either

Overview

FutureEither is an extension of the original Future<L, R> data type from fluture. It intends to control the flow of a tri-state object that contains E, L, R branches. The definition of those branches are stated as follows:

  E -> Fatal-Error, should be thrown immediately

  L -> Left-Value, usually for an error but could do side-effects

  R -> Right-Value, returns when succeeded

This requirement comes from real coding practice. Take "querying an user from database" as an example. The process may encounter 3 different situations:

  • query succeed and data is fetched.
  • query failed because of no such user in database.
  • database connection error.

For 1# and 2#, we usually expect further operation (side-effect) may continue execution according to the results;

For 3#, error should throw immediately.

API

fromFuture

FutureEither.fromFuture  :: Future<L, R> -> FutureEither<E, L, R> 

Construct a FutureEither object from existing Future instance.

fromPromise

FutureEither.fromPromise  :: (A -> Promise<R>) -> (A -> FutureEither<E, L, R>)

Construct a function that returns a FutureEither object from a promise function.

Notice: there will be only L, R branch of the FutureEither object, corresponding to Promise.reject and Promise.resolve respectively. E branch will not happen there.

fromP2

FutureEither.fromP2  :: (A -> B -> Promise<R>) -> (A -> B -> FutureEither<E, L, R>)

Similar with fromPromise, but with 2 parameters.

fromP3

FutureEither.fromP3  :: (A -> B -> C -> Promise<R>) -> (A -> B -> C -> FutureEither<E, L, R>)

Similar with fromPromise, but with 3 parameters.

chainRight

FutureEither.prototype.chainRight  :: FutureEither<E, L, R> ~> (R -> Future<E, V>)   -> FutureEither<E, L, V> 

Sequence a new FutureEither object of the R value. It only applies to the R branch, that is, L, E branch will be ignored.

chainLeft

FutureEither.prototype.chainLeft  :: FutureEither<E, L, R> ~> (L -> Future<E, V>)   -> FutureEither<E, V, R>

Sequence a new FutureEither object of the L value. Similar to chainRight(), it only applies to the L branch, that is, R, E branch will be ignored.

mapRight

FutureEither.prototype.mapRight  :: FutureEither<E, L, R> ~> (R -> V)   -> FutureEither<E, L, V>

mapLeft

FutureEither.prototype.mapLeft  :: FutureEither<E, L, R> ~> (L -> V)   -> FutureEither<E, V, R>

chain

FutureEither.prototype.mapLeft  :: FutureEither<E, L, R> ~> (Future<L, R> -> FutureEither<E, L, R>)   -> FutureEither<E, L, R>

chainRej

FutureEither.prototype.mapLeft  :: FutureEither<E, L, R> ~> (E -> FutureEither<E, L, R>)   -> FutureEither<E, L, R>

toValue

FutureEither.prototype.toValue  :: FutureEither<E, L, R> ~> Future<L, R>

Export the future instance with L or R branch for further operations.

toPromiseValue

FutureEither.prototype.toPromiseValue :: FutureEither<E, L, R> ~> Promise<R>

Export the promise object of the future instance. Notice: both E and L branch will throw error!