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

something-something

v0.0.1

Published

a little asynchronous functional programming library.

Downloads

232

Readme

something something

go crazy? don't mind if i do...

a little asynchronous functional programming library.

why?

There are plenty of collections libraries out there (think underscore, lodash, etc) and plenty of asynchronous ones (async comes to mind), but none of them seem to support asynchronous mapping over plain old JavaScript objects. So I wrote this for that use-case, and while I was at it generalized it to handle both objects and arrays.

how?

Use the package manager of your choice to install. We support

# npm
npm install --save something-something

# component
component install couchand/something-something

# bower
bower install something-something

Require it in your project and start asynchronizing.

__ = require 'something-something'

double = (value, cb) -> cb null, value * 2
ba_s = (key, value, cb) -> cb null, /ba./.test key

original =
  foo: 1
  bar: 2
  baz: 3

__.map original, double, (error, doubled) ->
  __.filter doubled, ba_s, (error, result) ->
    assert Object.keys(result).length is 2
    assert result.bar is 4
    assert result.baz is 6

Simple, right?

what?

The standard functional collections methods are here.

All methods work equally well for arrays and objects.

map

__.map(collection, iterator, [complete])

collection = Array
           | Object
iterator   = (value, cb) -> result
           | (key, value, cb) -> result
           | (key, value, collection, cb) -> result
complete   = (error, results) ->

Standard map function, known in some circles as collect. The iterator function is called for each element in the collection. Its behavior is guessed from the airity of the function, so don't try any fancy business with arguments here.

The complete callback is called with the results collection once every iteration is complete. If any iteration callsback with an error the map immediately fails, calling back with that error.

filter

__.filter(collection, predicate, [complete])

collection = Array
           | Object
predicate  = (value, cb) -> Boolean
           | (key, value, cb) -> Boolean
           | (key, value, collection, cb) -> Boolean
complete   = (error, results) ->

Standard filter function, also known as select. The predicate is called for each element in the collection. Again its behavior is assumed based on the airity. The result is coerced to a Boolean.

The complete callback is called with the filtered results once every predicate is complete. If any predicate callsback with an error the filter immediately fails, calling back with that error.

any

__.any(collection, predicate, [complete])

collection = Array
           | Object
predicate  = (value, cb) -> Boolean
           | (key, value, cb) -> Boolean
           | (key, value, collection, cb) -> Boolean
complete   = (error, result) ->

Short-circuiting boolean or (aka some). Callsback true as soon as any of the predicates callsback true. Callsback false if every predicate callsback false.

Callsback with an error if any predicate callsback in error before one callsback true. This means it swallows some errors and not others, which may not be desirable.

all

collection = Array
           | Object
predicate  = (value, cb) -> Boolean
           | (key, value, cb) -> Boolean
           | (key, value, collection, cb) -> Boolean
complete   = (error, result) ->

Short-circuiting boolean and (aka every). Callsback false as soon as a single predicate callsback false. Callsback true if every predicate callsback true.

Callsback with an error if any predicate callsback in error before one callsback false. This means it swallows some errors and not others, which may not be desirable.

what, no reduce?

This library is about eagerly evaluating a sequence of asynchronous callbacks massively parallel. Reduce is by nature a series algorithm. If you think there's a good way to write reduce in the same style as the other methods please do submit a pull request.

╭╮☲☲☲╭╮