com.fpinjava.common.Tuple类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(103)

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

Tuple介绍

暂无

代码示例

代码示例来源:origin: fpinjava/fpinjava

public static Tuple<Tuple<Integer, Double>, RNG> intDouble(RNG rng) {
 Tuple<Integer, RNG> t1 = rng.nextInt();
 Tuple<Double, RNG> t2 = doubleRnd(t1._2);
 return new Tuple<>(new Tuple<>(t1._1, t2._1), t2._2);
}

代码示例来源:origin: fpinjava/fpinjava

@Test
public void testSplitAt_() throws Exception {
 List<Integer> list = List.list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
 assertEquals("([1, 2, 3, 4, 5, NIL],[6, 7, 8, 9, 10, 11, 12, 13, 14, NIL])", list.splitAt_(5).toString());
 assertEquals("([NIL],[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, NIL])", list.splitAt_(0).toString());
 assertEquals("([NIL],[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, NIL])", list.splitAt_(-2).toString());
 assertEquals("([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, NIL],[14, NIL])", list.splitAt_(13).toString());
 assertEquals("([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, NIL],[NIL])", list.splitAt_(14).toString());
 assertEquals("([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, NIL],[NIL])", list.splitAt_(15).toString());
}

代码示例来源:origin: fpinjava/fpinjava

@Test
 public void testSplitAt() throws Exception {
  List<Integer> list = List.list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
  assertEquals("([1, 2, 3, 4, 5, NIL],[6, 7, 8, 9, 10, 11, 12, 13, 14, NIL])", list.splitAt(5).toString());
  assertEquals("([NIL],[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, NIL])", list.splitAt(0).toString());
  assertEquals("([NIL],[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, NIL])", list.splitAt(-2).toString());
  assertEquals("([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, NIL],[14, NIL])", list.splitAt(13).toString());
  assertEquals("([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, NIL],[NIL])", list.splitAt(14).toString());
  assertEquals("([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, NIL],[NIL])", list.splitAt(15).toString());
 }
}

代码示例来源:origin: fpinjava/fpinjava

public <B, C> List<C> zipWithAll(List<B> s2, Function<Tuple<Result<A>, Result<B>>, C> f) {
 Function<Tuple<List<A>, List<B>>, Result<Tuple<C, Tuple<List<A>, List<B>>>>> g = x -> x._1.isEmpty() && x._2.isEmpty()
   ? Result.empty()
   : x._2.isEmpty()
     ? Result.success(new Tuple<>(f.apply(new Tuple<>(Result.success(x._1.head()), Result.empty())), new Tuple<>(x._1.tail(), List.<B> list())))
     : x._1.isEmpty()
       ? Result.success(new Tuple<>(f.apply(new Tuple<>(Result.empty(), Result.success(x._2.head()))), new Tuple<>(List.<A> list(), x._2.tail())))
       : Result.success(new Tuple<>(f.apply(new Tuple<>(Result.success(x._1.head()), Result.success(x._2.head()))), new Tuple<>(x._1.tail(), x._2.tail())));
 return unfold(new Tuple<>(this, s2), g);
}

代码示例来源:origin: fpinjava/fpinjava

public Stream<A> takeViaUnfold(int n) {
 return unfold(new Tuple<>(this, n), x -> x._1.isEmpty()
   ? Result.empty()
   : x._2 > 0
     ? Result.success(new Tuple<>(x._1.head()._1, new Tuple<>(x._1.tail(), x._2 - 1)))
     : Result.empty());
}

代码示例来源:origin: fpinjava/fpinjava

public <B, C> List<C> zipWithAll(List<B> s2, Function<Tuple<Result<A>, Result<B>>, C> f) {
 Function<Tuple<List<A>, List<B>>, Result<Tuple<C, Tuple<List<A>, List<B>>>>> g = x -> x._1.isEmpty() && x._2.isEmpty()
   ? Result.empty()
   : x._2.isEmpty()
     ? Result.success(new Tuple<>(f.apply(new Tuple<>(Result.success(x._1.head()), Result.empty())), new Tuple<>(x._1.tail(), List.<B> list())))
     : x._1.isEmpty()
       ? Result.success(new Tuple<>(f.apply(new Tuple<>(Result.empty(), Result.success(x._2.head()))), new Tuple<>(List.<A> list(), x._2.tail())))
       : Result.success(new Tuple<>(f.apply(new Tuple<>(Result.success(x._1.head()), Result.success(x._2.head()))), new Tuple<>(x._1.tail(), x._2.tail())));
 return unfold(new Tuple<>(this, s2), g);
}

代码示例来源:origin: fpinjava/fpinjava

public <B, C> List<C> zipWithAll(List<B> s2, Function<Tuple<Result<A>, Result<B>>, C> f) {
 Function<Tuple<List<A>, List<B>>, Result<Tuple<C, Tuple<List<A>, List<B>>>>> g = x -> x._1.isEmpty() && x._2.isEmpty()
   ? Result.empty()
   : x._2.isEmpty()
     ? Result.success(new Tuple<>(f.apply(new Tuple<>(Result.success(x._1.head()), Result.empty())), new Tuple<>(x._1.tail(), List.<B> list())))
     : x._1.isEmpty()
       ? Result.success(new Tuple<>(f.apply(new Tuple<>(Result.empty(), Result.success(x._2.head()))), new Tuple<>(List.<A> list(), x._2.tail())))
       : Result.success(new Tuple<>(f.apply(new Tuple<>(Result.success(x._1.head()), Result.success(x._2.head()))), new Tuple<>(x._1.tail(), x._2.tail())));
 return unfold(new Tuple<>(this, s2), g);
}

