Skip to content

Instantly share code, notes, and snippets.

@Geal
Last active August 29, 2015 14:15
Show Gist options
  • Save Geal/c8b121788b7fdc4e1b29 to your computer and use it in GitHub Desktop.
Save Geal/c8b121788b7fdc4e1b29 to your computer and use it in GitHub Desktop.
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