Last active
August 29, 2015 14:15
-
-
Save Geal/c8b121788b7fdc4e1b29 to your computer and use it in GitHub Desktop.
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
pub type Fun<'a> = Box<FnMut(u8) -> Res<'a> +'a>; | |
pub enum Res<'a> { | |
Done(u8, u8), | |
Incomplete(Fun<'a>) | |
} | |
pub trait FMap { | |
fn fmap<'y,F: Fn(u8) -> u8 + 'y>(&'y mut self, f: F) -> Res<'y>; | |
} | |
impl<'z> FMap for Res<'z> { | |
fn fmap<'y,F: Fn(u8) -> u8 + 'y>(&'y mut self, f: F) -> Res<'y> { | |
match self { | |
&mut Res::Incomplete(ref mut g) => { | |
Res::Incomplete(Box::new(move |input| { | |
let tmp = g(input); | |
let res = tmp.fmap(f); | |
res | |
})) | |
}, | |
&mut Res::Done(i, o) => Res::Done(i,f(o)) | |
} | |
} | |
} | |
fn main() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment