tuplemagic
TupleMagic is a Rust library that provides utilities for manipulating tuples through various operations like mapping, filtering, nesting, and reducing. This library supports both value-level and type-level operations on tuples.
Details
TupleMagic transforms tuples into a nested form which allows for varargs-like
processing of tuple types. An input tuple of type (A, B, C) becomes the nested
form (A, (B, (C, EOT))).
Turning tuples into nested types simplifies filtering and mapping operations because it leverages recursive type structures, which are inherently more adaptable to recursive traits.
Note that some features of this library are only available in macro form as the
non-macro form of the operation may be unergonomic (ie: filter and map
operations).
Features
- Nesting and Unnesting: Transform tuples into nested structures and vice versa.
# use *;
let a = .nest;
- Mapping: Apply transformations to each element of a tuple based on a predicate.
# use *;
type T = ;
type U = tuple_mapper!;
- Filtering: Include or exclude elements from a tuple based on a predicate.
# use *;
type T = ;
tuple_filter_predicate!;
type U = tuple_filter!;
- Reducing: Reduce a tuple to a single value using a reducer.
# use *;
;
let out = reduce;
Operations
| Operation | Value Level | Type Level |
|---|---|---|
| Nesting | Yes | Yes |
| Unnesting | Yes | Yes |
| Mapping | Yes | No |
| Filtering | Yes | Yes |
| Reducing | Yes | No |
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"