{"id":16162357,"url":"https://github.com/sunsided/map-ok","last_synced_at":"2026-03-16T03:34:10.632Z","repository":{"id":211808335,"uuid":"729992314","full_name":"sunsided/map-ok","owner":"sunsided","description":"Mapping of Ok variants in an iterator","archived":false,"fork":false,"pushed_at":"2024-05-15T19:45:25.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T15:56:14.952Z","etag":null,"topics":["iterators","map-ok","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/map_ok","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunsided.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-12-11T00:35:46.000Z","updated_at":"2024-05-15T19:45:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"f2e6a6e5-7a9e-422d-9ab0-2b215ac406b9","html_url":"https://github.com/sunsided/map-ok","commit_stats":null,"previous_names":["sunsided/map-ok"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fmap-ok","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fmap-ok/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fmap-ok/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fmap-ok/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunsided","download_url":"https://codeload.github.com/sunsided/map-ok/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243382786,"owners_count":20282008,"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":["iterators","map-ok","rust"],"created_at":"2024-10-10T02:29:52.034Z","updated_at":"2025-09-25T12:10:31.030Z","avatar_url":"https://github.com/sunsided.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MapOk / BoxOk\n\n[![codecov](https://codecov.io/gh/sunsided/map-ok/graph/badge.svg?token=DHREBDQ19F)](https://codecov.io/gh/sunsided/map-ok)\n\nThis crate provides the `MapOk` trait that allows mapping `Ok` variants in an iterator to a different type. Instead\nof matching `Result` variants in a `map` call, you call\n\n```rust\nfn example() {\n    let input = [\"10\", \"20\", \"x\", \"30\"];\n    let mut iterator = input.into_iter().map(u32::from_str).map_ok(|x| x * 100);\n}\n```\n\ninstead of the more verbose\n\n```rust\nfn example() {\n    let input = [\"10\", \"20\", \"x\", \"30\"];\n    let mut iterator = input.into_iter().map(u32::from_str).map(|x| match x {\n        Ok(x) =\u003e Ok(x * 100),\n        Err(e) =\u003e Err(e),\n    });\n}\n```\n\nLikewise, the `box_ok` function wraps the contents of the `Ok` variant into a `Box`, i.e. it behaves\nlike `.map_ok(Box::new)`:\n\n```rust\nfn example() {\n    let input = [\"10\", \"20\", \"x\", \"30\"];\n    let results: Vec\u003cResult\u003cBox\u003cu32\u003e, ParseIntError\u003e\u003e = input\n        .into_iter()\n        .map(u32::from_str)\n        .map_ok(|x| x * 100)\n        .box_ok()\n        .collect();\n}\n```\n\n## Examples\n\nBelow is a worked example with a bit more involved parsing:\n\n```rust\nuse std::num::ParseIntError;\nuse std::str::FromStr;\nuse map_ok::MapOk;\n\n/// A struct that represents a person.\nstruct Person {\n    age: u8,\n}\n\nimpl Person {\n    /// Constructs a new `Person` instance.\n    ///\n    /// # Arguments\n    ///\n    /// * `age` - an unsigned 8-bit integer representing a person's age.\n    fn new(age: u8) -\u003e Self {\n        Person { age }\n    }\n}\n\nimpl FromStr for Person {\n    type Err = ParseIntError;\n\n    /// Converts a string slice into a `Person` instance.\n    ///\n    /// # Arguments\n    ///\n    /// * `s` - a string slice that holds the person's age.\n    ///\n    /// # Returns\n    ///\n    /// A result that is either a `Person` or a `ParseIntError`.\n    fn from_str(s: \u0026str) -\u003e Result\u003cSelf, Self::Err\u003e {\n        let age = u8::from_str(s)?;\n        Ok(Person::new(age))\n    }\n}\n\n/// In this example, the `map_ok` function is utilized to transform the `Ok` variant of a `Result`\n/// by mapping the value of the `Person` age.\nfn example() {\n    let input = vec![\"10\", \"20\", \"x\", \"30\"];\n    let mut iterator = input.into_iter()\n        .map(Person::from_str)\n        .map_ok(|p| p.age);\n\n    assert_eq!(iterator.next(), Some(Ok(10)));\n    assert_eq!(iterator.next(), Some(Ok(20)));\n    assert!(iterator.next().unwrap().is_err());\n    assert_eq!(iterator.next(), Some(Ok(30)));\n    assert_eq!(iterator.next(), None);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fmap-ok","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunsided%2Fmap-ok","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fmap-ok/lists"}