scala.util.Either.isLeft()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(249)

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

Either.isLeft介绍

暂无

代码示例

代码示例来源:origin: com.typesafe.play/play_2.11

static <A, B> Accumulator<ByteString, F.Either<Result, A>> delegate(play.api.mvc.BodyParser<B> delegate, Function<B, A> transform, Http.RequestHeader request) {
    Accumulator<ByteString, scala.util.Either<play.api.mvc.Result, B>> javaAccumulator = delegate.apply(request.asScala()).asJava();
      
    return javaAccumulator.map(result -> {
        if (result.isLeft()) {
          return F.Either.Left(result.left().get().asJava());
        } else {
          return F.Either.Right(transform.apply(result.right().get()));
        }
      },
      JavaParsers.trampoline());
  }
}

代码示例来源:origin: com.typesafe.play/play_2.12

static <A, B> Accumulator<ByteString, F.Either<Result, A>> delegate(play.api.mvc.BodyParser<B> delegate, Function<B, A> transform, Http.RequestHeader request) {
    Accumulator<ByteString, scala.util.Either<play.api.mvc.Result, B>> javaAccumulator = delegate.apply(request.asScala()).asJava();
      
    return javaAccumulator.map(result -> {
        if (result.isLeft()) {
          return F.Either.Left(result.left().get().asJava());
        } else {
          return F.Either.Right(transform.apply(result.right().get()));
        }
      },
      JavaParsers.trampoline());
  }
}

代码示例来源:origin: com.typesafe.play/play

static <A, B> Accumulator<ByteString, F.Either<Result, A>> delegate(play.api.mvc.BodyParser<B> delegate, Function<B, A> transform, Http.RequestHeader request) {
    Accumulator<ByteString, scala.util.Either<play.api.mvc.Result, B>> javaAccumulator = delegate.apply(request.asScala()).asJava();
      
    return javaAccumulator.map(result -> {
        if (result.isLeft()) {
          return F.Either.Left(result.left().get().asJava());
        } else {
          return F.Either.Right(transform.apply(result.right().get()));
        }
      },
      JavaParsers.trampoline());
  }
}

代码示例来源:origin: com.yahoo.maha/maha-par-request-2

/**
 * Casts the leftEither from <E,A> to <E,B>, meaning it is of type E already and not A or B
 */
public static <E, A, B> Either<E, B> castLeft(Either<E, A> leftEither) {
  Preconditions.checkArgument(leftEither.isLeft());
  return (Either<E, B>) leftEither;
}

代码示例来源:origin: com.typesafe.play/play

/**
 * Delegates underlying functionality to another body parser and converts the
 * result to Java API.
 */
@Override
public play.libs.streams.Accumulator<ByteString, F.Either<Result, Http.MultipartFormData<A>>> apply(Http.RequestHeader request) {
  return delegate.apply(request.asScala())
      .asJava()
      .map(result -> {
            if (result.isLeft()) {
              return F.Either.Left(result.left().get().asJava());
            } else {
              final play.api.mvc.MultipartFormData<A> scalaData = result.right().get();
              return F.Either.Right(new DelegatingMultipartFormData(scalaData));
            }
          },
          JavaParsers.trampoline()
      );
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * Delegates underlying functionality to another body parser and converts the
 * result to Java API.
 */
@Override
public play.libs.streams.Accumulator<ByteString, F.Either<Result, Http.MultipartFormData<A>>> apply(Http.RequestHeader request) {
  return delegate.apply(request.asScala())
      .asJava()
      .map(result -> {
            if (result.isLeft()) {
              return F.Either.Left(result.left().get().asJava());
            } else {
              final play.api.mvc.MultipartFormData<A> scalaData = result.right().get();
              return F.Either.Right(new DelegatingMultipartFormData(scalaData));
            }
          },
          JavaParsers.trampoline()
      );
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * Delegates underlying functionality to another body parser and converts the
 * result to Java API.
 */
@Override
public play.libs.streams.Accumulator<ByteString, F.Either<Result, Http.MultipartFormData<A>>> apply(Http.RequestHeader request) {
  return delegate.apply(request.asScala())
      .asJava()
      .map(result -> {
            if (result.isLeft()) {
              return F.Either.Left(result.left().get().asJava());
            } else {
              final play.api.mvc.MultipartFormData<A> scalaData = result.right().get();
              return F.Either.Right(new DelegatingMultipartFormData(scalaData));
            }
          },
          JavaParsers.trampoline()
      );
}

代码示例来源:origin: com.yahoo.maha/maha-par-request-2

/**
 * Converts Either<E,A> to T by applying the right function or left function depending on if it isRight or isLeft
 */
public static <T, E, A> T fold(Function<E, T> doWithLeft, Function<A, T> doWithRight, Either<E,A> either) {
  if (either.isLeft()) {
    return doWithLeft.apply(either.left().get());
  } else {
    return doWithRight.apply(either.right().get());
  }
}

代码示例来源:origin: com.yahoo.maha/maha-par-request-2

public static Either<GeneralError, DateTime> parseDateTimeWithZone(String input, DateTimeZone zone,
                                  DateTimeFormatter[] dateTimeFormatter) {
  Either<GeneralError, DateTime> parsedResult = parseDateTime(input, dateTimeFormatter);
  if (parsedResult.isLeft()) {
    return EitherUtils.castLeft(parsedResult);
  } else {
    return new Right<>(new DateTime(parsedResult.right().get().getMillis(), zone));
  }
}

代码示例来源:origin: kframework/k

static Either<Set<ParseFailedException>,Term> visitPolyChildren(TermCons tc, Function<Term, Either<Set<ParseFailedException>, Term>> apply) {
  Set<ParseFailedException> errors = new HashSet<>();
  for (int i : getPolyChildren(tc)) {
    Either<Set<ParseFailedException>, Term> res = apply.apply(tc.get(i - 1));
    if (res.isLeft()) {
      errors.addAll(res.left().get());
    }
  }
  if (errors.isEmpty())
    return Right.apply(tc);
  else
    return Left.apply(errors);
}

代码示例来源:origin: srikalyc/Sql4D

public List<String> getMetrics(String name, Map<String, String> reqHeaders) {
  Either<String,Tuple2<List<String>,List<String>>> aboutDataSource = aboutDataSource(name, reqHeaders);
  if (aboutDataSource.isLeft()) {
    return Lists.newArrayList();
  } 
  return aboutDataSource.right().get()._2();
}
/**

代码示例来源:origin: com.yahoo.sql4d/Sql4Ddriver

public List<String> getDimensions(String name, Map<String, String> reqHeaders) {
  Either<String,Tuple2<List<String>,List<String>>> aboutDataSource = aboutDataSource(name, reqHeaders);
  if (aboutDataSource.isLeft()) {
    return Lists.newArrayList();
  } 
  return aboutDataSource.right().get()._1();
}

代码示例来源:origin: com.yahoo.sql4d/Sql4Ddriver

public List<String> getMetrics(String name, Map<String, String> reqHeaders) {
  Either<String,Tuple2<List<String>,List<String>>> aboutDataSource = aboutDataSource(name, reqHeaders);
  if (aboutDataSource.isLeft()) {
    return Lists.newArrayList();
  } 
  return aboutDataSource.right().get()._2();
}
/**

代码示例来源:origin: srikalyc/Sql4D

public List<String> getDimensions(String name, Map<String, String> reqHeaders) {
  Either<String,Tuple2<List<String>,List<String>>> aboutDataSource = aboutDataSource(name, reqHeaders);
  if (aboutDataSource.isLeft()) {
    return Lists.newArrayList();
  } 
  return aboutDataSource.right().get()._1();
}

代码示例来源:origin: com.yahoo.maha/maha-par-request-2

/**
 * Converts Either<E,A> to T by applying the right function or left function depending on if it isRight or isLeft
 */
public static <T, E, A> T fold(Function1<E, T> doWithLeft, Function<A, T> doWithRight, Either<E,A> either) {
  if (either.isLeft()) {
    return doWithLeft.apply(either.left().get());
  } else {
    return doWithRight.apply(either.right().get());
  }
}

代码示例来源:origin: kframework/k

static Tuple2<Either<Set<ParseFailedException>, Term>, Set<VarInfo>> visitPolyChildrenSets(TermCons tc, Function<Term, Tuple2<Either<Set<ParseFailedException>, Term>, Set<VarInfo>>> apply) {
  Set<ParseFailedException> errors = new HashSet<>();
  Set<VarInfo> info = new HashSet<>();
  for (int i : getPolyChildren(tc)) {
    Tuple2<Either<Set<ParseFailedException>, Term>, Set<VarInfo>> res = apply.apply(tc.get(i - 1));
    info.addAll(res._2());
    if (res._1().isLeft())
      errors.addAll(res._1().left().get());
  }
  if (errors.isEmpty())
    return Tuple2.apply(Right.apply(tc), info);
  else
    return Tuple2.apply(Left.apply(errors), info);
}

代码示例来源:origin: kframework/k

/**
 * Parses a string with a particular start symbol/sort.
 *
 * @param startSymbol the start symbol/sort
 * @param toParse     the String to parse
 * @param fromSource  the Source of the String toParse
 * @return a pair: the left projection is a parsed string as a K, if successful;
 * the right projection is the set of issues encountered while parsing
 */
@SuppressWarnings("unchecked")
public Tuple2<Option<K>, Set<Warning>> apply(Sort startSymbol, String toParse, Source fromSource) {
  Tuple2<Either<Set<ParseFailedException>, K>, Set<ParseFailedException>> res = parseInModule.parseString(toParse, startSymbol, fromSource);
  Set<Warning> problemSet = new HashSet<>();
  problemSet.addAll((Set<Warning>) (Object) res._2());
  if (res._1().isLeft())
    problemSet.addAll((Set<Warning>) (Object) res._1().left().get());
  return Tuple2.apply(res._1().right().toOption(), problemSet);
}

代码示例来源:origin: kframework/k

@Override
public Either<java.util.Set<ParseFailedException>, Term> apply(TermCons tc) {
  assert tc.production() != null : this.getClass() + ":" + " production not found." + tc;
  if (!tc.production().isSyntacticSubsort()
      && tc.production().klabel().isDefined()
      && (tc.production().klabel().get().name().equals("#SyntacticCast")
        || tc.production().klabel().get().name().startsWith("#SemanticCastTo"))) {
    // match only on the outermost elements
      Either<java.util.Set<ParseFailedException>, Term> rez =
          new PriorityVisitor2(tc).apply(tc.get(0));
      if (rez.isLeft())
        return rez;
      tc = tc.with(0, rez.right().get());
  }
  return super.apply(tc);
}

代码示例来源:origin: kframework/k

public Tuple2<Either<Set<ParseFailedException>, K>, Set<ParseFailedException>>
  parseString(String input, Sort startSymbol, Scanner scanner, Source source, int startLine, int startColumn, boolean inferSortChecks) {
  final Tuple2<Either<Set<ParseFailedException>, Term>, Set<ParseFailedException>> result
      = parseStringTerm(input, startSymbol, scanner, source, startLine, startColumn, inferSortChecks);
  Either<Set<ParseFailedException>, K> parseInfo;
  if (result._1().isLeft()) {
    parseInfo = Left.apply(result._1().left().get());
  } else {
    parseInfo = Right.apply(new TreeNodesToKORE(Outer::parseSort, inferSortChecks && strict).apply(result._1().right().get()));
  }
  return new Tuple2<>(parseInfo, result._2());
}

代码示例来源:origin: kframework/k

private void parseTerm(String term, String sort, K expected, int expectWarnings) {
  String source = "AddEmpytListsTest." + testName.getMethodName();
  final Tuple2<Either<Set<ParseFailedException>, K>, Set<ParseFailedException>> parseResult
      = parser.parseString(term, Sort(sort), new Source(source));
  if (parseResult._1().isLeft()) {
    Assert.assertTrue("Unexpected parse errors" + parseResult._1().left().get(), false);
  }
  K actual = new TreeNodesToKORE(Outer::parseSort, false).down(parseResult._1().right().get());
  Assert.assertEquals(expected, actual);
  if (parseResult._2().size() != expectWarnings) {
    Assert.assertTrue("Unexpected parse warnings" + parseResult._2(), false);
  }
}

相关文章

微信公众号

最新文章

更多