qubit-function 0.18.2

Functional programming traits and Box/Rc/Arc adapters for Rust, inspired by Java functional interfaces
// =============================================================================
//    Copyright (c) 2025 - 2026 Haixing Hu.
//
//    SPDX-License-Identifier: Apache-2.0
//
//    Licensed under the Apache License, Version 2.0.
// =============================================================================

use qubit_function::BoxFunction;
use qubit_function::Function;

#[test]
fn test_box_conditional_function_applies_matching_branch() {
    let double = BoxFunction::new(|value: &i32| value * 2);
    let identity = BoxFunction::<i32, i32>::identity();
    let conditional = double.when(|value: &i32| *value > 0).or_else(identity);

    assert_eq!(conditional.apply(&5), 10);
    assert_eq!(conditional.apply(&-5), -5);
}