Preserving string matching #45
Replies: 2 comments 2 replies
-
The more idiomatic way would be The reason it's not in the API is because it's not usually something you do very often, you can ask the same question for a lot of different operators. That being said, |
Beta Was this translation helpful? Give feedback.
-
Of course, there is nothing to stop you defining it yourself! Defining an implicit class somewhere in your project will allow you to use the operator (it's the exact same mechanism which Parsley uses to make all the other operators... See import parsley.Parsley
import parsley.lift.lift2
object ParsleyExtensions {
implicit final class StringAppend[P](p: =>P)(implicit con: P => Parsley[String]) {
def <++>(q: =>Parsley[String]): Parsley[String] = lift2[String, String, String](_ ++ _, p, q)
}
} |
Beta Was this translation helpful? Give feedback.
-
The <::> and <~> operators are quite useful, in that regard, I've seen a very similar operator which is missing (or I can't seem to have found it). Is there any equivalent operator for string concatenation?
what I would like to write is
val ays: Parsley[String] = "a" <++> "ys" and mean "match 'a' and 'ys' and retain both strings in the result" I know string concatenation is expensive, yet it would be very handy to have something like this rather than write
val ays: Parsley[String] = "a" <**> ("ys" <#> concat) where concat = (ys: String) => (xs: String) => xs.concat(ys)
Is there any reason for this not being present in the API?
Beta Was this translation helpful? Give feedback.
All reactions