https://github.com/zakarumych/array-fu
Array comprehension
https://github.com/zakarumych/array-fu
Last synced: about 2 months ago
JSON representation
Array comprehension
- Host: GitHub
- URL: https://github.com/zakarumych/array-fu
- Owner: zakarumych
- License: other
- Created: 2022-04-28T15:27:56.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T18:59:44.000Z (about 3 years ago)
- Last Synced: 2024-10-13T17:16:36.564Z (8 months ago)
- Language: Rust
- Size: 16.6 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: COPYING
Awesome Lists containing this project
README
# array-fu
[](https://crates.io/crates/array-fu)
[](https://docs.rs/array-fu)
[](https://github.com/zakarumych/array-fu/actions?query=workflow%3ARust)
[](COPYING)
This crate defines [`array!`] and other macros that can construct arrays.
Use simple syntax, make it more complex as requirements change.[`array!`] macro constructs arrays by repeating expression execution, possibly with enumeration bound to provided pattern.
# Examples
```
use array_fu::array;
use rand::random;let values: [f32; 2] = array![random(); 2];
```This also means that expression type may not be `Copy` or event `Clone`.
```
use array_fu::array;
# use std::sync::Mutex;
let values = array![Mutex::new(1); 2];
```See more examples in the [`array!`] macro documentation.
[`collect_array!`] macro constructs arrays by repeating expression execution with elements from iterators bound to provided patterns.
# Examples
```
use array_fu::collect_array;let opt = collect_array![x in 1.., y in 2.. => x + y; where x * y > 10; 3];
assert_eq!(opt, Some([7, 9, 11]));
``````
use array_fu::collect_array;let values = collect_array![(x, y) in [(1, 2), (3, 4), (5, 6)] => x + y; 3];
assert_eq!(values, Some([3, 7, 11]));
```See more examples in the [`collect_array!`] macro documentation.
[`array!`]: https://docs.rs/array-fu/latest/array_fu/macro.array.html
[`collect_array!`]: https://docs.rs/array-fu/latest/array_fu/macro.collect_array.html## License
Licensed under either of
* Apache License, Version 2.0, ([license/APACHE](license/APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([license/MIT](license/MIT) or http://opensource.org/licenses/MIT)at your option.
## Contributions
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.