Skip to content

Commit

Permalink
Finish Reader and add copyright
Browse files Browse the repository at this point in the history
  • Loading branch information
d-plaindoux committed Sep 17, 2023
1 parent 0bf3973 commit b20beb6
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/core/hkp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

pub trait HKP<'a> {
type T<A: 'a>;
}
6 changes: 6 additions & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

pub mod hkp;
pub mod transform;
6 changes: 6 additions & 0 deletions src/core/transform.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use crate::core::hkp::HKP;

pub trait Transform<'a, A>: HKP<'a> {
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

pub mod core;
pub mod specs;
pub mod standard;
6 changes: 6 additions & 0 deletions src/specs/applicative.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use crate::specs::functor::Functor;

pub trait Applicative<'a>: Functor<'a> {
Expand Down
6 changes: 6 additions & 0 deletions src/specs/bind.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use crate::specs::applicative::Applicative;

pub trait Bind<'a>: Applicative<'a>
Expand Down
6 changes: 6 additions & 0 deletions src/specs/functor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use crate::core::hkp::HKP;

pub trait Functor<'a>: HKP<'a> {
Expand Down
6 changes: 6 additions & 0 deletions src/specs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

pub mod applicative;
pub mod bind;
pub mod functor;
Expand Down
6 changes: 6 additions & 0 deletions src/specs/monad.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use crate::specs::bind::Bind;

pub trait Monad<'a>: Bind<'a> {
Expand Down
6 changes: 6 additions & 0 deletions src/standard/either.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use std::marker::PhantomData;

use crate::core::hkp::HKP;
Expand Down
6 changes: 6 additions & 0 deletions src/standard/identity.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use crate::core::hkp::HKP;
use crate::specs::applicative::Applicative;
use crate::specs::bind::Bind;
Expand Down
5 changes: 4 additions & 1 deletion src/standard/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

*/
pub mod either;
pub mod identity;
pub mod option;
Expand Down
6 changes: 6 additions & 0 deletions src/standard/option.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use crate::core::hkp::HKP;
use crate::specs::applicative::Applicative;
use crate::specs::bind::Bind;
Expand Down
26 changes: 26 additions & 0 deletions src/standard/reader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use crate::core::hkp::HKP;
use crate::specs::applicative::Applicative;
use crate::specs::bind::Bind;
Expand Down Expand Up @@ -61,6 +67,26 @@ impl<'e, E: Copy, F: Bind<'e> + 'e> Bind<'e> for ReaderK<'e, E, F> {

impl<'e, E: Copy, F: Bind<'e> + 'e> Monad<'e> for ReaderK<'e, E, F> {}

impl<'e, E: Copy + 'e, F: Monad<'e> + 'e> ReaderK<'e, E, F> {
pub fn reader<A>(f: fn(E) -> F::T<A>) -> Reader<'e, E, F, A> {
Reader(Box::new(f), PhantomData)
}

pub fn run<A>(reader: Reader<'e, E, F, A>) -> Box<dyn FnOnce(E) -> F::T<A> + 'e> {
let Reader(f, _) = reader;
f
}

pub fn ask() -> Reader<'e, E, F, E> {
Reader(Box::new(F::returns), PhantomData)
}

pub fn local<A>(f: fn(E) -> E, reader: Reader<'e, E, F, A>) -> Reader<'e, E, F, A> {
let Reader(run, _) = reader;
Reader(Box::new(move |e| run(f(e))), PhantomData)
}
}

pub mod infix {
use crate::core::hkp::HKP;
use crate::core::transform::Transform;
Expand Down
6 changes: 6 additions & 0 deletions src/standard/result.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use std::marker::PhantomData;

use crate::core::hkp::HKP;
Expand Down
6 changes: 6 additions & 0 deletions src/standard/vec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

use crate::core::hkp::HKP;
use crate::specs::applicative::Applicative;
use crate::specs::bind::Bind;
Expand Down
6 changes: 6 additions & 0 deletions tests/test_applicative.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

#[cfg(test)]
mod tests_apply {
use maitar::specs::applicative::Applicative;
Expand Down
6 changes: 6 additions & 0 deletions tests/test_bind.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

#[cfg(test)]
mod tests_join {

Expand Down
6 changes: 6 additions & 0 deletions tests/test_functor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

#[cfg(test)]
mod tests_map {

Expand Down
6 changes: 6 additions & 0 deletions tests/test_monad.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* MIT License
*
* Copyright (c) 2023 Didier Plaindoux
*/

#[cfg(test)]
mod tests_returns {

Expand Down

0 comments on commit b20beb6

Please sign in to comment.