Created
October 16, 2016 21:15
-
-
Save anonymous/aaa9745f8471659fbc76fc2993522fe8 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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