Skip to content

Commit 860839e

Browse files
committed
traverse => traverse_ to avoid building list of units!
1 parent d8f8a48 commit 860839e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

parsley/shared/src/main/scala/parsley/combinator.scala

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ object combinator {
185185
def traverse[A, B](f: A => Parsley[B], xs: A*): Parsley[List[B]] = sequence(xs.map(f): _*)
186186
// this will be used in future!
187187
private [parsley] def traverse5[A, B](xs: A*)(f: A => Parsley[B]): Parsley[List[B]] = traverse(f, xs: _*)
188+
private [parsley] def traverse_[A](xs: A*)(f: A => Parsley[_]): Parsley[Unit] = skip(unit, xs.map(f): _*)
188189

189190
/** This combinator will parse each of `ps` in order, discarding the results.
190191
*

parsley/shared/src/main/scala/parsley/errors/tokenextractors/LexToken.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import parsley.Success
1010
import parsley.XAssert.assert
1111
import parsley.XCompat.unused
1212
import parsley.character.{item, stringOfSome}
13-
import parsley.combinator.{option, traverse5}
13+
import parsley.combinator.{option, traverse5, traverse_}
1414
import parsley.errors.{ErrorBuilder, Token, TokenSpan}
1515
import parsley.position
1616

@@ -58,7 +58,7 @@ trait LexToken { this: ErrorBuilder[_] =>
5858
private lazy val makeParser: Parsley[Either[::[(String, (Int, Int))], String]] = {
5959
val toks = traverse5(tokens: _*)(p => option(lookAhead(attempt(p) <~> position.pos))).map(_.flatten).collect { case toks@(_::_) => toks }
6060
// this can only fail if either there is no input (which there must be), or there is a token at the front, in which case `rawTok` is not parsed anyway
61-
val rawTok = stringOfSome(traverse5(tokens: _*)(notFollowedBy) *> item)
61+
val rawTok = stringOfSome(traverse_(tokens: _*)(notFollowedBy) *> item)
6262
toks <+> rawTok
6363
}
6464

0 commit comments

Comments
 (0)