代码示例来源:origin: fpinjava/fpinjava

public <B, C> List<C> zipWithAll(List<B> s2, Function<Tuple<Result<A>, Result<B>>, C> f) {
 Function<Tuple<List<A>, List<B>>, Result<Tuple<C, Tuple<List<A>, List<B>>>>> g = x -> x._1.isEmpty() && x._2.isEmpty()
   ? Result.empty()
   : x._2.isEmpty()
     ? Result.success(new Tuple<>(f.apply(new Tuple<>(Result.success(x._1.head()), Result.empty())), new Tuple<>(x._1.tail(), List.<B> list())))
     : x._1.isEmpty()
       ? Result.success(new Tuple<>(f.apply(new Tuple<>(Result.empty(), Result.success(x._2.head()))), new Tuple<>(List.<A> list(), x._2.tail())))
       : Result.success(new Tuple<>(f.apply(new Tuple<>(Result.success(x._1.head()), Result.success(x._2.head()))), new Tuple<>(x._1.tail(), x._2.tail())));
 return unfold(new Tuple<>(this, s2), g);
}

代码示例来源:origin: fpinjava/fpinjava

@Override
public Tuple<Result<A>, Stream<A>> headOption() {
 Tuple<A, Stream<A>> t = head();
 return new Tuple<>(Result.success(t._1), t._2);
}

代码示例来源:origin: fpinjava/fpinjava

public static Tuple<List<Integer>, RNG> integers(RNG rng, int length) {
 Tuple<List<Tuple<Integer, RNG>>, RNG> result = List.range(0, length).foldLeft(new Tuple<>(List.list(), rng), tuple -> i -> {
  Tuple<Integer, RNG> t = integer(tuple._2);
  return new Tuple<>(tuple._1.cons(t), t._2);
 });
 List<Integer> list = result._1.map(x -> x._1);
 return new Tuple<>(list, result._2);
}

代码示例来源: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<A> getAt(int index) {
 Tuple<Result<A>, Integer> identity = new Tuple<>(Result.failure("Index out of bound"), index);
 Tuple<Result<A>, Integer> rt = index < 0 || index >= length()
   ? identity
   : foldLeft(identity, ta -> a -> ta._2 < 0 ? ta : new Tuple<>(Result.success(a), ta._2 - 1));
 return rt._1;
}

代码示例来源: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<A> getAt(int index) {
 Tuple<Result<A>, Integer> identity = new Tuple<>(Result.failure("Index out of bound"), index);
 Tuple<Result<A>, Integer> rt = index < 0 || index >= length()
   ? identity
   : foldLeft(identity, ta -> a -> ta._2 < 0 ? ta : new Tuple<>(Result.success(a), ta._2 - 1));
 return rt._1;
}

代码示例来源:origin: fpinjava/fpinjava

public Result<A> getAt(int index) {
 Tuple<Result<A>, Integer> identity = new Tuple<>(Result.failure("Index out of bound"), index);
 Tuple<Result<A>, Integer> rt = index < 0 || index >= length()
   ? identity
   : foldLeft(identity, ta -> a -> ta._2 < 0 ? ta : new Tuple<>(Result.success(a), ta._2 - 1));
 return rt._1;
}

代码示例来源:origin: fpinjava/fpinjava

public Result<A> getAt_(int index) {
 Tuple<Result<A>, Integer> identity = new Tuple<>(Result.failure("Index out of bound"), index);
 Tuple<Result<A>, Integer> rt = index < 0 || index >= length()
   ? identity
   : foldLeft(identity, ta -> a -> ta._2 < 0 ? ta : new Tuple<>(Result.success(a), ta._2 - 1));
 return rt._1;
}

代码示例来源:origin: fpinjava/fpinjava

public Result<A> getAt(int index) {
 Tuple<Result<A>, Integer> identity = new Tuple<>(Result.failure("Index out of bound"), index);
 Tuple<Result<A>, Integer> rt = index < 0 || index >= length()
   ? identity
   : foldLeft(identity, ta -> a -> ta._2 < 0 ? ta : new Tuple<>(Result.success(a), ta._2 - 1));
 return rt._1;
}

代码示例来源:origin: fpinjava/fpinjava

public Result<A> getAt(int index) {
 Tuple<Result<A>, Integer> identity = new Tuple<>(Result.failure("Index out of bound"), index);
 Tuple<Result<A>, Integer> rt = index < 0 || index >= length()
   ? identity
   : foldLeft(identity, ta -> a -> ta._2 < 0 ? ta : new Tuple<>(Result.success(a), ta._2 - 1));
 return rt._1;
}

代码示例来源:origin: fpinjava/fpinjava

public Result<A> getAt(int index) {
 Tuple<Result<A>, Integer> identity = new Tuple<>(Result.failure("Index out of bound"), index);
 Tuple<Result<A>, Integer> rt = index < 0 || index >= length()
   ? identity
   : foldLeft(identity, ta -> a -> ta._2 < 0 ? ta : new Tuple<>(Result.success(a), ta._2 - 1));
 return rt._1;
}

代码示例来源:origin: fpinjava/fpinjava

public Result<A> getAt(int index) {
 Tuple<Result<A>, Integer> identity = new Tuple<>(Result.failure("Index out of bound"), index);
 Tuple<Result<A>, Integer> rt = index < 0 || index >= length()
   ? identity
   : foldLeft(identity, ta -> a -> ta._2 < 0 ? ta : new Tuple<>(Result.success(a), ta._2 - 1));
 return rt._1;
}

相关文章

微信公众号

最新文章

更多

Tuple类方法