{"id":18016912,"url":"https://github.com/fitzgen/noodles","last_synced_at":"2025-03-26T18:32:33.569Z","repository":{"id":1290377,"uuid":"1231016","full_name":"fitzgen/noodles","owner":"fitzgen","description":"Asynchronous, non-blocking, continuation-passing-style versions of the common higher order functions in `Array.prototype`.","archived":false,"fork":false,"pushed_at":"2011-01-11T08:36:41.000Z","size":112,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T11:59:42.812Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fitzgen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-01-07T19:38:05.000Z","updated_at":"2019-02-19T18:33:46.000Z","dependencies_parsed_at":"2022-08-16T12:55:24.977Z","dependency_job_id":null,"html_url":"https://github.com/fitzgen/noodles","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fnoodles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fnoodles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fnoodles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fnoodles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fitzgen","download_url":"https://codeload.github.com/fitzgen/noodles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245713150,"owners_count":20660353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T04:19:40.738Z","updated_at":"2025-03-26T18:32:33.308Z","avatar_url":"https://github.com/fitzgen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `noodles`\n\nAsynchronous, non-blocking, continuation-passing-style versions of the common\nhigher order functions in `Array.prototype`.\n\n## `noodles(items).reduce(iterFn, callback [, initial])`\n\n`reduce` applies `iterFn` across each item in `items` from left to right,\naccumulating the results. All the other functions provided by `noodles` are\nbased upon this one. It takes the following arguments:\n\n  * `items`: Array of items to reduce.\n\n  * `iterFn`: Function doing the reducing. Is passed four arguments on each\n    iteration:\n\n      1. Accumulated result of reducing items thus far.\n\n      2. The current item.\n\n      3. Function which takes result of reducing the accumulation with the\n         current item and continues the computation.\n\n      4. Function which can be used to break out of the reduce iteration and\n         send callback a final value prematurely.\n\n  * `callback`: Function which takes the resulting value once the iteration has\n    finished (or was short circuited).\n\n  * `initial`: The starting value for reducing, or result if items is\n    empty. This is optional, so long as `items` is not empty. If it is not\n    provided, than the first element in `items` becomes the initial value.\n\nHere is an example use of `reduce` to find the sum of the numbers in an\narray and log them to the console:\n\n    noodles([1,2,3,4,5,6,7,8,9,10]).reduce(function (sum, n, next, exit) {\n        next(sum + n);\n    }, function (sum) {\n        console.log(\"The sum is \" + sum);\n    }, 0);\n\n## `noodles(items).map(iterFn, callback)`\n\nCreate a new array with the results of calling `iterFn` on each of the\n`items`. The order of `items` and their execution is preserved.\n\nHere is an example using node's `fs` module:\n\n    var fs = require(\"fs\");\n    noodles([\"a.txt\", \"b.txt\", \"c.txt\"]).map(function (file, next) {\n        fs.readFile(file, \"utf-8\", function (err, data) {\n            // Ignore errors for brevity.\n            next(data);\n        });\n    }, function (fileBodies) {\n        ...\n    });\n\n## `noodles(items).filter(testFn, callback)`\n\nCreate a new array which consists of only each item in `items` for which\n`testFn(item)` is truthy. The order of `items` and execution is preserved.\n\n## `noodles(items).forEach(iterFn, callback)`\n\nCall `iterFn(item)` for each item in `items` (presumably for side effects). The\norder of items and execution is preserved.\n\nNote that even though you aren't \"returning\" anything to the `next` function\npassed to `iterFn`, you must still call it if you want iteration to continue. If\nyou would like to stop iteration prematurely, you should call the `exit`\nfunction so that `callback` is still triggered. If you do not call either `next`\nor `exit`, `callback` will never be called.\n\nExample:\n\n    noodles(someBigLongArray).forEach(function (item, index, next, exit) {\n        if ( someCondition(item) ) {\n            exit();\n        } else {\n            next();\n        }\n    }, function () {\n        ...\n    });\n\n## `noodles(items).every(testFn, callback)`\n\nIs `testFn(item)` true for every item in `items`? Note that it is vacuously true\nthat every item in an empty array passes the test.\n\nExample:\n\n    function siteIsUp (url, returns) {\n        jQuery.ajax({\n            url: url,\n            success: function () {\n                returns(true);\n            },\n            error: function () {\n                returns(false);\n            }\n        });\n    }\n    var faveSites = [\"http://news.ycombinator.com\",\n                     \"http://google.com/reader\",\n                     \"http://nytimes.com\"];\n    noodles(faveSites).every(siteIsUp, function (res) {\n        if (res) {\n            console.log(\"Time to waste time on the net...\");\n        } else {\n            console.log(\"Oh noes! Not all of my fave sites are up!\");\n        }\n    });\n\n## `noodles(items).some(testFn, callback)`\n\nDoes `iterFn(item)` return a truthy value for at least one item in `items`?\nNote that when the array is empty, there is no item in `items` for which\n`testFn(item)` is true and so the result of calling `some` on an empty\narray is false.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffitzgen%2Fnoodles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffitzgen%2Fnoodles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffitzgen%2Fnoodles/lists"}