Skip to content

Provides an iter_from_closure function for getting an Iterator<Item = Item> from FnMut() -> Option<Item>

Notifications You must be signed in to change notification settings

Centril/iter_from_closure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

iter_from_closure

Note: As of Rust 1.34.0, the standard library contains std::iter::from_fn. If you can, prefer using that function instead of the one in this crate.

Iterator<Item = Item> creation for one-time use iterators from mutable closures in the form FnMut() -> Option<Item>.

Please read the API documentation here.

crates

Usage

How to use with cargo:

[dependencies]
iter_from_closure = "1.0.0"

How to use in your crate:

extern crate iter_from_closure;

use iter_from_closure::iter_from_closure;

let mut count = 5;
let iter = iter_from_closure(|| {
    let c = count;
    count = c - 1;
    if c > 0 { Some(c) } else { None }
});

assert_eq!(vec![5, 4, 3, 2, 1], iter.collect::<Vec<_>>());

Recent Changes

  • 1.0.0 - Initial version. Unlikely to be more.

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 or the MIT license, at your option. This file may not be copied, modified, or distributed except according to those terms.

About

Provides an iter_from_closure function for getting an Iterator<Item = Item> from FnMut() -> Option<Item>

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages