Created
May 26, 2015 05:49
-
-
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>`
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
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