Skip to content

Instantly share code, notes, and snippets.

@jfirebaugh
Forked from anonymous/playground.rs
Created October 16, 2016 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfirebaugh/369959a0d6d7f744a51fef0dcb5a4117 to your computer and use it in GitHub Desktop.
Save jfirebaugh/369959a0d6d7f744a51fef0dcb5a4117 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