Skip to content

Commit

Permalink
minor improvement to cheapOneOf0 (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Mar 28, 2022
1 parent c7b99fa commit 7856e98
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/shared/src/main/scala/cats/parse/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,17 @@ object Parser {
items match {
case Nil => Fail()
case pa :: Nil => pa
case many => OneOf0(many)
case many =>
def to1(p: Parser0[A]): Option[Parser[A]] =
p match {
case p: Parser[A] => Some(p)
case _ => None
}

many.traverse(to1) match {
case Some(p1s) => OneOf(p1s)
case None => OneOf0(many)
}
}

def oneOfInternal[A](parsers: List[Parser[A]]): Parser[A] = {
Expand Down

0 comments on commit 7856e98

Please sign in to comment.