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

lazychain

v0.3.0-alpha.23

Published

**[Document](http://falsandtru.github.io/lazychain/)** | **[js](https://github.com/falsandtru/lazychain/releases)** | **[d.ts](src/ts/.d/lazychain.d.ts)**

Downloads

11

Readme

LazyChain

Document | js | d.ts

Build Status Coverage Status Dependency Status

FRP(Functional reactive programming) supporting DSL. Lazy stream, monad, pattern match, guard implements in JavaScript.

Data-Oriented Design by Pipeline

mainstream
[input]
  |     substream(async)
  | ----> |
  |       :     procstream
  |       | ----> |
  |       |       |
  |       | <---- |
  |       |
  |       |     ajax(async)
  |       | ----> |
  |       |       :
  |       | <---- |
  |       |
  |       |     worker(async)
  |       | ----> |
  |       |       :
  |       | <---- |
  |       |
  |       |     process
  |       | ----> |
  |       |       |
  |       | <---- |
  |       |
  | <---- |
  |
[output]
var streams = build({
  main: LazyChain(),
  sub: LazyChain(),
  proc: LazyChain()
});

streams.main.notify('');

function build(streams) {
  streams.proc
    .map(encodeURI);

  streams.sub
    .lazy()
    .stream(streams.proc)
    .lazy(req)
    .filter(isXHR)
    .map(conv);

  streams.main
    .stream(streams.sub)
    .stream(alert);

  return streams;
}

function req(v) {
  return $.ajax(v);
}

function isXHR(v) {
  return v instanceof Object;
}

function conv(xhr) {
  return xhr.responseText;
}
// Double dispatch by pattern match
class A {
  constructor(public val?) {
  }
  type = 1
}
class B {
  constructor(public val?) {
  }
  type = 2
}

var f = LazyChain.dispatcher<A|B, string>([
    [<A|B>{ val: 0 }],
    _ => 'val 0'
  ], [
    [<A|B>{ val: Number }],
    _ => 'val Number'
  ], [
    [A],
    _ => 'A'
  ], [
    [<B>{ type: 2 }],
    _ => 'type 2'
  ], [
    [B],
    _ => 'B'
  ]);

f(new A());  // 'A'
f(new B());  // 'type 2'
f(new A(0)); // 'val 0'
f(new A(1)); // 'val Number'
// Asynchronous method chain
LazyChain([1, 2])
  .lazy(function (v, i, a, e, d) { setTimeout(function () { d.resolve(v * 2) }, 50) }, true)
  .map(function (v) { return v * 3 })
  .lazy(function (v, i, a, e, d) { setTimeout(function () { d.resolve(v * 10) }, 50) }, true)
  .reduce(function (r, v, i, a) { return r + v }, 0)
  .forEach(function (v) {
    console.log(v); // 180 = (1 * 2 * 3 * 10) + (2 * 2 * 3 * 10)
  });

LazyChain($.ajax(''))
  .filter(function (v) { return 'object' === typeof v })
  .forEach(function (xhr) {
    console.log(xhr); // XHR object
  });
LazyChain(true);
['./']
  .lazy(function (v) { return $.ajax(v) })
  .filter(function (v) { return 'object' === typeof v })
  .forEach(function (xhr) {
    console.log(xhr); // XHR object
  });
LazyChain(false);

// Stream generate and control
var a = LazyChain(),
    b = LazyChain();

LazyChain(a)
  .stream('number', b)
  .stream(function (v, i, a, e) {
    console.log(v); // 0
  });

a.notify(0, '');
b
  .stream(function (v, i, a, e) {
    console.log(typeof v); // string
  });
// Maybe
var Just = Number,
    Nothing = Error;
 
LazyChain<number>([-1, 0, 1, NaN])
  .pattern([
    Number, n => n > 0,
    n => Just(n)
  ], [
    Number,
    _ => Nothing()
  ], [
    void 0,
    _ => Nothing()
  ])
  .pattern([
    Just,
    n => Just(n * 100)
  ])
  .pattern([
    Just,
    n => console.log(Just, n) // 1
  ], [
    Nothing,
    e => console.log(Nothing, e)
  ]);

// Either
type Either = [number, number|typeof Number];
type EitherValue = [number, number];
var LEFT: Either =
      [1, Number],
    Left =
      (data: number) => <EitherValue>[LEFT[0], data],
    RIGHT: Either =
      [0, Number],
    Right =
      (data: number) => <EitherValue>[RIGHT[0], data],
    Either = {
      return: Right,
      bind: (m: EitherValue, f: typeof Right|typeof Left) => <EitherValue>f.apply(undefined, [m[1]]),
      fail: _ => Left(NaN)
    };
var monad =
  LazyChain<number>()
    .monad<Either>(Either, false)
    .monadic([
      RIGHT,
      data => Right(data + 1)
    ], [
      LEFT,
      data => Left(data)
    ]);
var stream =
  LazyChain<number>();
stream
  .monad<Either>(Either)
  .stream(monad)
  .monadic([
    RIGHT,
    function (data) {
      console.log(data); // 1
      return Right(data);
    }
  ]);
stream.notify(0);

Extend

Underscore.js / Lo-Dash

LazyChain([1, 2, 3], _)
  .stream(function (v) {
    console.log(v); // 1, 2, 3
  })
  .difference([1, 3])
  .stream(function (v) {
    console.log(v); // 2
  });

Installation

npm i lazychain

Documentation

API

Spec

Sorry, japanese documents only. I welcome translation.

Browser

  • IE9+
  • Chrome
  • Firefox
  • Safari
  • Android
  • iOS

License

MIT License