Functional Weave
Code in TypeScript

money.compare@2.0.0

impl/rust/max_money.rs

559 bytes · the Rust implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

use super::funejson::Value;  ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::money_amount::{money_from_value, money_to_value, Money};  ← from money.amount ^1.0.0 · built alongside by fune
use super::money_compare_compare_money::compare_money;  ← compareMoney, another function of this group · built into the same file, even by a slim install

/// The larger amount; the first when they are equal.
///
/// # Panics
/// Panics if the two amounts are in different currencies.
pub fn max_money(a: &Money, b: &Money) -> Money {
    if compare_money(b, a) > 0 { b.clone() } else { a.clone() }
}

pub fn fune_vector(args: &[Value]) -> Value {
    money_to_value(&max_money(
        &money_from_value(&args[0]),
        &money_from_value(&args[1]),
    ))
}