@Test public void bracket() throws SQLException { ResultSet resultSet = mock(ResultSet.class); when(resultSet.getString("id")).thenReturn("value"); EIO<Throwable, String> bracket = EIO.bracket(open(resultSet), getString("id")); assertEquals(Either.right("value"), bracket.safeRunSync()); verify(resultSet).close(); }
public static <E, A extends AutoCloseable, B> EIO<E, B> bracket(EIO<E, ? extends A> acquire, Function1<? super A, ? extends EIO<E, ? extends B>> use) { return new EIO<>(ZIO.bracket(acquire.instance, resource -> use.andThen(EIOOf::<E, B>narrowK).apply(resource).instance)); }
EIO implements EIOOf<E, A> { public static <E, A extends AutoCloseable, B> EIO<E, B> bracket(EIO<E, ? extends A> acquire, Function1<? super A, ? extends EIO<E, ? extends B>> use) { return new EIO<>(ZIO.bracket(acquire.instance, resource -> use.andThen(EIOOf::<E, B>narrowK).apply(resource).instance)); } }
EIO implements EIOOf<E, A> { public static <E, A extends AutoCloseable, B> EIO<E, B> bracket(EIO<E, ? extends A> acquire, Function1<? super A, ? extends EIO<E, ? extends B>> use) { return new EIO<>(ZIO.bracket(acquire.instance, resource -> use.andThen(EIOOf::<E, B>narrowK).apply(resource).instance)); } EIO(ZIO<Nothing, E, A> value); }
EIO implements EIOOf<E, A> { public static <E, A extends AutoCloseable, B> EIO<E, B> bracket(EIO<E, ? extends A> acquire, Function1<? super A, ? extends EIO<E, ? extends B>> use) { return new EIO<>(ZIO.bracket(acquire.instance, resource -> use.andThen(EIOOf::<E, B>narrowK).apply(resource).instance)); } EIO(ZIO<Nothing, E, A> value); @SuppressWarnings("unchecked") ZIO<R, E, A> toZIO(); UIO<A> toUIO(); Either<E, A> safeRunSync(); Future<Either<E, A>> toFuture(); Future<Either<E, A>> toFuture(Executor executor); void safeRunAsync(Executor executor, Consumer1<? super Try<? extends Either<E, ? extends A>>> callback); void safeRunAsync(Consumer1<? super Try<? extends Either<E, ? extends A>>> callback); Kind<F, A> foldMap(Async<F> monad); EIO<E, B> map(Function1<? super A, ? extends B> map); EIO<E, B> flatMap(Function1<? super A, ? extends EIO<E, ? extends B>> map); EIO<A, E> swap(); EIO<B, A> mapError(Function1<? super E, ? extends B> map); EIO<F, A> flatMapError(Function1<? super E, ? extends EIO<F, ? extends A>> map); EIO<F, B> bimap(Function1<? super E, ? extends F> mapError, Function1<? super A, ? extends B> map); EIO<E, B> andThen(EIO<E, ? extends B> next); EIO<E, B> ap(EIO<E, Function1<? super A, ? extends B>> apply); EIO<F, B> foldM(
      Function1<? super E, ? extends EIO<F, ? extends B>> mapError, 
      Function1<? super A, ? extends EIO<F, ? extends B>> map); UIO<B> fold(Function1<? super E, ? extends B> mapError, Function1<? super A, ? extends B> map); UIO<A> recover(Function1<? super E, ? extends A> mapError); EIO<E, A> orElse(EIO<E, ? extends A> other); EIO<E, Tuple2<A, B>> zip(EIO<E, ? extends B> other); EIO<E, A> zipLeft(EIO<E, ? extends B> other); EIO<E, B> zipRight(EIO<E, ? extends B> other); EIO<E, C> zipWith(EIO<E, ? extends B> other, 
      Function2<? super A, ? super B, ? extends C> mapper); EIO<E, A> repeat(); EIO<E, A> repeat(int times); EIO<E, A> repeat(Duration delay); EIO<E, A> repeat(Duration delay, int times); EIO<E, B> repeat(Schedule<Nothing, A, B> schedule); EIO<E, A> retry(); EIO<E, A> retry(int maxRetries); EIO<E, A> retry(Duration delay); EIO<E, A> retry(Duration delay, int maxRetries); EIO<E, A> retry(Schedule<Nothing, E, S> schedule); EIO<E, Tuple2<Duration, A>> timed(); EIO<X, A> refineOrDie(Class<X> type); static EIO<E, C> map2(EIO<E, ? extends A> za, EIO<E, ? extends B> zb, 
      Function2<? super A, ? super B, ? extends C> mapper); static EIO<E, A> absorb(EIO<E, Either<E, A>> value); static Function1<A, EIO<Throwable, B>> lift(Function1<? super A, ? extends B> function); static EIO<E, A> fromEither(Producer<Either<E, ? extends A>> task); static EIO<Throwable, Unit> exec(CheckedRunnable task); static EIO<E, A> pure(A value); static EIO<E, A> defer(Producer<EIO<E, ? extends A>> lazy); static EIO<Throwable, A> task(Producer<? extends A> task); static EIO<Throwable, A> async(Consumer1<Consumer1<? super Try<? extends A>>> consumer); static EIO<Throwable, A> asyncF(Function1<Consumer1<? super Try<? extends A>>, UIO<Unit>> consumer); static EIO<E, A> raiseError(E error); static EIO<E, B> bracket(EIO<E, ? extends A> acquire, 
      Function1<? super A, ? extends EIO<E, ? extends B>> use); static EIO<E, B> bracket(EIO<E, ? extends A> acquire, 
      Function1<? super A, ? extends EIO<E, ? extends B>> use, Consumer1<? super A> release); @SuppressWarnings("unchecked") static EIO<E, Unit> unit(); }
