{"id":22687389,"url":"https://github.com/cablehead/nu_plugin_stateful_filter","last_synced_at":"2025-08-07T01:31:06.657Z","repository":{"id":250620165,"uuid":"834968496","full_name":"cablehead/nu_plugin_stateful_filter","owner":"cablehead","description":"Nushell plugin to support stateful filtering","archived":false,"fork":false,"pushed_at":"2024-08-27T17:43:46.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-08T20:43:22.347Z","etag":null,"topics":["nushell","nushell-plugin"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/cablehead.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":"2024-07-28T21:15:00.000Z","updated_at":"2024-08-27T17:43:51.000Z","dependencies_parsed_at":"2024-07-28T22:58:26.138Z","dependency_job_id":null,"html_url":"https://github.com/cablehead/nu_plugin_stateful_filter","commit_stats":null,"previous_names":["cablehead/nu_plugin_stateful_filter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cablehead%2Fnu_plugin_stateful_filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cablehead%2Fnu_plugin_stateful_filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cablehead%2Fnu_plugin_stateful_filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cablehead%2Fnu_plugin_stateful_filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cablehead","download_url":"https://codeload.github.com/cablehead/nu_plugin_stateful_filter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228976847,"owners_count":18000694,"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":["nushell","nushell-plugin"],"created_at":"2024-12-09T23:18:10.975Z","updated_at":"2025-08-07T01:31:06.645Z","avatar_url":"https://github.com/cablehead.png","language":"Rust","readme":"## Status: archived\n\n[Thanks](https://github.com/nushell/nushell/pull/14804) to [@Bahex](https://github.com/Bahex), Nushell's built-in [`generate`](https://www.nushell.sh/commands/docs/generate.html#generate-for-generators) command [now](https://github.com/nushell/nushell/pull/14804) supports this functionality.\n\n```nushell\n$messages\n| each {|x| sleep 1sec; $x }\n| generate {|x, state={found: false, last: null}|\n    if $state.found {\n        { out: $x, next: $state }\n    } else if $x.type == \"threshold\" {\n        { out: $state.last, next: {found: true, last: null} }\n    } else {\n        { next: {found: false, last: $x} }\n    }\n}\n```\n\n## the sketch\n\nIt's similar to the\n[`generate`](https://www.nushell.sh/commands/docs/generate.html#generate-for-generators)\ncommand, but instead of generating a pipeline with no input, it allows you to\nprocess an input pipeline.\n\nIt's also similar to the\n[`reduce`](https://www.nushell.sh/commands/docs/reduce.html) command, but it\npreserves the pipeline, allowing streaming. With `reduce`, you would accumulate\na list in memory.\n\n## Usage\n\n```nushell\nlet messages = [\n    { type: \"data\", value: 1 }\n    { type: \"data\", value: 2 }\n    { type: \"data\", value: 3 }\n    { type: \"threshold\" }\n    { type: \"data\", value: 4 }\n    { type: \"data\", value: 5 }\n]\n\n# output the last message seen before encountering a “threshold” message,\n# then output all subsequent messages in real time\n\n$messages | each {|x| sleep 1sec; $x } | stateful filter {found: false} { |state, x|\n    if $state.found {\n        return { out: $x }\n    }\n\n    if $x.type == \"threshold\" {\n        return { state: {found: true}, out: ($state | get last?) }\n    }\n\n    { state: {found: false, last: $x} }\n}\n```\n\nOutputs:\n\n```\n{ type: \"data\", value: 3 }\n{ type: \"data\", value: 4 }\n{ type: \"data\", value: 5 }\n```\n\n## Usage\n\n```\nRun closure on each element of a list\n\nUsage:\n  \u003e stateful filter \u003cinitial\u003e \u003cclosure\u003e\n\nFlags:\n  -h, --help - Display the help message for this command\n\nParameters:\n  initial \u003cany\u003e: The initial state to pass to the closure\n  closure \u003cclosure(any, any)\u003e:\n    The closure receives `|state, value|` and should return a record in the\n    shape: { out?: value, state?: new_state }. Both `out` and `state` are\n    optional. You can drop rows by omitting the `out` key, and the current\n    state is preserved if its key is omitted.\n\nInput/output types:\n  ─#─┬────input────┬───output────\n   0 │ list-stream │ list-stream\n  ───┴─────────────┴─────────────\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcablehead%2Fnu_plugin_stateful_filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcablehead%2Fnu_plugin_stateful_filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcablehead%2Fnu_plugin_stateful_filter/lists"}