com.github.tonivade.purefun.instances.URIOInstances Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2022, 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.effect.URIOOf.toURIO;
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.Tuple2;
import com.github.tonivade.purefun.Unit;
import com.github.tonivade.purefun.concurrent.Future;
import com.github.tonivade.purefun.data.Sequence;
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.type.Either;
import com.github.tonivade.purefun.type.Try;
import com.github.tonivade.purefun.typeclasses.Applicative;
import com.github.tonivade.purefun.typeclasses.Async;
import com.github.tonivade.purefun.typeclasses.Bracket;
import com.github.tonivade.purefun.typeclasses.Concurrent;
import com.github.tonivade.purefun.typeclasses.Console;
import com.github.tonivade.purefun.typeclasses.Defer;
import com.github.tonivade.purefun.typeclasses.Fiber;
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 Async> async() {
return URIOAsync.INSTANCE;
}
static Concurrent> concurrent() {
return concurrent(Future.DEFAULT_EXECUTOR);
}
static Concurrent> concurrent(Executor executor) {
return URIOConcurrent.instance(executor);
}
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