io.vavr.control.Option.some()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(170)

本文整理了Java中io.vavr.control.Option.some()方法的一些代码示例,展示了Option.some()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.some()方法的具体详情如下:
包路径:io.vavr.control.Option
类名称:Option
方法名:some

Option.some介绍

[英]Creates a new Some of a given value.

The only difference to Option#of(Object) is, when called with argument null.

Option.of(null);   // = None 
Option.some(null); // = Some(null)

[中]在给定的值中创建一个新的值。
与(Object)选项#的唯一区别是,当使用参数null调用时。

Option.of(null);   // = None 
Option.some(null); // = Some(null)

代码示例

代码示例来源:origin: vavr-io/vavr

/**
 * Creates a new {@code Option} of a given value.
 *
 * @param value A value
 * @param <T>   type of the value
 * @return {@code Some(value)} if value is not {@code null}, {@code None} otherwise
 */
static <T> Option<T> of(T value) {
  return (value == null) ? none() : some(value);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Filters this right-biased {@code Either} by testing a predicate.
 * <p>
 *
 * @param predicate A predicate
 * @return a new {@code Option} instance
 * @throws NullPointerException if {@code predicate} is null
 */
default Option<Either<L, R>> filter(Predicate<? super R> predicate) {
  Objects.requireNonNull(predicate, "predicate is null");
  return isLeft() || predicate.test(get()) ? Option.some(this) : Option.none();
}

代码示例来源:origin: vavr-io/vavr

@SuppressWarnings({ "unchecked", "varargs" })
@SafeVarargs
public final <R> Option<R> option(Case<? extends T, ? extends R>... cases) {
  Objects.requireNonNull(cases, "cases is null");
  for (Case<? extends T, ? extends R> _case : cases) {
    final Case<T, R> __case = (Case<T, R>) _case;
    if (__case.isDefinedAt(value)) {
      return Option.some(__case.apply(value));
    }
  }
  return Option.none();
}

代码示例来源:origin: vavr-io/vavr

/**
 * Creates a {@code FutureImpl} that is immediately completed with the given value. No task will be started.
 *
 * @param executor An {@link Executor} to run and control the computation and to perform the actions.
 * @param value the result of this Future
 * @param <T> value type of the Future
 * @return a new {@code FutureImpl} instance
 */
static <T> FutureImpl<T> of(Executor executor, Try<? extends T> value) {
  return new FutureImpl<>(executor, Option.some(Try.narrow(value)), null, null, (complete, updateThread) -> {});
}

代码示例来源:origin: vavr-io/vavr

/**
 * Turns this sequence into a plain function returning an Option result.
 *
 * @return a function that takes an index i and returns the value of
 * this sequence in a Some if the index is within bounds, otherwise a None.
 * @deprecated Will be removed
 */
@Deprecated
default Function1<Integer, Option<T>> lift() {
  return i -> (i >= 0 && i < length()) ? Option.some(apply(i)) : Option.none();
}

代码示例来源:origin: vavr-io/vavr

/**
 * Shortcut for {@code isEmpty() ? Option.none() : Option.some(reduceLeft(op))}.
 *
 * @param op A BiFunction of type T
 * @return a reduced value
 * @throws NullPointerException if {@code op} is null
 */
@Override
default Option<T> reduceLeftOption(BiFunction<? super T, ? super T, ? extends T> op) {
  Objects.requireNonNull(op, "op is null");
  return isEmpty() ? Option.none() : Option.some(reduceLeft(op));
}

代码示例来源:origin: vavr-io/vavr

/**
 * Shortcut for {@code isEmpty() ? Option.none() : Option.some(reduceRight(op))}.
 *
 * @param op An operation of type T
 * @return a reduced value
 * @throws NullPointerException if {@code op} is null
 */
@Override
default Option<T> reduceRightOption(BiFunction<? super T, ? super T, ? extends T> op) {
  Objects.requireNonNull(op, "op is null");
  return isEmpty() ? Option.none() : Option.some(reduceRight(op));
}

代码示例来源:origin: vavr-io/vavr

@SuppressWarnings("unchecked")
@Override
public Option<M> initOption() {
  return isEmpty() ? Option.none() : Option.some(init());
}

代码示例来源:origin: vavr-io/vavr

@Override
public boolean hasNext() {
  while (next.isEmpty() && that.hasNext()) {
    final T candidate = that.next();
    if (predicate.test(candidate)) {
      next = Option.some(candidate);
    }
  }
  return next.isDefined();
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns the head element without modifying the List.
 *
 * @return {@code None} if this List is empty, otherwise a {@code Some} containing the head element
 */
default Option<T> peekOption() {
  return isEmpty() ? Option.none() : Option.some(head());
}

代码示例来源:origin: vavr-io/vavr

@Override
public Option<HashSet<T>> tailOption() {
  if (tree.isEmpty()) {
    return Option.none();
  } else {
    return Option.some(tail());
  }
}

代码示例来源:origin: vavr-io/vavr

/**
 * Removes an element from this Queue.
 *
 * @return {@code None} if this Queue is empty, otherwise {@code Some} {@code Tuple} containing the first element and the remaining elements of this Queue
 */
public Option<Tuple2<T, Q>> dequeueOption() {
  return isEmpty() ? Option.none() : Option.some(dequeue());
}

代码示例来源:origin: vavr-io/vavr

/**
 * Dual of {@linkplain #headOption()}, returning the last element as {@code Option}.
 *
 * @return {@code Some(element)} or {@code None} if this is empty.
 */
default Option<T> lastOption() {
  return isEmpty() ? Option.none() : Option.some(last());
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns the minimum element of this tree according to the underlying comparator.
 *
 * @return Some element, if this is not empty, otherwise None
 */
default Option<T> min() {
  return isEmpty() ? Option.none() : Option.some(Node.minimum((Node<T>) this));
}

代码示例来源:origin: vavr-io/vavr

/**
 * Removes the head element from this List.
 *
 * @return {@code None} if this List is empty, otherwise a {@code Some} containing the elements of this List without the head element
 */
default Option<List<T>> popOption() {
  return isEmpty() ? Option.none() : Option.some(pop());
}

代码示例来源:origin: vavr-io/vavr

/**
 * Converts this to an {@link Option}.
 *
 * @return A new {@link Option}.
 */
default Option<T> toOption() {
  if (this instanceof Option) {
    return (Option<T>) this;
  } else {
    return isEmpty() ? Option.none() : Option.some(get());
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
default Option<Iterator<T>> tailOption() {
  if (hasNext()) {
    next();
    return Option.some(this);
  } else {
    return Option.none();
  }
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns the first element of a non-empty Traversable as {@code Option}.
 *
 * @return {@code Some(element)} or {@code None} if this is empty.
 */
default Option<T> headOption() {
  return isEmpty() ? Option.none() : Option.some(head());
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns the first element without modifying the Queue.
 *
 * @return {@code None} if this Queue is empty, otherwise a {@code Some} containing the first element
 */
public Option<T> peekOption() {
  return isEmpty() ? Option.none() : Option.some(peek());
}

代码示例来源:origin: vavr-io/vavr

/**
 * Removes the head element from this List.
 *
 * @return {@code None} if this List is empty, otherwise {@code Some} {@code Tuple} containing the head element and the remaining elements of this List
 */
default Option<Tuple2<T, List<T>>> pop2Option() {
  return isEmpty() ? Option.none() : Option.some(Tuple.of(head(), pop()));
}

相关文章