Skip to content

Instantly share code, notes, and snippets.

@rkuhn
Last active May 16, 2020 08:39
Show Gist options
  • Save rkuhn/1f48b322ed16ecf046a40ae1bd45c5c0 to your computer and use it in GitHub Desktop.
Save rkuhn/1f48b322ed16ecf046a40ae1bd45c5c0 to your computer and use it in GitHub Desktop.
struct X<T>(T);
impl<T> X<T> {
pub fn new(t: T) -> Self {
Self(t)
}
pub fn map<U>(&self, mut f: impl FnMut(&T) -> U + 'static) -> X<U> {
X(f(&self.0))
}
}
pub fn main() {
let x = X::new(42);
let y = x.map(|x| (*x, ""));
let z = y.map(|(a, _b)| *a);
}
struct X<T>(T);
impl<T> X<T> {
pub fn new(t: T) -> Self {
Self(t)
}
pub fn map<U>(self, mut f: impl FnMut(T) -> U + 'static) -> X<U> {
X(f(self.0))
}
}
pub fn main() {
let x = X::new(42);
let y = x.map(|x| (x, ""));
let z = y.map(|(a, _b)| a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment