A tiny crate mimicking Elixir's pipe operator for Rust without macros.

Overview

Pipette

A small crate for using pipes in Rust.

use pipette::{Pipeline, pipe};

let input = 1;

let output = pipe((
    input
    |a| a * 2,
    |a| a * 3,
    |a| a * 4,
    |a| a * 5,
    |a| a * 6,
    |a| a * 7,
    |a| a * 8,
));

assert_eq!(output, 40_320);

Pipette is unique:

  • Supports polymorphic pipeline sizes
  • Integrates well with IDE
  • Does not require macros or custom traits

How to use Pipette

Pipette uses trait-based polymorphism (the Pipeline trait) to make it easy to assemble closure-based pipelines in Rust. A single pipeline may consist of up to 12 closures and does not require static typing (ie pipe3, pipe4, pipe5 etc.). Instead, the Pipeline trait will allow any tuple, calling compute any any size of pipeline.

fn add_one(a: i32) -> i32 {
    a + 1
}

let r0 = pipe((0, add_one, add_one));
let r1 = pipe((0, add_one, add_one, add_one));
let r2 = pipe((0, add_one, add_one, add_one, add_one));
let r3 = pipe((0, add_one, add_one, add_one, add_one, add_one));

// lazy pipeline
let add_three = (0, add_one, add_one, add_one);

add_three.compute();

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Pipette by you, shall be licensed as MIT, without any additional terms or conditions.

Issues
  • why not use generic arrays?

    why not use generic arrays?

    thank you for great idea but I wonder why arrays are not used instead of tuple, does this implementation have an advantage? sample code :

    pub fn pip<T, F, const N: usize>(init: T, funcs: [F; N]) -> T
    where
        F: FnOnce(T) -> T,
    {
        let mut r = init;
        for f in funcs {
            r = f(r)
        }
        r
    }
    
    opened by robatipoor 1
Owner
Jonathan Kelley
Systems engineer. Passionate about complex systems, data, and business.
Jonathan Kelley
A copypastable guide to implementing simple derive macros in Rust.

A copypastable guide to implementing simple derive macros in Rust. The goal Let's say we have a trait with a getter trait MyTrait {

Imbolc 64 Nov 16, 2021
todo-or-die provides procedural macros that act as checked reminders.

todo-or-die provides procedural macros that act as checked reminders.

David Pedersen 509 Nov 20, 2021
twilight-interactions is a set of macros and utilities to work with Discord Interactions using twilight.

Twilight interactions twilight-interactions is a set of macros and utilities to work with Discord Interactions using twilight. Note: This crate is not

null 8 Nov 14, 2021
Procedural macros for Floccus

floccus-proc Procedural macros for floccus This crate contains procedural attribute macros (currently only one) used by the floccus. But potentially c

ScaleWeather 1 Nov 4, 2021
A metamacro toolkit for writing complex macros.

Big Mac This crate contains the branching_parser! metamacro, which can be used to create complex macros with few lines of code. To use the macro, call

null 1 Nov 14, 2021
RusTiny -- A Rust implementation of Tiny+ language

RusTiny -- A Rust implementation of Tiny+ language 编译器实践 基本要求: 参考《编译原理及实践》的TINY语言编译器(已上传到群中)完成TINY+ 语言(见附录 A)的解释器:即给定满足 TINY+语言的源代码输入,你的解 释器可以给出对其的解释执

M4tsuri 1 Oct 22, 2021
Tiny Commands Toolchain

Tiny Commands Toolchain: TCT A 1.62MB (release profile) monolithic commands kit for casual terminal usage without any run-time dependency. MMade in 17

Defmc 5 Nov 27, 2021
📦 Crate Protocol allows anyone to create, manage, and trade a tokenized basket of assets, which we refer to as a Crate.

?? Crate Protocol Crate Protocol allows anyone to create, manage, and trade a tokenized basket of assets, which we refer to as a Crate. A Crate is alw

Crate Protocol 18 Nov 27, 2021
dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle!

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle (such as rewriting/refactroing your DM code).

SS220 8 Nov 24, 2021
Build fast, reward everyone, and scale without friction.

Scrypto Language for building DeFi apps on Radix. Terminology Package: A collection of blueprints, compiled and published as a single unit. Blueprint:

Radix DLT 55 Nov 18, 2021
Rust crate for parsing stivale and stivale 2 structures.

stivale-rs Rust crate for parsing stivale and stivale 2 structures. Resources Stivale v2 Specification Stivale Specification License Licensed under ei

Anhad Singh 5 Nov 10, 2021
A simple entity-component-system crate for rust with serialization support

Gallium A simple entity-component-system crate for rust with serialization support Usage You can include the library using carge: [dependencies] galli

null 7 Aug 31, 2021
Rust crate to generate, manipulate and traverse trees.

SOCAREL Rust crate to generate, manipulate and traverse trees. It provides iterators for eight different traversal algorithms. Add and remove nodes in

Andreu 8 Nov 14, 2021
A translation of Brendan Galea's Vulkan tutorial into Rust using the ash crate

Rust Light Vulkan Engine This is a translation of Brendan Galea's Vulkan tutorial into rust using the Ash crate. Original tutorial: Brendan Galea's Yo

Mot 6 Nov 16, 2021
Community SVD file, peripheral access crate in embedde Rust for WinnerMicro W800, W801 & W806 chip

Community SVD file, peripheral access crate in embedde Rust for WinnerMicro W800, W801 & W806 chip

Luo Jia 23 Nov 22, 2021
This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you specified.

prae This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you spec

null 36 Sep 12, 2021
This crate defines a single macro that is a brainfunct compile-time interpreter.

Compile Protection This crate defines a single macro that is a brainfunct compile-time interpreter. One example is as follows #![recursion_limit = "18

John Marsden 6 Sep 26, 2021
secmem-proc is a crate designed to harden a process against low-privileged attackers running on the same system trying to obtain secret memory contents of the current process.

secmem-proc is a crate designed to harden a process against low-privileged attackers running on the same system trying to obtain secret memory contents of the current process. More specifically, the crate disables core dumps and tries to disable tracing on unix-like OSes.

null 1 Nov 5, 2021
Example of structuring a proc macro crate for testability

testing-proc-macros Example of structuring a proc macro crate for testability. See accompanying blog post for details. License Licensed under either o

Ferrous Systems 3 Oct 22, 2021