fj.data.List.zip()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(91)

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

List.zip介绍

[英]The first-class version of the zip function.
[中]zip函数的一流版本。

代码示例

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Zips this non empty list with the given non empty list to produce a list of pairs. If this list and the given list
 * have different lengths, then the longer list is normalised so this function never fails.
 *
 * @param bs The non empty list to zip this non empty list with.
 * @return A new non empty list with a length the same as the shortest of this list and the given list.
 */
public <B> NonEmptyList<P2<A, B>> zip(final NonEmptyList<B> bs) {
 final List<P2<A, B>> list = toList().zip(bs.toList());
 return nel(list.head(), list.tail());
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-optimization

/**
 * Converts the variable-to-variable pairs into a list of equalities.
 */
private static List<Function> generateVariableEqualities(Set<Variable> equivalentVariables) {
  List<Variable> variableList = equivalentVariables.toList();
  List<P2<Variable, Variable>> variablePairs = variableList.zip(variableList.tail());
  return variablePairs
      .map((F<P2<Variable, Variable>, Function>) pair -> TERM_FACTORY.getFunctionEQ(pair._1(), pair._2()));
}

代码示例来源:origin: novarto-oss/sane-dbc

@Test
public void chainedTransaction()
{
  DB<List<String>> readInserted = insertKeysOp(asList("a", "b", "c")).bind(ids ->
  {
    List<P2<Integer, String>> data = ids.zip(list("Pesho", "Gosho", "Dragan"));
    return insertDataOp(data).bind(whatever -> SELECT_ALL_DATA_OP);
  });
  List<String> result = DB.transact(readInserted);
  assertThat(result, is(list("Pesho", "Gosho", "Dragan")));
}

代码示例来源:origin: novarto-oss/sane-dbc

@Test
public void rollback2()
{
  DB<Unit> failedInsert = insertKeysOp(list("ok"))
      .bind(ids -> insertDataOp(ids.zip(list("description"))).bind(insertCount ->
      {
        throw new RuntimeException("failed I have");
      }));
  swallow(() -> DB.transact(failedInsert));
  DB<P2<Long, Long>> tryCounts = COUNT_IDS.bind(idCount -> COUNT_DATA.map(dataCount -> p(idCount, dataCount)));
  P2<Long, Long> counts = DB.submit(tryCounts);
  assertEquals(0, (long) counts._1());
  assertEquals(0, (long) counts._2());
}

代码示例来源:origin: novarto-oss/sane-dbc

@Test
public void selectBy()
{
  DB<Unit> insertIt = insertKeysOp(list("a"))
      .bind(ids -> insertDataOp(ids.zip(list("my_description"))).map(ignore -> Unit.unit()));
  DB.submit(insertIt);
  List<String> descriptions = DB.submit(selectByDescOp("my_description"));
  assertEquals(list("my_description"), descriptions);
}

相关文章