{"id":20181829,"url":"https://github.com/nichoth/pull-with-latest","last_synced_at":"2025-08-22T06:33:00.154Z","repository":{"id":77400165,"uuid":"87247600","full_name":"nichoth/pull-with-latest","owner":"nichoth","description":"Combine a stream with the latest value from another stream","archived":false,"fork":false,"pushed_at":"2017-12-04T23:44:50.000Z","size":9,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-19T01:32:41.141Z","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/nichoth.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-05T00:19:34.000Z","updated_at":"2018-01-31T22:04:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d99c6fc-2ecf-4776-a1ac-9be013fcd7ba","html_url":"https://github.com/nichoth/pull-with-latest","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fpull-with-latest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fpull-with-latest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fpull-with-latest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fpull-with-latest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nichoth","download_url":"https://codeload.github.com/nichoth/pull-with-latest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241616696,"owners_count":19991543,"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-11-14T02:36:50.804Z","updated_at":"2025-03-03T06:12:35.317Z","avatar_url":"https://github.com/nichoth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pull with latest\n\nTake two streams, and return a new stream that emits every value from the first stream with the most recent value from the other stream. This operator is sometimes called 'sample'.\n\n## install \n\n    npm install pull-with-latest\n\n## example\n\n```js\nvar test = require('tape')\nvar withLatest = require('../')\nvar S = require('pull-stream')\n\ntest('pass null for the default predicate', function (t) {\n    t.plan(2)\n    var predicate = null\n\n    S(\n        withLatest.apply(null, [predicate].concat(sources())),\n        S.collect(function (err, res) {\n            t.error(err)\n            t.deepEqual(res, [\n                [2, 'a'],\n                [4, 'b'],\n                [6, 'c']\n            ], 'should combine the streams ok')\n        })\n    )\n})\n\ntest('use predicate function', function (t) {\n    t.plan(2)\n    var predicate = function (a, b) {\n        return { a: a, b: b }\n    }\n\n    S(\n        withLatest.apply(null, [predicate].concat(sources())),\n        S.collect(function (err, res) {\n            t.error(err)\n            t.deepEqual(res, [\n                { a:2, b:'a' },\n                { a:4, b:'b' },\n                { a:6, b:'c' }\n            ], 'should combine the streams ok')\n        })\n    )\n})\n\n\nfunction sources () {\n    var sampler = S(\n        S.values(['a','b','c']),\n        S.asyncMap(function (ev, cb) {\n            setTimeout(function () {\n                cb(null, ev)\n            }, 210)\n        })\n    )\n\n    var otherStream = S(\n        S.values([1,2,3,4,5,6]),\n        S.asyncMap(function (ev, cb) {\n            setTimeout(function () {\n                cb(null, ev)\n            }, 100)\n        })\n    )\n\n    return [otherStream, sampler]\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fpull-with-latest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnichoth%2Fpull-with-latest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fpull-with-latest/lists"}