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

akh

v3.1.2

Published

Monad and Monad Transformer Collection

Downloads

2,034

Readme

$ npm install --save akh

Overview

Akh is a collection of monad and monad transformers that implement Fantasy Land's interfaces. It is inspired by Haskell's MTL.

Usage

Akh can either be used as a single library, or you can pick up individual types from split out libraries. See each library for more documentation on that type.

All functions from akh.core are top level exports.

Monad Transformers

  • akh.ContT - Continuation transformer. (Monad, Functor, Applicative Functor)
  • akh.DContT - Delimited continuation transformer. (Monad, Functor, Applicative Functor)
  • akh.EitherT - Either transformer. (Monad, Monoid, Functor, Applicative Functor)
  • akh.ErrorT - Error transformer. (Monad, Monoid, Functor, Applicative Functor)
  • akh.IdentityT - Transforms a monad to itself. (Monad, Functor, Applicative Functor)
  • akh.ListT - List transformer. (Monad, Monoid, Functor, Applicative Functor)
  • akh.MaybeT - Maybe transformer. (Monad, Monoid, Functor, Applicative Functor)
  • akh.ReaderT - Reader transformer. (Monad, Monoid, Functor, Applicative Functor)
  • akh.StateT - State transformer. (Monad, Monoid, Functor, Applicative Functor)
  • akh.UniqueT - Get unique int value (Monad, Monoid, Functor, Applicative Functor)
  • akh.WriterT - Writer transformer. (Monad, Monoid, Functor, Applicative Functor)

Monads

  • akh.Cont - Continuation computation. (Monad, Functor, Applicative Functor)
  • akh.DCont - Delimited continuation computation. (Monad, Functor, Applicative Functor)
  • akh.Either - Either computation. (Monad, Functor, Applicative Functor)
  • akh.Error - Error computation. (Monad, Functor, Applicative Functor)
  • akh.Identity - Identity computation. (Monad, Functor, Applicative Functor)
  • akh.List - List computation. (Monad, Monoid, Functor, Applicative Functor)
  • akh.Maybe - Computation that may produce a value or nothing. (Monad, Monoid, Functor, Applicative Functor)
  • akh.Reader - Reader monad. (Monad, Monoid, Functor, Applicative Functor)
  • akh.State – Stateful computation. (Monad, Functor, Applicative Functor)
  • akh.Unique – Get Unique int (Monad, Monoid, Functor, Applicative Functor)
  • akh.Writer - Writer monad. (Monad, Monoid, Functor, Applicative Functor)

Quick Example

const List = require('akh').List
const StateT = require('akh').StateT

// Define a new monad using the state transformer on the list monad.
const M = StateT(List)

// Define a way to pass values through `M`
const run = (c, state) => List.runList(StateT.runStateT(c, state))


// Create a simple stateful computation with an initial value
const start = M.of('porky')

// Run the stateful computation to get a list of
// value, state pairs
run(start, 'wackyland') === [
    { value: 'porky', state: 'wackyland' }
]

// Let's update the current state using a function
const modifiedState = start.modify(state => state.toUpperCase())

run(modifiedState, 'wackyland') === [
    { value: 'WACKYLAND', state: 'WACKYLAND' }
]

// Note that modify also updated the held value here. We could avoid that
// by instead writing
const modifiedState2 = start
    .chain(currentValue =>
        M.modify(state => state.toUpperCase())
            .map(_ => currentValue))

run(modifiedState2, 'wackyland') === [
    { value: 'porky', state: 'WACKYLAND' }
]

// Now let's start using the list monad and branch the state.
const branched = modifiedState2
    .concat(
        M.put('nuts').map(_ => 100)  // `put` sets the current state
    )
    .concat(
        M.put('squirrel').map(_ => 1)
    )
    .concat(
        M.get // gets the state
    )

run(branched, 'wackyland') === [
    { value: 'porky', state: 'WACKYLAND' },
    { value: 100, state: 'nuts' },
    { value: 1, state: 'squirrel' },
    { value: 'wackyland', state: 'wackyland' }
]


// We can then operate on all states at the same time.
const doubled = branched.map(x => x + x)

run(doubled, 'wackyland') === [
    { value: 'porkyporky', state: 'WACKYLAND' },
    { value: 200, state: 'nuts' },
    { value: 2, state: 'squirrel' },
    { value: 'wackylandwackyland', state: 'wackyland' }
]

Contribute

Improvement and additions to Akh are welcome. Please report any issues or send a pull request.