Skip to content

Commit 4c8c2af

Browse files
committed
feat: Add apply_to combinator
1 parent 74d8236 commit 4c8c2af

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ pub trait GenericCombinators {
122122
fn chain_opt<X>(self, o: Option<X>, f: impl FnOnce(Self, X) -> Self) -> Self
123123
where
124124
Self: Sized;
125+
126+
/// Helper method to revert function application order.
127+
/// ```
128+
/// # use famedly_rust_utils::GenericCombinators;
129+
/// "huge multiline expression here".apply_to(|x| println!("{x}"));
130+
/// ```
131+
fn apply_to<X>(self, f: impl FnOnce(Self) -> X) -> X
132+
where
133+
Self: Sized;
125134
}
126135

127136
impl<A> GenericCombinators for A {
@@ -151,6 +160,11 @@ impl<A> GenericCombinators for A {
151160
self
152161
}
153162
}
163+
164+
#[inline]
165+
fn apply_to<X>(self, f: impl FnOnce(Self) -> X) -> X {
166+
f(self)
167+
}
154168
}
155169

156170
/// Helper function to convert values to `()`

0 commit comments

Comments
 (0)