diff --git a/README.md b/README.md index 966e66a05..24794a05e 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,7 @@ In this project I have implemented some patterns of functional programming that there are not such thing, but it can be simulated using a especial codification of types. In Scala we can define a higher kinded typed just like this `Monad[F[_]]` but in Java it can be codified -like this `Monad`. `Witness` is a simple mark interface. Then we can define a type using a special -codification like this: +like this `Monad`. Then we can define a type using a special codification like this: ```java interface SomeType extends SomeTypeOf { } @@ -58,12 +57,12 @@ interface SomeTypeOf implements Kind { return (SomeType) hkt; } - static Fixer, SomeType> toSomeType() { + static Function, SomeType> toSomeType() { return SomeType::narrowK; } } -final class SomeType_ extends Witness { +final class SomeType_ { private SomeType_() {} } ``` @@ -504,7 +503,7 @@ With higher kinded types simulation we can implement typeclases. ### Functor ```java -public interface Functor extends Invariant { +public interface Functor extends Invariant { Kind map(Kind value, Function1 map); } @@ -513,7 +512,7 @@ public interface Functor extends Invariant { ### Applicative ```java -public interface Applicative extends Functor { +public interface Applicative extends Functor { Kind pure(T value); @@ -529,7 +528,7 @@ public interface Applicative extends Functor { ### Selective ```java -public interface Selective extends Applicative { +public interface Selective extends Applicative { Kind select(Kind> value, Kind> apply); @@ -546,7 +545,7 @@ public interface Selective extends Applicative { ### Monad ```java -public interface Monad extends Selective { +public interface Monad extends Selective { Kind flatMap(Kind value, Function1> map); @@ -603,7 +602,7 @@ The same like `SemigroupK` but for a `Monoid`. ### Invariant ```java -public interface Invariant { +public interface Invariant { Kind imap(Kind value, Function1 map, Function1 comap); } ``` @@ -611,7 +610,7 @@ public interface Invariant { ### Contravariant ```java -public interface Contravariant extends Invariant { +public interface Contravariant extends Invariant { Kind contramap(Kind value, Function1 map); } ``` @@ -619,7 +618,7 @@ public interface Contravariant extends Invariant { ### Bifunctor ```java -public interface Bifunctor { +public interface Bifunctor { Kind, D> bimap(Kind, B> value, Function1 leftMap, Function1 rightMap); } ``` @@ -627,7 +626,7 @@ public interface Bifunctor { ### Profunctor ```java -public interface Profunctor { +public interface Profunctor { Kind, D> dimap(Kind, B> value, Function1 contramap, Function1 map); } ``` @@ -635,7 +634,7 @@ public interface Profunctor { ### Applicative Error ```java -public interface ApplicativeError extends Applicative { +public interface ApplicativeError extends Applicative { Kind raiseError(E error); @@ -646,7 +645,7 @@ public interface ApplicativeError extends Applicative { ### Monad Error ```java -public interface MonadError extends ApplicativeError, Monad { +public interface MonadError extends ApplicativeError, Monad { default Kind ensure(Kind value, Producer error, Matcher1 matcher) { return flatMap(value, a -> matcher.match(a) ? pure(a) : raiseError(error.get())); @@ -657,7 +656,7 @@ public interface MonadError extends ApplicativeError ### Monad Throw ```java -public interface MonadThrow extends MonadError { +public interface MonadThrow extends MonadError { } ``` @@ -665,7 +664,7 @@ public interface MonadThrow extends MonadError ### MonadReader ```java -public interface MonadReader extends Monad { +public interface MonadReader extends Monad { Kind ask(); @@ -678,7 +677,7 @@ public interface MonadReader extends Monad { ### MonadState ```java -public interface MonadState extends Monad { +public interface MonadState extends Monad { Kind get(); Kind set(S state); @@ -699,7 +698,7 @@ public interface MonadState extends Monad { ### MonadWriter ```java -public interface MonadWriter extends Monad { +public interface MonadWriter extends Monad { Kind writer(Tuple2 value); Kind> listen(Kind value); @@ -714,7 +713,7 @@ public interface MonadWriter extends Monad { ### Comonad ```java -public interface Comonad extends Functor { +public interface Comonad extends Functor { Kind coflatMap(Kind value, Function1, B> map); @@ -729,7 +728,7 @@ public interface Comonad extends Functor { ### Foldable ```java -public interface Foldable { +public interface Foldable { B foldLeft(Kind value, B initial, Function2 mapper); @@ -740,9 +739,9 @@ public interface Foldable { ### Traverse ```java -public interface Traverse extends Functor, Foldable { +public interface Traverse extends Functor, Foldable { - Kind> traverse(Applicative applicative, Kind value, + Kind> traverse(Applicative applicative, Kind value, Function1> mapper); } ``` @@ -750,7 +749,7 @@ public interface Traverse extends Functor, Foldable { ### Semigroupal ```java -public interface Semigroupal { +public interface Semigroupal { Kind> product(Kind fa, Kind fb); } @@ -759,7 +758,7 @@ public interface Semigroupal { ### Defer ```java -public interface Defer { +public interface Defer { Kind defer(Producer> defer); } @@ -768,7 +767,7 @@ public interface Defer { ### Bracket ```java -public interface Bracket extends MonadError { +public interface Bracket extends MonadError { Kind bracket(Kind acquire, Function1> use, Consumer1 release); } @@ -777,7 +776,7 @@ public interface Bracket extends MonadError { ### MonadDefer ```java -public interface MonadDefer extends MonadThrow, Bracket, Defer, Timer { +public interface MonadDefer extends MonadThrow, Bracket, Defer, Timer { default Kind later(Producer later) { return defer(() -> Try.of(later::get).fold(this::raiseError, this::pure)); @@ -788,7 +787,7 @@ public interface MonadDefer extends MonadThrow, Bracket extends MonadDefer { +public interface Async extends MonadDefer { Kind async(Consumer1>> consumer); @@ -798,7 +797,7 @@ public interface Async extends MonadDefer { ### Timer ```java -public interface Timer { +public interface Timer { Kind sleep(Duration duration); } @@ -809,7 +808,7 @@ public interface Timer { It represents a natural transformation between two different kinds. ```java -public interface FunctionK { +public interface FunctionK { Kind apply(Kind from); } ```