Skip to content

Instantly share code, notes, and snippets.

@MarchLiu
Created May 26, 2015 05:49
Show Gist options
  • Save MarchLiu/8afa138de6485f8041cc to your computer and use it in GitHub Desktop.
Save MarchLiu/8afa138de6485f8041cc to your computer and use it in GitHub Desktop.
expected `core::iter::Map<&mut &core::iter::Iterator<Item=A>, F>`, found `core::iter::Map<&mut core::iter::Iterator<Item=A>, F>`
use std::vec::Vec;
use std::iter::{Iterator, Map};
pub trait Functor<A, B, F: FnMut(&A) -> B> {
type Output;
fn fmap(&self, f: F ) -> <Self as Functor<A, B, F>>::Output;
}
pub trait FunctorMut<A, B, F: FnMut(&A) -> B> {
type Output;
fn fmap(mut self, f: F) -> <Self as Functor<A, B, F>>::Output;
}
impl<A, B, F> Functor<A, B, F> for Vec<A>
where F:FnMut(&A)->B {
type Output=Vec<B>;
fn fmap(&self, f:F) -> Self::Output {
self.into_iter().map(f).collect::<Self::Output>()
}
}
impl<'a, A, B, F:FnMut(&A)->B> Functor<A, B, F> for &'a Iterator<Item=A>
where F:FnMut(&A)->B{
type Output=Map<&'a mut Self, F>;
fn fmap(&self, f:F) -> Self::Output {
self.into_iter().map(f)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment