Skip to content

Commit

Permalink
FormatTokens: use Either.merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jul 30, 2023
1 parent 0656948 commit 4743d76
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,23 @@ class FormatTokens(leftTok2tok: Map[TokenOps.TokenHash, Int])(
final def findToken(
ft: FormatToken,
iter: FormatToken => FormatToken
)(f: FormatToken => Boolean): Either[FormatToken, FormatToken] =
findTokenWith(ft, iter)(Some(_).filter(f))
)(f: FormatToken => Boolean): FormatToken =
findTokenWith(ft, iter)(Some(_).filter(f)).merge

final def nextNonCommentSameLine(curr: FormatToken): FormatToken =
findToken(curr, next)(ft => ft.hasBreak || !ft.right.is[Token.Comment])
.fold(identity, identity)

final def nextNonComment(curr: FormatToken): FormatToken =
findToken(curr, next)(!_.right.is[Token.Comment]).fold(identity, identity)
findToken(curr, next)(!_.right.is[Token.Comment])

final def nextNonComment(curr: FormatToken.Meta): FormatToken =
nextNonComment(arr(curr.idx))

final def prevNonCommentSameLine(curr: FormatToken): FormatToken =
findToken(curr, prev)(ft => ft.hasBreak || !ft.left.is[Token.Comment])
.fold(identity, identity)

final def prevNonComment(curr: FormatToken): FormatToken =
findToken(curr, prev)(!_.left.is[Token.Comment]).fold(identity, identity)
findToken(curr, prev)(!_.left.is[Token.Comment])

@inline
final def prevNonCommentBefore(curr: FormatToken): FormatToken =
Expand Down

0 comments on commit 4743d76

Please sign in to comment.