{"id":17254284,"url":"https://github.com/waynevanson/indexed-state-rust","last_synced_at":"2025-10-12T07:24:27.889Z","repository":{"id":214114327,"uuid":"735714639","full_name":"waynevanson/indexed-state-rust","owner":"waynevanson","description":"The `IndexedState` monad from Haskell, implemented in Rust without allocations","archived":false,"fork":false,"pushed_at":"2023-12-26T08:54:12.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-12T07:24:27.614Z","etag":null,"topics":[],"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/waynevanson.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}},"created_at":"2023-12-25T23:38:26.000Z","updated_at":"2023-12-26T08:05:04.000Z","dependencies_parsed_at":"2023-12-26T00:29:32.896Z","dependency_job_id":"538870da-f3b8-456d-b65e-529cac494666","html_url":"https://github.com/waynevanson/indexed-state-rust","commit_stats":null,"previous_names":["waynevanson/stateful-monad-rust","waynevanson/indexed-state-rust"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/waynevanson/indexed-state-rust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waynevanson%2Findexed-state-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waynevanson%2Findexed-state-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waynevanson%2Findexed-state-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waynevanson%2Findexed-state-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waynevanson","download_url":"https://codeload.github.com/waynevanson/indexed-state-rust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waynevanson%2Findexed-state-rust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010651,"owners_count":26084784,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-15T07:08:13.258Z","updated_at":"2025-10-12T07:24:27.829Z","avatar_url":"https://github.com/waynevanson.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `indexed_state`\n\nA Rust implementation of the `IndexedState` monad pattern from functional languages like Haskell.\n\n## Installation\n\nAdd this git repository to your dependencies.\n\n```toml\n[dependencies.stateful]\ngit = \"https://github.com/waynevanson/indexed-state-rust\"\n```\n\n## Usage\n\nPlease see the trait `Stateful` for more details, for now.\n\n### Summary\n\nAn `IndexedState` a structure that stores a stateful computation, where a computation is a function that takes state and returns a value and some state.\n\n```rust\nFnOnce(Input) -\u003e (Value, Output)\n```\n\nThe above signature implements `IndexedState`, so creating this in the form of a closure means the combinators on the trait are available for composition.\n\nFor example, if we were creating a PRNG, it would look like this.\n\n```rust\nuse index_state::IndexedState;\n\nfn from_usize_to_16(seed: usize) -\u003e u16 {\n    (seed % (u16::MAX as usize + 1)) as u16\n}\n\n// Implementation of an Linear Congruent Generator\nfn increment(seed: usize) {\n    (1164525 * seed + 1013904223) % (2**32)\n}\n\nfn prng_u16(seed: usize) {\n    (from_usize_to_u16(seed), increment(seed))\n}\n\nfn main() {\n    // as a function\n    let prng = prng_u16;\n\n    // as a closure\n    let prng = |seed: usize| {\n        (from_usize_to_u16(seed), increment(seed))\n    };\n\n    // or using the constructors and combinators\n    let prng = indexed_state::new::\u003cusize\u003e()\n        .map(from_usize_to_u16)\n        .map_state(increment)\n\n\n    let input_seed = 1234567890;\n\n    // consume the state, returning the value state\n    let (value, state) = prng_16.run(input_seed);\n\n    // consume the state, returning the value only\n    let value = prng_16.evaluate(input_seed)\n\n    // consume the state, returning the state only\n    let state = prng_16.execute(input_seed)\n}\n```\n\n### Caveats\n\nClosures are pure (`FnOnce`). Will consider adding a way where closures are `Fn` so that `run` can be called multiple times on a structure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaynevanson%2Findexed-state-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaynevanson%2Findexed-state-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaynevanson%2Findexed-state-rust/lists"}