@Test public void ofSuccessTest() { Function<Integer,Try<Integer>> fn = Try.<Integer, Integer>of(i -> i + 1); assertEquals(new Success(2), fn.apply(1)); }
public static <I, O> Function<I, Try<O>> of(ThrowingFunction<I, O> function) { return input -> { try { O result = function.apply(input); return new Success<>(result); } catch (RuntimeException e) { throw e; } catch (Exception e) { return new Failure<>(e); } }; }
Try { public static <I, O> Function<I, Try<O>> of(ThrowingFunction<I, O> function) { return input -> { try { O result = function.apply(input); return new Success<>(result); } catch (RuntimeException e) { throw e; } catch (Exception e) { return new Failure<>(e); } }; } }
Try { public static <I, O> Function<I, Try<O>> of(ThrowingFunction<I, O> function) { return input -> { try { O result = function.apply(input); return new Success<>(result); } catch (RuntimeException e) { throw e; } catch (Exception e) { return new Failure<>(e); } }; }  }
Try { public static <I, O> Function<I, Try<O>> of(ThrowingFunction<I, O> function) { return input -> { try { O result = function.apply(input); return new Success<>(result); } catch (RuntimeException e) { throw e; } catch (Exception e) { return new Failure<>(e); } }; }  static Function<I, Try<O>> of(ThrowingFunction<I, O> function); static Function<I, Supplier<Try<O>>> lazyOf(ThrowingFunction<I, O> function); static Collector<Try<E>, ?, Map<Type, List<Try<E>>>> groupingBySuccess(); static TryCollector<E> collect(); abstract Type getType(); boolean isSuccess(); boolean isFailure(); Try<F> map(Function<E, F> mapper); Try<O> flatMap(Function<E, Try<O>> mapper); Optional<E> toOption(); E getOrThrow(); void ifPresent(Consumer<E> consumer); Success<E> asSuccess(); Failure<E> asFailure(); }
Try { public static <I, O> Function<I, Try<O>> of(ThrowingFunction<I, O> function) { return input -> { try { O result = function.apply(input); return new Success<>(result); } catch (RuntimeException e) { throw e; } catch (Exception e) { return new Failure<>(e); } }; }  static Function<I, Try<O>> of(ThrowingFunction<I, O> function); static Function<I, Supplier<Try<O>>> lazyOf(ThrowingFunction<I, O> function); static Collector<Try<E>, ?, Map<Type, List<Try<E>>>> groupingBySuccess(); static TryCollector<E> collect(); abstract Type getType(); boolean isSuccess(); boolean isFailure(); Try<F> map(Function<E, F> mapper); Try<O> flatMap(Function<E, Try<O>> mapper); Optional<E> toOption(); E getOrThrow(); void ifPresent(Consumer<E> consumer); Success<E> asSuccess(); Failure<E> asFailure();  }