Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Pattern matching in javascript for asynchronous iteration
tree: f45c8b827f

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
node_modules
samples
.travis.yml
README.md
package.json
pattern.js

README.md

pattern

pattern is a way to do pattern matching in javascript that helps you do asynchronous iterations.

var insertAll = require('p')
  , _
  ;

// pretending we are doing an async call
function insertElement(data, callback) {
  setTimeout(function() { callback(null, data); }, 100);
}

insertAll([], _, function (cb) { cb(); });
insertAll(function (l,cb) {
  var elem = l.shift(); // head
  insertElement(elem, function(err, elem) {
    if(err) { return cb(err); }
    console.log(elem + ' inserted');
    insertAll(l, cb);
  });
}); 

insertAll([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function () { 
  console.log('done'); 
});

this is what you normally would do.

installation

node.js

  1. install npm
  2. npm install p
  3. var p = require('p');

browser

  1. minimize p.js
  2. load it into your webpage

disclaimer

if you are not familiar with haskell and you love your javascript oo code you better look away right now. this pretty much breaks everything you love and care about in javascript.

pattern was made so i could learn some more javascript. it's slow, and certainly not web scale. this software does not obey laws, common best practices or even common sense. it does everything that is wrong in javascript; or at least attempts to. (suggestions are welcome)

i'll probably still use it anyway

roadmap

check issues

contribute

everyone is welcome to contribute. patches, bug-fixes, new features

  1. create an issue so the community can comment on your idea
  2. fork pattern
  3. create a new branch git checkout -b feature_name
  4. create tests for the changes you made
  5. make sure you pass both existing and newly inserted tests
  6. commit your changes
  7. push to your branch git push origin feature_name
  8. create an pull request

meta

(oO)--',- in caos

license

copyright 2012 nuno job (oO)--',--

licensed under the apache license, version 2.0 (the "license"); you may not use this file except in compliance with the license. you may obtain a copy of the license at

http://www.apache.org/licenses/LICENSE-2.0

unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. see the license for the specific language governing permissions and limitations under the license.

Something went wrong with that request. Please try again.