Skip to content

Commit

Permalink
Writer functor
Browse files Browse the repository at this point in the history
  • Loading branch information
d-plaindoux committed Sep 17, 2023
1 parent 1c839d1 commit 65b0a35
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/standard/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

use crate::core::hkp::HKP;
use crate::specs::functor::Functor;
use std::marker::PhantomData;

pub struct Writer<'a, E: 'a, F: HKP<'a>, A: 'a>(F::T<(A, E)>);
Expand All @@ -14,3 +15,13 @@ pub struct WriterK<'a, E, F: HKP<'a>>(PhantomData<&'a E>, PhantomData<F>);
impl<'a, E, F: HKP<'a>> HKP<'a> for WriterK<'a, E, F> {
type T<B: 'a> = Writer<'a, E, F, B>;
}

impl<'e, E, F: Functor<'e>> Functor<'e> for WriterK<'e, E, F> {
fn map<A, B, MAP>(f: MAP, ma: Self::T<A>) -> Self::T<B>
where
MAP: Fn(A) -> B + 'e,
{
let Writer(va) = ma;
Writer(F::map(move |(a, e)| (f(a), e), va))
}
}

0 comments on commit 65b0a35

Please sign in to comment.