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

continuable-fantasy

v0.0.5

Published

Fantasy-land compliant continuables

Downloads

4

Readme

Continuable-fantasy

Turn the awesome continuable into a fantasy land compliant functor and monad.

Since it is based of continuable any error will short circuit the chain and propagate all the way to the end. The Fantasy-land spec lets you use the very familiar .map() function on any compliant type, and sometimes more.

// -- List --
var arr = Array('Hello world')
// => array with one item ('Hello world')

arr.map(function(s) { return s.toUpperCase() })
// => new array with one item ('HELLO WORLD')


// -- Async --
var later = ContinuableFantasy.of('Hello world')
// => function that will be called with (null, 'Hello world')

later.map(function(s) { return s.toUpperCase() })
// => new function that will be called with (null, 'HELLO WORLD')

Example

var buffer = ContinuableFantasy(fs.readFile.bind(null, './simple.js'))

// Make the buffer a string
buffer.map(String)

// Take only first line
.map(function(str) {
  return str.split('\n')[0]
})

// Consume the error or result
.consume(handleError, console.log)


// (function(err, data) { 
//    if (err) return handleError(err);
//    console.log(val)
// })
// Is ok too, if you prefer that. It's just callbacks under the hood


function handleError(err) {
  console.log(err) // Not that handled, but you get the point
}

Docs

// type Continuable<T>: (Error, Value) => void

Extender/Decorator

ContinuableFantasy( Continuable<T> ) => contFantasy<T>

var contBuffer = fs.readFile.bind(null, 'fileName')

// Extends contBuffer with map, chain and consume
ContinuableFantasy(contBuffer)

Instanse methods

contFantasy<A>.map( func:(A) => B ) => contFantasy<B>

contFantasy<Buffer>.map(function(buffer) {
  return buffer.toString()
})
// => contFantasy<String>

contFantasy<A>.chain( func:(A) => contFantasy<B> ) => contFanasy<B>

contFantasy<String>.chain(function(str) {
  var json = JSON.parse(str)
  // The data from the old continuable is used to determine the new
  return ContinuableFantasy(fs.readFile.bind(null, json.property))
})
// => contFantasy<Buffer>

contFantasy<A>.consume( (Error) => void, (A) => void ) => void

contFantasy<String>.consume(
  function(error) {
    console.log('There was an error')
    console.log(error)
  },
  function(string)
    // String ready for usage
    console.log(string)
  )

Static methods

ContinuableFantasy.of( Value ) => contFantasy<Value>

ContinuableFantasy.of( 'Hello' ).consume(null, function(s) {
  assert.equal(s, 'Hello')
})

ContinuableFantasy.error( Error ) => contFantasy<void>

var error = new Error('Bad bad thing, do not throw in node')
ContinuableFantasy.error( err ).consume(function(err) {
  assert.equal(err, error)
}) // Did not handle success

ContinuableFantasy.join( Continuable<Continuable<T>> ) => contFantasy<T>

var contOfA = ContinuableFantasy.of('So nested')
var contOfContOfA = ContinuableFantasy.of(contOfA)

ContinuableFantasy.join(contOfContOfA)
.consume(null, function(s) {
  assert.equal(s, 'So nested')
})

Fantasy Land Compatible

License MIT