function

Macro function 

Source
macro_rules! function {
    ($name:ident: $input:ty => $output:ty = $body:expr) => { ... };
}
Expand description

Macro for creating named function morphisms with type annotations.

This macro provides a convenient syntax for creating function morphisms with explicit type annotations, making the code more readable and self-documenting. This replaces the deprecated Composable trait functionality.

ยงExamples

use rustica::category::function_category::{function, FunctionCategory};
use rustica::traits::category::Category;

function!(double: i32 => i32 = |x: i32| x * 2);
function!(to_string: i32 => String = |x: i32| x.to_string());

assert_eq!(double(21), 42);
assert_eq!(to_string(42), "42");

// Example of composing the created morphisms
let pipeline = FunctionCategory::compose_morphisms(&to_string, &double);
assert_eq!(pipeline(5), "10");