本文整理了Java中fj.data.Option.bind()
方法的一些代码示例,展示了Option.bind()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.bind()
方法的具体详情如下:
包路径:fj.data.Option
类名称:Option
方法名:bind
[英]First-class bind function.
[中]第一类绑定函数。
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Joins the given optional value of optional value using a bind operation.
*
* @param o The optional value of optional value to join.
* @return A new optional value that is the join of the given optional value.
*/
public static <A> Option<A> join(final Option<Option<A>> o) {
final F<Option<A>, Option<A>> id = identity();
return o.bind(id);
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Performs function application within an optional value (applicative functor pattern).
*
* @param of The optional value of functions to apply.
* @return A new optional value after applying the given optional value of functions through this
* optional value.
*/
public final <B> Option<B> apply(final Option<F<A, B>> of) {
return of.bind(f -> map(f));
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* First-class bind function.
*
* @return A function that binds a given function across an option with a final join.
*/
public static <A, B> F<F<A, Option<B>>, F<Option<A>, Option<B>>> bind() {
return curry((f, a) -> a.bind(f));
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Performs a bind across the optional value, but ignores the element value in the function.
*
* @param o The optional value to apply in the final join.
* @return A new optional value after the final join.
*/
public final <B> Option<B> sequence(final Option<B> o) {
final F<A, Option<B>> c = constant(o);
return bind(c);
}
代码示例来源:origin: org.functionaljava/functionaljava
@Override
public Option<C> getOption(final S s) {
return PPrism.this.getOption(s).bind(other::getOption);
}
};
代码示例来源:origin: org.functionaljava/functionaljava
public final <B,C,D,E,F$,G,H> Option<P8<A,B,C,D,E,F$,G,H>> bindProduct(final Option<B> ob, final Option<C> oc,
final Option<D> od, final Option<E> oe,
final Option<F$> of, final Option<G> og,
final Option<H> oh) {
return bind(ob, oc, od, oe, of, og, oh, P.p8());
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Promotes a function of arity-2 so that it operates over options.
*
* @param f A function to promote.
* @return The given function promoted to operate on options.
*/
public static <A, B, C> F<Option<A>, F<Option<B>, Option<C>>> liftM2(final F<A, F<B, C>> f) {
return curry((a, b) -> a.bind(b, f));
}
代码示例来源:origin: org.functionaljava/functionaljava
public final <B, C, D> Option<P4<A,B,C,D>> bindProduct(final Option<B> ob, final Option<C> oc, final Option<D> od) {
return bind(ob, oc, od, P.p4());
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Binds the given function across the element of this optional value and the given optional value
* with a final join.
*
* @param ob A given optional value to bind the given function with.
* @param oc A given optional value to bind the given function with.
* @param f The function to apply to the element of this optional value and the given optional
* value.
* @return A new optional value after performing the map, then final join.
*/
public final <B, C, D> Option<D> bind(final Option<B> ob, final Option<C> oc, final F<A, F<B, F<C, D>>> f) {
return oc.apply(bind(ob, f));
}
代码示例来源:origin: org.functionaljava/functionaljava
public final <B,C,D,E> Option<P5<A,B,C,D,E>> bindProduct(final Option<B> ob, final Option<C> oc, final Option<D> od,
final Option<E> oe) {
return bind(ob, oc, od, oe, P.p5());
}
代码示例来源:origin: org.functionaljava/functionaljava
public final <B,C,D,E,F$> Option<P6<A,B,C,D,E,F$>> bindProduct(final Option<B> ob, final Option<C> oc, final Option<D> od,
final Option<E> oe, final Option<F$> of) {
return bind(ob, oc, od, oe, of, P.p6());
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Lift the function of arity-2 through options.
*
* @param f A function to lift.
* @return An optional result.
*/
public final <B, C> Option<C> liftM2(final Option<B> ob, final F2<A, B, C> f) {
return bind(a -> ob.map(b -> f.f(a, b)));
}
代码示例来源:origin: no.arktekk.unix/unix-sysv-pkg
public void addSymlink( UnixFsObject.Symlink symlink )
{
fileSystem = fileSystem.addSymlink( new SymlinkEntry( symlink.attributes.bind( findClassTag ), symlink ) );
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns an optional non-empty string, or no value if the given string is empty.
*
* @param s A string to turn into an optional non-empty string.
* @return an optional non-empty string, or no value if the given string is empty.
*/
public static Option<String> fromString(final String s) {
return fromNull(s).bind(s1 -> {
final Option<String> none = none();
return s.length() == 0 ? none : some(s);
});
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns a potential value that the given key maps to.
*
* @param k The key to look up in the tree map.
* @return A potential value for the given key.
*/
public Option<V> get(final K k) {
return tree.lookup(p(k, Option.none())).bind(P2::_2);
}
代码示例来源:origin: org.functionaljava/functionaljava
public ListIterator<A> listIterator(final int index) {
return toListIterator(toZipper().bind(Zipper.<A>move().f(index)));
}
代码示例来源:origin: org.codehaus.mojo.unix/unix-pkg
public void addFile( FileObject fromFile, UnixFsObject.RegularFile file )
{
fileSystem = fileSystem.addFile( new FileEntry( file.attributes.bind( findClassTag ), some( false ), file, some( asFile( fromFile ) ) ) );
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Traversable instance of Stream for Option.
*
* @return traversed value
*/
public final <B> Option<Stream<B>> traverseOption(F<A, Option<B>> f) {
return this.foldRight1((a, acc) -> acc.bind(bs -> f.f(a).map(bs::cons)), some(Stream.nil()));
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Traverses through the List with the given function
*
* @param f The function that produces Option value
* @return none if applying f returns none to any element of the list or f mapped list in some .
*/
public final <B> Option<List<B>> traverseOption(final F<A, Option<B>> f) {
return foldRight(
(a, obs) -> f.f(a).bind(o -> obs.map(os -> os.cons(o))),
some(List.nil())
);
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Sequence through the option monad.
*
* @param a The list of option to sequence.
* @return The option of list after sequencing.
*/
public static <A> Option<List<A>> sequence(final List<Option<A>> a) {
return a.isEmpty() ?
some(List.nil()) :
a.head().bind(aa -> sequence(a.tail()).map(cons_(aa)));
}
内容来源于网络,如有侵权,请联系作者删除!