1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// webrust/src/iter/comprehension.rs
//! # Python-like List and Dictionary Comprehensions
//!
//! Transforms Rust's iterator chains into intuitive Python-like syntax:
//! `.when()` for filtering and `.then()` for mapping with automatic collection.
//!
//! ## Speaking Syntax
//!
//! - `when(predicate)` = filter ("when this condition is true")
//! - `then(mapper)` = map + collect automatically
//!
//! ## List Comprehensions
//!
//! ```rust
//! use webrust::prelude::*;
//! # fn example() {
//! // [x**2 for x in range(10)]
//! let squares: Vec<i32> = 0.to(10).then(|x| x * x);
//!
//! // [x for x in range(20) if x % 2 == 0]
//! let evens: Vec<i32> = 0.to(20)
//! .when(|&x| x % 2 == 0)
//! .then(|x| x);
//! # }
//! ```
//!
//! ## Dictionary Comprehensions
//!
//! ```rust
//! use webrust::prelude::*;
//! use std::collections::HashMap;
//! # fn example() {
//! // {x: x**2 for x in range(5)}
//! let squares: HashMap<i32, i32> = 0.to(5).then(|x| (x, x * x));
//!
//! // {c: ord(c) for c in 'abc'}
//! let codes: HashMap<char, u8> = 'a'.to('d').then(|c| (c, c as u8));
//! # }
//! ```
//!
//! ## Chained Filters
//!
//! ```rust
//! use webrust::prelude::*;
//! # fn example() {
//! // Multiple conditions (webrust advantage)
//! let result: Vec<i32> = 0.to(100)
//! .when(|&x| x % 2 == 0) // Even numbers
//! .when(|&x| x % 3 == 0) // Divisible by 3
//! .then(|x| x * x); // Square them
//! # }
//! ```
//!
//! Type inference automatically detects `Vec<T>` vs `HashMap<K,V>`
//! based on the mapper's return type.