本文整理了Java中io.vavr.control.Option.none()
方法的一些代码示例,展示了Option.none()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.none()
方法的具体详情如下:
包路径:io.vavr.control.Option
类名称:Option
方法名:none
[英]Returns the single instance of None
[中]返回None的单个实例
代码示例来源:origin: vavr-io/vavr
@Override
public T getNext() {
final T result = next.get();
next = Option.none();
return result;
}
};
代码示例来源: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
/**
* Returns {@code Some(value)} if this is a {@code Some} and the value satisfies the given predicate.
* Otherwise {@code None} is returned.
*
* @param predicate A predicate which is used to test an optional value
* @return {@code Some(value)} or {@code None} as specified
*/
default Option<T> filter(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return isEmpty() || predicate.test(get()) ? this : none();
}
代码示例来源:origin: vavr-io/vavr
/**
* Maps the value to a new {@code Option} if this is a {@code Some}, otherwise returns {@code None}.
*
* @param mapper A mapper
* @param <U> Component type of the resulting Option
* @return a new {@code Option}
*/
@SuppressWarnings("unchecked")
default <U> Option<U> flatMap(Function<? super T, ? extends Option<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
return isEmpty() ? none() : (Option<U>) mapper.apply(get());
}
代码示例来源: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
/**
* 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
/**
* 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 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
@SuppressWarnings("unchecked")
@Override
Option<V> lookup(int shift, int keyHash, K key) {
final int frag = hashFragment(shift, keyHash);
final int bit = toBitmap(frag);
if ((bitmap & bit) != 0) {
final AbstractNode<K, V> n = (AbstractNode<K, V>) subNodes[fromBitmap(bitmap, bit)];
return n.lookup(shift + SIZE, keyHash, key);
} else {
return Option.none();
}
}
内容来源于网络,如有侵权,请联系作者删除!