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

ts-do

v2.0.0

Published

Do like notation for typescript and fp-ts

Downloads

191

Readme

Description

This library works as an extension for fp-ts allowing the usage of a haskell like do notation. One can use exec, bind, sequence and into to chain computations on any of the supplied monads. Each bind or sequence in the computation chain contributes to a threaded context that is available to each subsequent step. The exec function can also be used to perform computations that add nothing to the context for their side-effects. It is possible to use this with any monads as long as its kind is defined in ft-ts.

Installation

To install the stable version:

yarn add ts-do

Using the extension

Start by importing the extension:

import { some, map } from "fp-ts/lib/Option"
import { pipe } from "fp-ts/lib/pipeable"
import { range, sum } from "ramda"
import * as Do from "ts-do"

const bind = Do.bind(option)
const into = Do.into(option)
const exec = Do.exec(option)
const sequence = Do.sequence(array, option)

const result = pipe(
  some(3),
  into("x"), // Chains the computation. Creates a context with { x: 3 }
  exec(() => some(undefined)), // Chains the computation. Adds nothing to the context
  sequence("ys", ({ x }) => range(0, x).map(() => some(1))), // Sequences computations. Adds { ys: [1, 1, 1] } to the context
  map(({ x, ys }) => x - sum(ys)),
)

// result === some(0)

Check the test folder for a few more examples.

Building

Clone the repo

git clone [email protected]:teves-castro/ts-do.git

Install dependencies

yarn

Test

yarn run test

Compile

yarn run build

Disclaimer

These kind of operations (do notation) should be done with compiler support, like the special case of async/await for promises, that is included in most major languages these days.

Although these languages are adopting more and more functional programming constructs, sadly more advanced concepts are left out due to not having critical mass to demand it's implementation.

So, this is an experiment on what can be accomplished without that compiler support. Meaning that if/when this is supported natively by the language itself, certainly with different syntax, this will become obsolete.

Also I make no commitment to evolve the library beyond my own needs, so bear these warnings in mind when using the library. And of course I appreciate any comments and suggestions on how to improve or on how I completely blundered something.