本文整理了Java中com.fpinjava.common.Function
类的一些代码示例,展示了Function
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Function
类的具体详情如下:
包路径:com.fpinjava.common.Function
类名称:Function
暂无
代码示例来源:origin: fpinjava/fpinjava
@Override
public <U> Result<U> flatMap(Function<V, Result<U>> f) {
return f.apply(value);
}
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <B> B foldLeft(B identity, Function<B, Function<A, B>> f, Function<B, Function<B, B>> g) {
// Post order right:
return g.apply(right.foldLeft(identity, f, g)).apply(f.apply(left.foldLeft(identity, f, g)).apply(this.value));
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <B> B foldRight(B identity, Function<A, Function<B, B>> f, Function<B, Function<B, B>> g) {
// Pre order left
return g.apply(f.apply(this.value).apply(left.foldRight(identity, f, g))).apply(right.foldRight(identity, f, g));
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <B> B foldLeft(B identity, Function<B, Function<A, B>> f, Function<B, Function<B, B>> g) {
// Post order right:
return g.apply(right.foldLeft(identity, f, g)).apply(f.apply(left.foldLeft(identity, f, g)).apply(this.value));
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <B> B foldLeft(B identity, Function<B, Function<A, B>> f, Function<B, Function<B, B>> g) {
// Post order right:
return g.apply(right.foldLeft(identity, f, g)).apply(f.apply(left.foldLeft(identity, f, g)).apply(this.value));
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <B> B foldLeft(B identity, Function<B, Function<A, B>> f, Function<B, Function<B, B>> g) {
// Post order right:
return g.apply(right.foldLeft(identity, f, g)).apply(f.apply(left.foldLeft(identity, f, g)).apply(this.value));
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <B> B foldRight(B identity, Function<A, Function<B, B>> f, Function<B, Function<B, B>> g) {
// Pre order left
return g.apply(f.apply(this.value).apply(left.foldRight(identity, f, g))).apply(right.foldRight(identity, f, g));
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <B> B foldLeft(B identity, Function<B, Function<A, B>> f, Function<B, Function<B, B>> g) {
// Post order right:
return g.apply(right.foldLeft(identity, f, g)).apply(f.apply(left.foldLeft(identity, f, g)).apply(this.value));
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <B> B foldLeft(B identity, Function<B, Function<A, B>> f, Function<B, Function<B, B>> g) {
// Post order right:
return g.apply(right.foldLeft(identity, f, g)).apply(f.apply(left.foldLeft(identity, f, g)).apply(this.value));
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <B> B foldRight(B identity, Function<A, Function<B, B>> f, Function<B, Function<B, B>> g) {
// Pre order left
return g.apply(f.apply(this.value).apply(left.foldRight(identity, f, g))).apply(right.foldRight(identity, f, g));
}
代码示例来源:origin: fpinjava/fpinjava
public static <A, B, C, D> Option<D> map3(Option<A> a,
Option<B> b,
Option<C> c,
Function<A, Function<B, Function<C, D>>> f) {
return a.flatMap(ax -> b.flatMap(bx -> c.map(cx -> f.apply(ax).apply(bx).apply(cx))));
}
代码示例来源:origin: fpinjava/fpinjava
public static <T, U> U foldRight(List<T> ts, U identity,
Function<T, Function<U, U>> f) {
return ts.isEmpty()
? identity
: f.apply(head(ts)).apply(foldRight(tail(ts), identity, f));
}
}
代码示例来源:origin: fpinjava/fpinjava
public static <A, B, C> Rand<C> map2_(Rand<A> ra, Rand<B> rb, Function<A, Function<B, C>> f) {
return rng -> {
Tuple<A, RNG> t1 = ra.apply(rng);
Tuple<B, RNG> t2 = rb.apply(t1._2);
return new Tuple<>(f.apply(t1._1).apply(t2._1), t2._2);
};
}
代码示例来源:origin: fpinjava/fpinjava
@Override
public <U> Result<U> flatMap(Function<T, Result<U>> f) {
try {
return f.apply(successValue());
} catch (Exception e) {
return failure(e.getMessage());
}
}
代码示例来源:origin: fpinjava/fpinjava
static <A, B> Random<B> map(Random<A> s, Function<A, B> f) {
return rng -> {
Tuple<A, RNG> t = s.apply(rng);
return new Tuple<>(f.apply(t._1), t._2);
};
}
代码示例来源:origin: fpinjava/fpinjava
public Result<T> filter(Function<T, Boolean> p, String message) {
return flatMap(x -> p.apply(x)
? this
: failure(message));
}
代码示例来源:origin: fpinjava/fpinjava
public Result<T> filter(Function<T, Boolean> p) {
return flatMap(x -> p.apply(x)
? this
: failure("Condition not matched"));
}
代码示例来源:origin: fpinjava/fpinjava
public static <T> Result<T> of(Function<T, Boolean> predicate, T value) {
try {
return predicate.apply(value)
? success(value)
: empty();
} catch (Exception e) {
String errMessage =
String.format("Exception while evaluating predicate: %s", value);
return Result.failure(new IllegalStateException(errMessage, e));
}
}
代码示例来源:origin: fpinjava/fpinjava
public Result<T> filter(Function<T, Boolean> p, String message) {
return flatMap(x -> p.apply(x)
? this
: failure(message));
}
代码示例来源:origin: fpinjava/fpinjava
public Result<T> filter(Function<T, Boolean> p) {
return flatMap(x -> p.apply(x)
? this
: failure("Condition not matched"));
}
内容来源于网络,如有侵权,请联系作者删除!