pub struct BoxBiTransformerOnce<T, U, R> { /* private fields */ }Expand description
BoxBiTransformerOnce - consuming bi-transformer wrapper based on
Box<dyn FnOnce>
A bi-transformer wrapper that provides single ownership with one-time use semantics. Consumes self and both input values.
§Features
- Based on:
Box<dyn FnOnce(T, U) -> R> - Ownership: Single ownership, cannot be cloned
- Reusability: Can only be called once (consumes self and inputs)
- Thread Safety: Not thread-safe (no
Send + Syncrequirement)
§Author
Haixing Hu
Implementations§
Source§impl<T, U, R> BoxBiTransformerOnce<T, U, R>
impl<T, U, R> BoxBiTransformerOnce<T, U, R>
Sourcepub fn new<F>(f: F) -> Selfwhere
F: FnOnce(T, U) -> R + 'static,
pub fn new<F>(f: F) -> Selfwhere
F: FnOnce(T, U) -> R + 'static,
Creates a new bi-transformer.
Wraps the provided closure in the appropriate smart pointer type for this bi-transformer implementation.
Examples found in repository?
18fn main() {
19 println!("=== BoxBiTransformerOnce and_then Method Example ===\n");
20
21 // Example 1: Basic and_then usage
22 println!("Example 1: Basic and_then usage");
23 let add = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
24 let double = |x: i32| x * 2;
25 let composed = add.and_then(double);
26 let result = composed.apply(3, 5);
27 println!(" (3 + 5) * 2 = {}", result);
28 assert_eq!(result, 16);
29 println!();
30
31 // Example 2: Type conversion
32 println!("Example 2: Type conversion");
33 let add2 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
34 let to_string = |x: i32| x.to_string();
35 let composed2 = add2.and_then(to_string);
36 let result2 = composed2.apply(20, 22);
37 println!(" (20 + 22).to_string() = \"{}\"", result2);
38 assert_eq!(result2, "42");
39 println!();
40
41 // Example 3: Multi-level chained composition
42 println!("Example 3: Multi-level chained composition");
43 let add3 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
44 let double3 = |x: i32| x * 2;
45 let to_string3 = |x: i32| format!("Result: {}", x);
46 let composed3 = add3.and_then(double3).and_then(to_string3);
47 let result3 = composed3.apply(3, 5);
48 println!(" (3 + 5) * 2 -> \"{}\"", result3);
49 assert_eq!(result3, "Result: 16");
50 println!();
51
52 // Example 4: String operations
53 println!("Example 4: String operations");
54 let concat = BoxBiTransformerOnce::new(|x: String, y: String| format!("{} {}", x, y));
55 let uppercase = |s: String| s.to_uppercase();
56 let composed4 = concat.and_then(uppercase);
57 let result4 = composed4.apply("hello".to_string(), "world".to_string());
58 println!(" \"hello\" + \"world\" -> uppercase = \"{}\"", result4);
59 assert_eq!(result4, "HELLO WORLD");
60 println!();
61
62 // Example 5: Mathematical calculation chain
63 println!("Example 5: Mathematical calculation chain");
64 let multiply = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
65 let to_float = |x: i32| x as f64 / 2.0;
66 let composed5 = multiply.and_then(to_float);
67 let result5 = composed5.apply(6, 7);
68 println!(" (6 * 7) / 2.0 = {}", result5);
69 assert!((result5 - 21.0).abs() < 1e-10);
70 println!();
71
72 // Example 6: Complex business logic
73 println!("Example 6: Complex business logic");
74 let calculate_total =
75 BoxBiTransformerOnce::new(|price: f64, quantity: i32| price * quantity as f64);
76 let apply_discount = |total: f64| {
77 if total > 100.0 {
78 total * 0.9 // 10% discount
79 } else {
80 total
81 }
82 };
83 let format_price = |total: f64| format!("${:.2}", total);
84 let composed6 = calculate_total
85 .and_then(apply_discount)
86 .and_then(format_price);
87 let result6 = composed6.apply(15.5, 8);
88 println!(" Price: $15.5, Quantity: 8");
89 println!(" Total price (with discount): {}", result6);
90 assert_eq!(result6, "$111.60");
91 println!();
92
93 println!("=== All examples executed successfully! ===");
94}More examples
16fn main() {
17 println!("=== BiTransformerOnce Examples ===\n");
18
19 // Example 1: Basic usage with closure
20 println!("1. Basic usage with closure:");
21 let add = |x: i32, y: i32| x + y;
22 let result = add.apply(20, 22);
23 println!(" 20 + 22 = {}", result);
24
25 // Example 2: BoxBiTransformerOnce with new
26 println!("\n2. BoxBiTransformerOnce with new:");
27 let multiply = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
28 println!(" 6 * 7 = {}", multiply.apply(6, 7));
29
30 // Example 3: Constant transformer
31 println!("\n3. Constant transformer:");
32 let constant = BoxBiTransformerOnce::constant("hello");
33 println!(" constant(123, 456) = {}", constant.apply(123, 456));
34
35 // Example 4: Consuming owned values
36 println!("\n4. Consuming owned values:");
37 let concat = BoxBiTransformerOnce::new(|x: String, y: String| format!("{} {}", x, y));
38 let s1 = String::from("hello");
39 let s2 = String::from("world");
40 let result = concat.apply(s1, s2);
41 println!(" concat('hello', 'world') = {}", result);
42
43 // Example 5: Conditional transformation with when/or_else
44 println!("\n5. Conditional transformation (positive numbers):");
45 let add = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
46 let multiply = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
47 let conditional = add
48 .when(|x: &i32, y: &i32| *x > 0 && *y > 0)
49 .or_else(multiply);
50 println!(" conditional(5, 3) = {} (add)", conditional.apply(5, 3));
51
52 println!("\n6. Conditional transformation (negative numbers):");
53 let add2 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
54 let multiply2 = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
55 let conditional2 = add2
56 .when(|x: &i32, y: &i32| *x > 0 && *y > 0)
57 .or_else(multiply2);
58 println!(
59 " conditional(-5, 3) = {} (multiply)",
60 conditional2.apply(-5, 3)
61 );
62
63 // Example 7: Conditional with closure in or_else
64 println!("\n7. Conditional with closure in or_else:");
65 let add3 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
66 let conditional3 = add3
67 .when(|x: &i32, y: &i32| *x > 0 && *y > 0)
68 .or_else(|x: i32, y: i32| x * y);
69 println!(" conditional(4, 6) = {}", conditional3.apply(4, 6));
70
71 // Example 8: Merging vectors
72 println!("\n8. Merging vectors:");
73 let merge = BoxBiTransformerOnce::new(|mut x: Vec<i32>, y: Vec<i32>| {
74 x.extend(y);
75 x
76 });
77 let v1 = vec![1, 2, 3];
78 let v2 = vec![4, 5, 6];
79 let result = merge.apply(v1, v2);
80 println!(" merge([1, 2, 3], [4, 5, 6]) = {:?}", result);
81
82 // Example 9: Complex transformation with calculation
83 println!("\n9. Complex transformation with calculation:");
84 let calculate = BoxBiTransformerOnce::new(|x: i32, y: i32| {
85 let sum = x + y;
86 let product = x * y;
87 (sum, product)
88 });
89 let (sum, product) = calculate.apply(5, 3);
90 println!(" calculate(5, 3) = (sum: {}, product: {})", sum, product);
91
92 // Example 10: String manipulation
93 println!("\n10. String manipulation:");
94 let process = BoxBiTransformerOnce::new(|x: String, y: String| {
95 format!("{} {} {}", x.to_uppercase(), "and", y.to_lowercase())
96 });
97 println!(
98 " process('Hello', 'WORLD') = {}",
99 process.apply("Hello".to_string(), "WORLD".to_string())
100 );
101
102 // Example 11: Converting to function
103 println!("\n11. Converting to function:");
104 let add4 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
105 let f = add4.into_fn();
106 println!(" f(10, 20) = {}", f(10, 20));
107
108 // Example 12: Converting to box (zero-cost)
109 println!("\n12. Converting to box (zero-cost):");
110 let add5 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
111 let boxed = add5.into_box();
112 println!(" boxed(15, 25) = {}", boxed.apply(15, 25));
113
114 println!("\n=== All examples completed successfully! ===");
115}Sourcepub fn new_with_name<F>(name: &str, f: F) -> Selfwhere
F: FnOnce(T, U) -> R + 'static,
pub fn new_with_name<F>(name: &str, f: F) -> Selfwhere
F: FnOnce(T, U) -> R + 'static,
Creates a new named bi-transformer.
Wraps the provided closure and assigns it a name, which is useful for debugging and logging purposes.
Sourcepub fn new_with_optional_name<F>(f: F, name: Option<String>) -> Selfwhere
F: FnOnce(T, U) -> R + 'static,
pub fn new_with_optional_name<F>(f: F, name: Option<String>) -> Selfwhere
F: FnOnce(T, U) -> R + 'static,
Creates a new named bi-transformer with an optional name.
Wraps the provided closure and assigns it an optional name.
Sourcepub fn name(&self) -> Option<&str>
pub fn name(&self) -> Option<&str>
Gets the name of this bi-transformer.
§Returns
Returns Some(&str) if a name was set, None otherwise.
Sourcepub fn clear_name(&mut self)
pub fn clear_name(&mut self)
Clears the name of this bi-transformer.
Sourcepub fn when<P>(self, predicate: P) -> BoxConditionalBiTransformerOnce<T, U, R>where
T: 'static,
U: 'static,
R: 'static,
P: BiPredicate<T, U> + 'static,
pub fn when<P>(self, predicate: P) -> BoxConditionalBiTransformerOnce<T, U, R>where
T: 'static,
U: 'static,
R: 'static,
P: BiPredicate<T, U> + 'static,
Creates a conditional two-parameter transformer that executes based on bi-predicate result.
§Parameters
predicate- The bi-predicate to determine whether to execute the transformation operation
§Returns
Returns a conditional two-parameter transformer that only executes
when the predicate returns true.
§Examples
use qubit_function::transformers::*;
let bi_transformer = BoxBiTransformer::new({
|key: String, value: i32| format!("{}: {}", key, value)
});
let conditional = bi_transformer
.when(|key: &String, value: &i32| *value > 0)
.or_else(|key: String, _value: i32| key);
assert_eq!(conditional.apply("test".to_string(), 5), "test: 5".to_string()); // transformed
assert_eq!(conditional.apply("test".to_string(), -1), "test".to_string()); // identity (key unchanged)Examples found in repository?
16fn main() {
17 println!("=== BiTransformerOnce Examples ===\n");
18
19 // Example 1: Basic usage with closure
20 println!("1. Basic usage with closure:");
21 let add = |x: i32, y: i32| x + y;
22 let result = add.apply(20, 22);
23 println!(" 20 + 22 = {}", result);
24
25 // Example 2: BoxBiTransformerOnce with new
26 println!("\n2. BoxBiTransformerOnce with new:");
27 let multiply = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
28 println!(" 6 * 7 = {}", multiply.apply(6, 7));
29
30 // Example 3: Constant transformer
31 println!("\n3. Constant transformer:");
32 let constant = BoxBiTransformerOnce::constant("hello");
33 println!(" constant(123, 456) = {}", constant.apply(123, 456));
34
35 // Example 4: Consuming owned values
36 println!("\n4. Consuming owned values:");
37 let concat = BoxBiTransformerOnce::new(|x: String, y: String| format!("{} {}", x, y));
38 let s1 = String::from("hello");
39 let s2 = String::from("world");
40 let result = concat.apply(s1, s2);
41 println!(" concat('hello', 'world') = {}", result);
42
43 // Example 5: Conditional transformation with when/or_else
44 println!("\n5. Conditional transformation (positive numbers):");
45 let add = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
46 let multiply = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
47 let conditional = add
48 .when(|x: &i32, y: &i32| *x > 0 && *y > 0)
49 .or_else(multiply);
50 println!(" conditional(5, 3) = {} (add)", conditional.apply(5, 3));
51
52 println!("\n6. Conditional transformation (negative numbers):");
53 let add2 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
54 let multiply2 = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
55 let conditional2 = add2
56 .when(|x: &i32, y: &i32| *x > 0 && *y > 0)
57 .or_else(multiply2);
58 println!(
59 " conditional(-5, 3) = {} (multiply)",
60 conditional2.apply(-5, 3)
61 );
62
63 // Example 7: Conditional with closure in or_else
64 println!("\n7. Conditional with closure in or_else:");
65 let add3 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
66 let conditional3 = add3
67 .when(|x: &i32, y: &i32| *x > 0 && *y > 0)
68 .or_else(|x: i32, y: i32| x * y);
69 println!(" conditional(4, 6) = {}", conditional3.apply(4, 6));
70
71 // Example 8: Merging vectors
72 println!("\n8. Merging vectors:");
73 let merge = BoxBiTransformerOnce::new(|mut x: Vec<i32>, y: Vec<i32>| {
74 x.extend(y);
75 x
76 });
77 let v1 = vec![1, 2, 3];
78 let v2 = vec![4, 5, 6];
79 let result = merge.apply(v1, v2);
80 println!(" merge([1, 2, 3], [4, 5, 6]) = {:?}", result);
81
82 // Example 9: Complex transformation with calculation
83 println!("\n9. Complex transformation with calculation:");
84 let calculate = BoxBiTransformerOnce::new(|x: i32, y: i32| {
85 let sum = x + y;
86 let product = x * y;
87 (sum, product)
88 });
89 let (sum, product) = calculate.apply(5, 3);
90 println!(" calculate(5, 3) = (sum: {}, product: {})", sum, product);
91
92 // Example 10: String manipulation
93 println!("\n10. String manipulation:");
94 let process = BoxBiTransformerOnce::new(|x: String, y: String| {
95 format!("{} {} {}", x.to_uppercase(), "and", y.to_lowercase())
96 });
97 println!(
98 " process('Hello', 'WORLD') = {}",
99 process.apply("Hello".to_string(), "WORLD".to_string())
100 );
101
102 // Example 11: Converting to function
103 println!("\n11. Converting to function:");
104 let add4 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
105 let f = add4.into_fn();
106 println!(" f(10, 20) = {}", f(10, 20));
107
108 // Example 12: Converting to box (zero-cost)
109 println!("\n12. Converting to box (zero-cost):");
110 let add5 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
111 let boxed = add5.into_box();
112 println!(" boxed(15, 25) = {}", boxed.apply(15, 25));
113
114 println!("\n=== All examples completed successfully! ===");
115}Sourcepub fn and_then<S, F>(self, after: F) -> BoxBiTransformerOnce<T, U, S>where
T: 'static,
U: 'static,
R: 'static,
S: 'static,
F: TransformerOnce<R, S> + 'static,
pub fn and_then<S, F>(self, after: F) -> BoxBiTransformerOnce<T, U, S>where
T: 'static,
U: 'static,
R: 'static,
S: 'static,
F: TransformerOnce<R, S> + 'static,
Chains execution with another two-parameter transformer, executing the current transformer first, then the subsequent transformer.
§Parameters
after- The subsequent two-parameter transformer to execute after the current transformer completes
§Returns
Returns a new two-parameter transformer that executes the current transformer and the subsequent transformer in sequence.
§Examples
use qubit_function::transformers::*;
let bi_transformer1 = BoxBiTransformer::new({
|key: String, value: i32| (key, value + 1)
});
let bi_transformer2 = BoxTransformer::new({
|value: (String, i32)| format!("{}: {}", value.0, value.1)
});
let chained = bi_transformer1.and_then(bi_transformer2);
let result = chained.apply("test".to_string(), 5);
assert_eq!(result, "test: 6"); // (value + 1) = 6Examples found in repository?
18fn main() {
19 println!("=== BoxBiTransformerOnce and_then Method Example ===\n");
20
21 // Example 1: Basic and_then usage
22 println!("Example 1: Basic and_then usage");
23 let add = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
24 let double = |x: i32| x * 2;
25 let composed = add.and_then(double);
26 let result = composed.apply(3, 5);
27 println!(" (3 + 5) * 2 = {}", result);
28 assert_eq!(result, 16);
29 println!();
30
31 // Example 2: Type conversion
32 println!("Example 2: Type conversion");
33 let add2 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
34 let to_string = |x: i32| x.to_string();
35 let composed2 = add2.and_then(to_string);
36 let result2 = composed2.apply(20, 22);
37 println!(" (20 + 22).to_string() = \"{}\"", result2);
38 assert_eq!(result2, "42");
39 println!();
40
41 // Example 3: Multi-level chained composition
42 println!("Example 3: Multi-level chained composition");
43 let add3 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
44 let double3 = |x: i32| x * 2;
45 let to_string3 = |x: i32| format!("Result: {}", x);
46 let composed3 = add3.and_then(double3).and_then(to_string3);
47 let result3 = composed3.apply(3, 5);
48 println!(" (3 + 5) * 2 -> \"{}\"", result3);
49 assert_eq!(result3, "Result: 16");
50 println!();
51
52 // Example 4: String operations
53 println!("Example 4: String operations");
54 let concat = BoxBiTransformerOnce::new(|x: String, y: String| format!("{} {}", x, y));
55 let uppercase = |s: String| s.to_uppercase();
56 let composed4 = concat.and_then(uppercase);
57 let result4 = composed4.apply("hello".to_string(), "world".to_string());
58 println!(" \"hello\" + \"world\" -> uppercase = \"{}\"", result4);
59 assert_eq!(result4, "HELLO WORLD");
60 println!();
61
62 // Example 5: Mathematical calculation chain
63 println!("Example 5: Mathematical calculation chain");
64 let multiply = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
65 let to_float = |x: i32| x as f64 / 2.0;
66 let composed5 = multiply.and_then(to_float);
67 let result5 = composed5.apply(6, 7);
68 println!(" (6 * 7) / 2.0 = {}", result5);
69 assert!((result5 - 21.0).abs() < 1e-10);
70 println!();
71
72 // Example 6: Complex business logic
73 println!("Example 6: Complex business logic");
74 let calculate_total =
75 BoxBiTransformerOnce::new(|price: f64, quantity: i32| price * quantity as f64);
76 let apply_discount = |total: f64| {
77 if total > 100.0 {
78 total * 0.9 // 10% discount
79 } else {
80 total
81 }
82 };
83 let format_price = |total: f64| format!("${:.2}", total);
84 let composed6 = calculate_total
85 .and_then(apply_discount)
86 .and_then(format_price);
87 let result6 = composed6.apply(15.5, 8);
88 println!(" Price: $15.5, Quantity: 8");
89 println!(" Total price (with discount): {}", result6);
90 assert_eq!(result6, "$111.60");
91 println!();
92
93 println!("=== All examples executed successfully! ===");
94}Source§impl<T, U, R> BoxBiTransformerOnce<T, U, R>
impl<T, U, R> BoxBiTransformerOnce<T, U, R>
Sourcepub fn constant(value: R) -> BoxBiTransformerOnce<T, U, R>where
R: Clone + 'static,
pub fn constant(value: R) -> BoxBiTransformerOnce<T, U, R>where
R: Clone + 'static,
Creates a constant bi-transformer
§Examples
/// rust /// use qubit_function::{BoxBiTransformerOnce, BiTransformer}; /// /// let constant = BoxBiTransformerOnce::constant("hello"); /// assert_eq!(constant.apply(123, 456), "hello"); ///
Examples found in repository?
16fn main() {
17 println!("=== BiTransformerOnce Examples ===\n");
18
19 // Example 1: Basic usage with closure
20 println!("1. Basic usage with closure:");
21 let add = |x: i32, y: i32| x + y;
22 let result = add.apply(20, 22);
23 println!(" 20 + 22 = {}", result);
24
25 // Example 2: BoxBiTransformerOnce with new
26 println!("\n2. BoxBiTransformerOnce with new:");
27 let multiply = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
28 println!(" 6 * 7 = {}", multiply.apply(6, 7));
29
30 // Example 3: Constant transformer
31 println!("\n3. Constant transformer:");
32 let constant = BoxBiTransformerOnce::constant("hello");
33 println!(" constant(123, 456) = {}", constant.apply(123, 456));
34
35 // Example 4: Consuming owned values
36 println!("\n4. Consuming owned values:");
37 let concat = BoxBiTransformerOnce::new(|x: String, y: String| format!("{} {}", x, y));
38 let s1 = String::from("hello");
39 let s2 = String::from("world");
40 let result = concat.apply(s1, s2);
41 println!(" concat('hello', 'world') = {}", result);
42
43 // Example 5: Conditional transformation with when/or_else
44 println!("\n5. Conditional transformation (positive numbers):");
45 let add = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
46 let multiply = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
47 let conditional = add
48 .when(|x: &i32, y: &i32| *x > 0 && *y > 0)
49 .or_else(multiply);
50 println!(" conditional(5, 3) = {} (add)", conditional.apply(5, 3));
51
52 println!("\n6. Conditional transformation (negative numbers):");
53 let add2 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
54 let multiply2 = BoxBiTransformerOnce::new(|x: i32, y: i32| x * y);
55 let conditional2 = add2
56 .when(|x: &i32, y: &i32| *x > 0 && *y > 0)
57 .or_else(multiply2);
58 println!(
59 " conditional(-5, 3) = {} (multiply)",
60 conditional2.apply(-5, 3)
61 );
62
63 // Example 7: Conditional with closure in or_else
64 println!("\n7. Conditional with closure in or_else:");
65 let add3 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
66 let conditional3 = add3
67 .when(|x: &i32, y: &i32| *x > 0 && *y > 0)
68 .or_else(|x: i32, y: i32| x * y);
69 println!(" conditional(4, 6) = {}", conditional3.apply(4, 6));
70
71 // Example 8: Merging vectors
72 println!("\n8. Merging vectors:");
73 let merge = BoxBiTransformerOnce::new(|mut x: Vec<i32>, y: Vec<i32>| {
74 x.extend(y);
75 x
76 });
77 let v1 = vec![1, 2, 3];
78 let v2 = vec![4, 5, 6];
79 let result = merge.apply(v1, v2);
80 println!(" merge([1, 2, 3], [4, 5, 6]) = {:?}", result);
81
82 // Example 9: Complex transformation with calculation
83 println!("\n9. Complex transformation with calculation:");
84 let calculate = BoxBiTransformerOnce::new(|x: i32, y: i32| {
85 let sum = x + y;
86 let product = x * y;
87 (sum, product)
88 });
89 let (sum, product) = calculate.apply(5, 3);
90 println!(" calculate(5, 3) = (sum: {}, product: {})", sum, product);
91
92 // Example 10: String manipulation
93 println!("\n10. String manipulation:");
94 let process = BoxBiTransformerOnce::new(|x: String, y: String| {
95 format!("{} {} {}", x.to_uppercase(), "and", y.to_lowercase())
96 });
97 println!(
98 " process('Hello', 'WORLD') = {}",
99 process.apply("Hello".to_string(), "WORLD".to_string())
100 );
101
102 // Example 11: Converting to function
103 println!("\n11. Converting to function:");
104 let add4 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
105 let f = add4.into_fn();
106 println!(" f(10, 20) = {}", f(10, 20));
107
108 // Example 12: Converting to box (zero-cost)
109 println!("\n12. Converting to box (zero-cost):");
110 let add5 = BoxBiTransformerOnce::new(|x: i32, y: i32| x + y);
111 let boxed = add5.into_box();
112 println!(" boxed(15, 25) = {}", boxed.apply(15, 25));
113
114 println!("\n=== All examples completed successfully! ===");
115}