pub mod collectors;
pub mod geometric_optics;
pub mod iter_ext;
pub mod logic;
pub mod optics;
pub mod profunctor;
pub mod signal;
pub mod simd;
pub mod step;
pub mod stream;
pub mod transducer;
pub mod transforms;
#[cfg(target_arch = "wasm32")]
pub mod pipeline;
#[cfg(target_arch = "wasm32")]
pub mod geometric_optics_wasm;
#[cfg(target_arch = "wasm32")]
pub mod optics_wasm;
pub use step::{cont, is_stopped, stop, unwrap_step, Step};
pub use transducer::{Compose, Identity, Transducer};
pub use transforms::{
Aperture, Chunk, Drop, DropWhile, Filter, FlatMap, Interpose, Map, Reject, RepeatEach, Scan,
Take, TakeWhile, Tap, Unique, UniqueBy,
};
pub use collectors::{
cartesian_product, contains, count, cycle, difference, drop_last, every, find, first,
frequencies, group_by, intersection, last, max, max_by, mean, median, merge, min, min_by, mode,
none, partition, partition_by, product, quantile, range, reduce, repeat, reservoir_sample,
reverse, some, sort_by, sort_with, std_dev, sum, symmetric_difference, take_last, to_vec,
top_k, unfold, union, variance, zip, zip_longest, zip_with,
};
pub use logic::{all_pass, any_pass, both, complement, either, IfElse, Unless, When};
pub use optics::{ComposedLens, Fold, Iso, Lens, Optional, Prism, Traversal};
pub use karpal_optics::{Getter, Review, Setter};
pub use geometric_optics::{
blade_grade, blades_at_grade_count, component_get, component_set, grade_extract, grade_indices,
grade_involution, grade_mask, grade_project, grade_project_max, has_grade, is_pure_grade, norm,
norm_squared, normalize,
};
#[cfg(target_arch = "wasm32")]
pub use pipeline::Pipeline;
#[cfg(target_arch = "wasm32")]
pub use geometric_optics_wasm::{
blade_grade as wasm_blade_grade, blades_at_grade_count as wasm_blades_at_grade_count,
component_get as wasm_component_get, component_set as wasm_component_set,
grade_extract as wasm_grade_extract, grade_indices as wasm_grade_indices,
grade_involution as wasm_grade_involution, grade_mask as wasm_grade_mask,
grade_project as wasm_grade_project, grade_project_max as wasm_grade_project_max,
has_grade as wasm_has_grade, is_pure_grade as wasm_is_pure_grade, mv_norm, mv_norm_squared,
mv_normalize, mv_reverse,
};
#[cfg(target_arch = "wasm32")]
pub use optics_wasm::{
fold, iso, lens, lens_path, optional, prism, traversal, JsFold, JsIso, JsLens, JsOptional,
JsPrism, JsTraversal,
};
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[cfg(all(target_arch = "wasm32", not(test)))]
#[wasm_bindgen(start)]
pub fn main() {
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_basic_pipeline() {
let pipeline = Map::new(|x: i32| x * 2)
.compose(Filter::new(|x: &i32| x % 3 == 0))
.compose(Take::new(5));
let result = to_vec(&pipeline, 1..100);
assert_eq!(result, vec![6, 12, 18, 24, 30]);
}
#[test]
fn test_early_termination() {
let pipeline = Take::<i32>::new(3);
let result = to_vec(&pipeline, 1..1_000_000);
assert_eq!(result, vec![1, 2, 3]);
}
#[test]
fn test_composition_laws() {
let f = Map::new(|x: i32| x * 2);
let id = Identity::<i32>::new();
let left = id.compose(Map::new(|x: i32| x * 2));
let right = Map::new(|x: i32| x * 2).compose(Identity::<i32>::new());
let data = vec![1, 2, 3, 4, 5];
assert_eq!(to_vec(&left, data.clone()), to_vec(&f, data.clone()));
assert_eq!(to_vec(&right, data.clone()), to_vec(&f, data.clone()));
}
#[test]
fn test_no_intermediate_allocations() {
let pipeline = Map::new(|x: i32| x * 2)
.compose(Filter::new(|x: &i32| *x > 5))
.compose(Map::new(|x: i32| x + 1))
.compose(Take::new(3));
let result = to_vec(&pipeline, 1..100);
assert_eq!(result, vec![7, 9, 11]);
}
}