EIO implements EIOOf<E, A> { public static <E, A extends AutoCloseable, B> EIO<E, B> bracket(EIO<E, ? extends A> acquire, Function1<? super A, ? extends EIO<E, ? extends B>> use) { return new EIO<>(ZIO.bracket(acquire.instance, resource -> use.andThen(EIOOf::<E, B>narrowK).apply(resource).instance)); } EIO(ZIO<Nothing, E, A> value); @SuppressWarnings("unchecked") ZIO<R, E, A> toZIO(); UIO<A> toUIO(); Either<E, A> safeRunSync(); Future<Either<E, A>> toFuture(); Future<Either<E, A>> toFuture(Executor executor); void safeRunAsync(Executor executor, Consumer1<? super Try<? extends Either<E, ? extends A>>> callback); void safeRunAsync(Consumer1<? super Try<? extends Either<E, ? extends A>>> callback); Kind<F, A> foldMap(Async<F> monad); EIO<E, B> map(Function1<? super A, ? extends B> map); EIO<E, B> flatMap(Function1<? super A, ? extends EIO<E, ? extends B>> map); EIO<A, E> swap(); EIO<B, A> mapError(Function1<? super E, ? extends B> map); EIO<F, A> flatMapError(Function1<? super E, ? extends EIO<F, ? extends A>> map); EIO<F, B> bimap(Function1<? super E, ? extends F> mapError, Function1<? super A, ? extends B> map); EIO<E, B> andThen(EIO<E, ? extends B> next); EIO<E, B> ap(EIO<E, Function1<? super A, ? extends B>> apply); EIO<F, B> foldM(
      Function1<? super E, ? extends EIO<F, ? extends B>> mapError, 
      Function1<? super A, ? extends EIO<F, ? extends B>> map); UIO<B> fold(Function1<? super E, ? extends B> mapError, Function1<? super A, ? extends B> map); UIO<A> recover(Function1<? super E, ? extends A> mapError); EIO<E, A> orElse(EIO<E, ? extends A> other); EIO<E, Tuple2<A, B>> zip(EIO<E, ? extends B> other); EIO<E, A> zipLeft(EIO<E, ? extends B> other); EIO<E, B> zipRight(EIO<E, ? extends B> other); EIO<E, C> zipWith(EIO<E, ? extends B> other, 
      Function2<? super A, ? super B, ? extends C> mapper); EIO<E, A> repeat(); EIO<E, A> repeat(int times); EIO<E, A> repeat(Duration delay); EIO<E, A> repeat(Duration delay, int times); EIO<E, B> repeat(Schedule<Nothing, A, B> schedule); EIO<E, A> retry(); EIO<E, A> retry(int maxRetries); EIO<E, A> retry(Duration delay); EIO<E, A> retry(Duration delay, int maxRetries); EIO<E, A> retry(Schedule<Nothing, E, S> schedule); EIO<E, Tuple2<Duration, A>> timed(); EIO<X, A> refineOrDie(Class<X> type); static EIO<E, C> map2(EIO<E, ? extends A> za, EIO<E, ? extends B> zb, 
      Function2<? super A, ? super B, ? extends C> mapper); static EIO<E, A> absorb(EIO<E, Either<E, A>> value); static Function1<A, EIO<Throwable, B>> lift(Function1<? super A, ? extends B> function); static EIO<E, A> fromEither(Producer<Either<E, ? extends A>> task); static EIO<Throwable, Unit> exec(CheckedRunnable task); static EIO<E, A> pure(A value); static EIO<E, A> defer(Producer<EIO<E, ? extends A>> lazy); static EIO<Throwable, A> task(Producer<? extends A> task); static EIO<Throwable, A> async(Consumer1<Consumer1<? super Try<? extends A>>> consumer); static EIO<Throwable, A> asyncF(Function1<Consumer1<? super Try<? extends A>>, UIO<Unit>> consumer); static EIO<E, A> raiseError(E error); static EIO<E, B> bracket(EIO<E, ? extends A> acquire, 
      Function1<? super A, ? extends EIO<E, ? extends B>> use); static EIO<E, B> bracket(EIO<E, ? extends A> acquire, 
      Function1<? super A, ? extends EIO<E, ? extends B>> use, Consumer1<? super A> release); @SuppressWarnings("unchecked") static EIO<E, Unit> unit();  }