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

recfun

v0.0.11

Published

Functionally Recursive Application State Manager

Downloads

3

Readme

recfun: Recursive(ly?) Functional Application State Manager

Recfun can be used to make composable processes. ##API

  • close: function(fun)
    • The close function takes a function as it's parameter. It is appended to the history array.
  • history: array Array containing all functions that have been supplied with close()
  • run: function([to])
    • Executes the first function in history. It's output is then passed on as the parameter of the following function. If to argument is supplied, the return value will be the function at position to in the history.
  • states: [ ]
    • array When ever checkout is executed, this array will be keep the results of each execution. This way you can see how the application is modifying the initial data. The difference between states and history are 2: History keeps additonal elements that compress previous results. History keeps functions, while states keeps the results of those functions.
  • checkout: function([from])
    • Similar to as run, but will execute starting from the last known executed state.
  • collapse: TODO
  • chain: TODO

Example

// assuming Node (console) context
var recfun = require('recfun');
var model = new recfun.recfun();
model.close(function(){
    // random binary data used as our model
    return "00110";
});
model.close(function(o){
    // turn string into array of characters 
    return o.split("");
});
model.close(function(o){
    // turn array values into int
    return o.map(function(value,index,array){
        return parseInt(value);
    });
});
model.close(function(o){
    // check if values > 0
    return o.map(function(value,index,array){
        return value>0;
    })
});
model.close(function(o){
    // print results
    console.log(o);
    return o;
});
// toString() logs the recfun object. checkout() hasn't been called yet
// so function return values have not been chached in recfun.states
model.toString(); 	// => { history:[ [Function], [Function], [Function], 
//					  [Function], [Function] ],
//				states: [],
//				debug: false,
//				checkpoint: 0 }
					
// run([from]) executes the function chain from beggining to end
// without caching the results. It takes an optional 
// parameter *from* that tells it to start running from a certain 
// point in the function chain this may be useful if you have cached
// some results using checkout().
// the return value is the return value in the last function executed 
// which means that if the last function does NOT return anything, the 
// return value is undefined
model.run();	// => [ false, false, true, false, true ]

// checkout([to]) executes the function chain from beggining to end 
// while caching the results in recfun.states. It takes an optional 
// parameter *to* that tells it to stop executing at a certain point 
// in the function chain. like run() the return value is the return 
// value in the last function executed which means that if the last 
// function does NOT return anything, the return value is undefined
model.checkout();// => [ false, false, true, false, true ]

// if we use toString() again, we see all the changes to the data on 
// the recfun.states array
model.toString(); // => { 	history:[ 
//					  [Function],[Function],[Function],
//				 	  [Function],[Function],[Function]
// 					 ],
//				states:[ 
//				 	'00110',
//				 	[ '0', '0', '1', '1', '0' ], 
// 				 	[ 0, 0, 1, 1, 0 ],
// 				  	[ false, false, true, true, false ],
// 				 	[ false, false, true, true, false ]
// 				 	],
//				debug: false,
//				checkpoint: 5 }