Skip to content

Instantly share code, notes, and snippets.

Created October 16, 2016 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/aaa9745f8471659fbc76fc2993522fe8 to your computer and use it in GitHub Desktop.
Save anonymous/aaa9745f8471659fbc76fc2993522fe8 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
enum Expression {
Literal(u32),
Add(Box<Expression>, Box<Expression>),
Sub(Box<Expression>, Box<Expression>)
}
impl Expression {
fn map<F: Fn(Expression) -> Expression>(self, f: F) -> Expression {
match self {
Expression::Literal(_) => self,
Expression::Add(a, b) => Expression::Add(Box::new(f(*a)), Box::new(f(*b))),
Expression::Sub(a, b) => Expression::Sub(Box::new(f(*a)), Box::new(f(*b)))
}
}
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment