-
-
Save jfirebaugh/369959a0d6d7f744a51fef0dcb5a4117 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