com.github.tonivade.purefun.instances.URIOInstances Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2020, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.instances;
import static com.github.tonivade.purefun.concurrent.FutureOf.toFuture;
import static com.github.tonivade.purefun.effect.URIOOf.toURIO;
import static com.github.tonivade.purefun.instances.FutureInstances.async;
import java.time.Duration;
import java.util.concurrent.Executor;
import com.github.tonivade.purefun.Consumer1;
import com.github.tonivade.purefun.Function1;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.Producer;
import com.github.tonivade.purefun.Unit;
import com.github.tonivade.purefun.concurrent.Future;
import com.github.tonivade.purefun.effect.UIO;
import com.github.tonivade.purefun.effect.URIO;
import com.github.tonivade.purefun.effect.URIOOf;
import com.github.tonivade.purefun.effect.URIO_;
import com.github.tonivade.purefun.typeclasses.Applicative;
import com.github.tonivade.purefun.typeclasses.Bracket;
import com.github.tonivade.purefun.typeclasses.Console;
import com.github.tonivade.purefun.typeclasses.Defer;
import com.github.tonivade.purefun.typeclasses.Functor;
import com.github.tonivade.purefun.typeclasses.Monad;
import com.github.tonivade.purefun.typeclasses.MonadDefer;
import com.github.tonivade.purefun.typeclasses.MonadError;
import com.github.tonivade.purefun.typeclasses.MonadThrow;
import com.github.tonivade.purefun.typeclasses.Runtime;
@SuppressWarnings("unchecked")
public interface URIOInstances {
static Functor> functor() {
return URIOFunctor.INSTANCE;
}
static Applicative> applicative() {
return URIOApplicative.INSTANCE;
}
static Monad> monad() {
return URIOMonad.INSTANCE;
}
static MonadThrow> monadThrow() {
return URIOMonadThrow.INSTANCE;
}
static MonadDefer> monadDefer() {
return URIOMonadDefer.INSTANCE;
}
static Console, Throwable>> console() {
return URIOConsole.INSTANCE;
}
static Runtime> runtime(R env) {
return URIORuntime.instance(env);
}
}
interface URIOFunctor extends Functor> {
@SuppressWarnings("rawtypes")
URIOFunctor INSTANCE = new URIOFunctor() {};
@Override
default URIO map(Kind, ? extends A> value,
Function1 super A, ? extends B> map) {
return URIOOf.narrowK(value).map(map);
}
}
interface URIOPure extends Applicative> {
@Override
default URIO pure(A value) {
return URIO.pure(value);
}
}
interface URIOApplicative extends URIOPure {
@SuppressWarnings("rawtypes")
URIOApplicative INSTANCE = new URIOApplicative() {};
@Override
default URIO
ap(Kind, ? extends A> value,
Kind, ? extends Function1 super A, ? extends B>> apply) {
return value.fix(URIOOf::narrowK).ap(apply.fix(URIOOf::narrowK));
}
}
interface URIOMonad extends URIOPure, Monad> {
@SuppressWarnings("rawtypes")
URIOMonad INSTANCE = new URIOMonad() {};
@Override
default URIO
flatMap(Kind, ? extends A> value,
Function1 super A, ? extends Kind, ? extends B>> map) {
return value.fix(toURIO()).flatMap(map.andThen(URIOOf::narrowK));
}
}
interface URIOMonadError extends URIOMonad, MonadError, Throwable> {
@SuppressWarnings("rawtypes")
URIOMonadError INSTANCE = new URIOMonadError © 2015 - 2025 Weber Informatics LLC | Privacy Policy