Skip to main content

Pipe

Trait Pipe 

Source
pub trait Pipe: Sized {
    // Provided method
    fn pipe<B>(self, f: impl FnOnce(Self) -> B) -> B { ... }
}
Expand description

A trait for left-to-right function application via method syntax.

Pipe provides the .pipe() method on all sized types via a blanket implementation, enabling pipeline-style composition similar to PureScript’s # operator or Haskell’s & operator.

This is particularly useful for composing operations on types where inherent methods are not available (e.g., stdlib types like Option and Vec).

Provided Methods§

Source

fn pipe<B>(self, f: impl FnOnce(Self) -> B) -> B

Pipes self into a function, enabling left-to-right composition.

Applies f to self and returns the result. This is the method syntax version of pipe.

§Type Signature

forall B. (self, Self -> B) -> B

§Type Parameters
  • B: The return type of the function.
§Parameters
  • self: The value to pipe.
  • f: The function to apply to the value.
§Returns

The result of applying f to self.

§Examples
use fp_library::{
	brands::*,
	classes::*,
	functions::*,
};

let result = Some(5)
	.pipe(|x| map::<OptionBrand, _, _>(|n| n + 1, x))
	.pipe(|x| bind::<OptionBrand, _, _>(x, |n| if n > 3 { Some(n) } else { None }));

assert_eq!(result, Some(6));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> Pipe for T

§Type Parameters
  • T: The type that implements Pipe.