zombie_utils

Crates.iozombie_utils
lib.rszombie_utils
version0.0.4
created_at2025-12-22 09:02:31.822865+00
updated_at2025-12-24 18:16:41.19964+00
descriptionUtility functions and combinators for zombie-rs (bindN, sequence, zip, traverse, etc.)
homepage
repositoryhttps://github.com/kawayww/zombie-rs
max_upload_size
id1999367
size33,540
K.Y. (KawaYww)

documentation

README

zombie_utils

Utility functions and combinators for zombie-rs.

Overview

This crate provides ergonomic APIs for working with Zombie values:

  • zbind! macro: C++-like ergonomic binding: zbind!(|x, y| x+y, a, b)
  • bindN functions (bind2 - bind23): Syntactic sugar for nested bind/map operations
  • Combinators: sequence, zip, zip_with, traverse
  • Extension trait: ZombieExt for fluent method chaining

Usage

use zombie_rs::prelude::*;
use zombie_utils::prelude::*;

fn main() {
    Runtime::init();

    let a = Zombie::new(1);
    let b = Zombie::new(2);
    let c = Zombie::new(3);

    // Using zbind! (Recommended)
    let sum = zbind!(|x, y, z| x + y + z, a.clone(), b.clone(), c.clone());
    assert_eq!(sum.get(), 6);

    // Using bind3
    let sum = bind3(a.clone(), b.clone(), c.clone(), |x, y, z| x + y + z);
    assert_eq!(sum.get(), 6);

    // Using zip (extension method)
    let pair = a.clone().zip(b.clone());
    assert_eq!(pair.get(), (1, 2));

    // Using sequence
    let items = vec![Zombie::new(1), Zombie::new(2), Zombie::new(3)];
    let collected = sequence(items);
    assert_eq!(collected.get(), vec![1, 2, 3]);

    // Using traverse
    let doubled = traverse(vec![1, 2, 3], |x| Zombie::new(x * 2));
    assert_eq!(doubled.get(), vec![2, 4, 6]);
}

API Reference

bindN Functions

// Combine 2-23 Zombie values with a function
let result = bind2(a, b, |va, vb| va + vb);
let result = bind3(a, b, c, |va, vb, vc| va + vb + vc);
// ... up to bind23

Combinators

// Convert Vec<Zombie<T>> to Zombie<Vec<T>>
let combined = sequence(vec![z1, z2, z3]);

// Combine two Zombies into a tuple
let pair = zip(a, b);  // Zombie<(A, B)>

// Combine with a function
let sum = zip_with(a, b, |x, y| x + y);

// Apply function to each element
let results = traverse(items, |x| Zombie::new(process(x)));

Extension Trait (ZombieExt)

use zombie_utils::ZombieExt;

let result = a.zip(b);           // Same as zip(a, b)
let result = a.zip_with(b, f);   // Same as zip_with(a, b, f)
let result = a.filter(|x| *x > 0);
let result = a.filter_map(|x| some_option(x));
let result = a.zip3(b, c);       // Zombie<(A, B, C)>

License

MIT

Commit count: 0

cargo fmt