com.github.tonivade.purefun.runtimes.FutureZIORuntime Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2019, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.runtimes;
import static com.github.tonivade.purefun.instances.FutureInstances.monadDefer;
import static java.util.Objects.requireNonNull;
import java.util.concurrent.Executor;
import com.github.tonivade.purefun.concurrent.Future;
import com.github.tonivade.purefun.type.Either;
import com.github.tonivade.purefun.zio.ZIO;
import com.github.tonivade.purefun.zio.ZIORuntime;
public class FutureZIORuntime implements ZIORuntime {
private Executor executor;
public FutureZIORuntime() {
this(Future.DEFAULT_EXECUTOR);
}
public FutureZIORuntime(Executor executor) {
this.executor = requireNonNull(executor);
}
@Override
public Future> run(R env, ZIO effect) {
return effect.foldMap(env, monadDefer(executor)).fix1(Future::narrowK);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy