Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sweet-monads/async

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sweet-monads/async

Promise helpers for monad

  • 2.1.4
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@sweet-monads/async

Package for better developer experience with Promise and @sweet-monad/interfaces/Monad

This library belongs to sweet-monads project

sweet-monads — easy-to-use monads implementation with static types definition and separated packages.

  • No dependencies, one small file
  • Easily auditable TypeScript/JS code
  • Check out all libraries: maybe, iterator, interfaces,

Usage

npm install @sweet-monads/async

import { chain } from "@sweet-monads/async";
import { right } from "@sweet-monads/either";

const fn = () =>
  Promise.resolve(right("Hello, Sweet Monad."))
    .then(chain(doSomethingAsync))
    .then(chain(doOneMoreAsyncThing));

API

chain
  chain<T, R>(fn: (v: T) => Promise<Monad<R>>): (m: Monad<T>) => Promise<Monad<R>>;
  • f: (v: T) => Promise<Monad<R>> - async function which convert a Monad to another one.
  • Returns Promise with mapped by fn function value wrapped by Monad by the Monad implementation rule.

Example:

declare function getUser(email: string): Promise<Either<UserNotFoundError, User>>;
declare function arePasswordsMatched(password: string, user: User): Promise<Either<WrongCredentialsError, boolean>>;

// result is Promise<Either<UserNotFoundError | WrongCredentialsError, boolean>>
const result = getUser("some@email.com")
  .then(chain(user => arePasswordsMatched("some password", user.password)));

License

MIT (c) Artem Kobzar see LICENSE file.

FAQs

Package last updated on 05 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc