在attoparsec中实现skipWhile1 [英] Implementing skipWhile1 in attoparsec
问题描述
Attoparsec 提供的功能 takeWhile1
至少会消耗一个字符。
Attoparsec provides the function takeWhile1
that consumes at least one character.
然而,对于 skipWhile
没有类比。我怎样才能实现这个功能 skipWhile1
?
However, there is no analog for skipWhile
. How can I implement this function skipWhile1
?
注意:这个问题故意显示no研究工作,因为它被回答为Q& A-Style。
Note: This question intentionally shows no research effort as it was answered Q&A-Style.
推荐答案
另一个可能的实现:
Another possible implementation:
import Control.Applicative
skipWhile1 p = skip p *> skipWhile p
这实际上可能比@ Uli的答案快,因为 takeWhile
生成一个结果字符串,而 skipWhile
不会。懒惰可能会使它们等价(也就是说,如果不使用它,也许 takeWhile
实际上不会构建字符串);我目前无法验证这一点。
This might actually be faster than @Uli's answer because takeWhile
builds a result string, whereas skipWhile
doesn't. Laziness might make them equivalent (ie. maybe takeWhile
doesn't actually build the string if you don't use it); I can't test at the moment to verify this.
这篇关于在attoparsec中实现skipWhile1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!