{"id":13822690,"url":"https://github.com/dtolnay/reduce","last_synced_at":"2025-05-16T17:31:36.505Z","repository":{"id":57659163,"uuid":"61503292","full_name":"dtolnay/reduce","owner":"dtolnay","description":"iter.reduce(fn) in Rust","archived":true,"fork":false,"pushed_at":"2022-12-19T18:35:43.000Z","size":70,"stargazers_count":36,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-16T18:46:17.770Z","etag":null,"topics":["iterator","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dtolnay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-19T22:26:43.000Z","updated_at":"2024-08-28T23:01:51.000Z","dependencies_parsed_at":"2023-01-29T22:25:19.195Z","dependency_job_id":null,"html_url":"https://github.com/dtolnay/reduce","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Freduce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Freduce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Freduce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Freduce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dtolnay","download_url":"https://codeload.github.com/dtolnay/reduce/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225442924,"owners_count":17475144,"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":["iterator","rust"],"created_at":"2024-08-04T08:02:12.818Z","updated_at":"2024-11-19T23:30:56.358Z","avatar_url":"https://github.com/dtolnay.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"iter.reduce(fn)\n===============\n\n[\u003cimg alt=\"github\" src=\"https://img.shields.io/badge/github-dtolnay/reduce-8da0cb?style=for-the-badge\u0026labelColor=555555\u0026logo=github\" height=\"20\"\u003e](https://github.com/dtolnay/reduce)\n[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/reduce.svg?style=for-the-badge\u0026color=fc8d62\u0026logo=rust\" height=\"20\"\u003e](https://crates.io/crates/reduce)\n[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-reduce-66c2a5?style=for-the-badge\u0026labelColor=555555\u0026logo=docs.rs\" height=\"20\"\u003e](https://docs.rs/reduce)\n[\u003cimg alt=\"build status\" src=\"https://img.shields.io/github/actions/workflow/status/dtolnay/reduce/ci.yml?branch=master\u0026style=for-the-badge\" height=\"20\"\u003e](https://github.com/dtolnay/reduce/actions?query=branch%3Amaster)\n\nThis crate gives Iterators a `reduce` function that is similar to\n[`fold`][std-fold] but without an initial value. The function returns `None` if\nthe iterator is empty and `Some(value)` otherwise. This matches the distinction\nbetween [`reduce`][scala-reduce] and [`fold`][scala-fold] in Scala.\n\n[std-fold]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.fold\n[scala-reduce]: https://www.scala-lang.org/api/current/scala/collection/Iterator.html#reduce[A1%3E:A](op:(A1,A1)=%3EA1):A1\n[scala-fold]: https://www.scala-lang.org/api/current/scala/collection/Iterator.html#fold[A1%3E:A](z:A1)(op:(A1,A1)=%3EA1):A1\n\n```toml\n[dependencies]\nreduce = \"0.1\"\n```\n\n## Examples\n\n```rust\nuse reduce::Reduce;\n\nfn main() {\n    // Reduce a non-empty iterator into Some(value)\n    let v = vec![1usize, 2, 3, 4, 5];\n    let sum = v.into_iter().reduce(|a, b| a + b);\n    assert_eq!(Some(15), sum);\n\n    // Reduce an empty iterator into None\n    let v = Vec::\u003cusize\u003e::new();\n    let sum = v.into_iter().reduce(|a, b| a + b);\n    assert_eq!(None, sum);\n}\n```\n\n\u003cbr\u003e\n\n#### License\n\n\u003csup\u003e\nLicensed under either of \u003ca href=\"LICENSE-APACHE\"\u003eApache License, Version\n2.0\u003c/a\u003e or \u003ca href=\"LICENSE-MIT\"\u003eMIT license\u003c/a\u003e at your option.\n\u003c/sup\u003e\n\n\u003cbr\u003e\n\n\u003csub\u003e\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this crate by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtolnay%2Freduce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdtolnay%2Freduce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtolnay%2Freduce/lists"}