gpt4 book ai didi

haskell - 在 attoparsec 中实现skipWhile1

转载 作者:行者123 更新时间:2023-12-02 21:29:36 25 4
gpt4 key购买 nike

Attoparsec提供了至少消耗一个字符的函数 takeWhile1

但是,skipWhile 没有类似的东西。如何实现这个函数skipWhile1

注意:这个问题故意表现出没有研究工作,因为它是以问答方式回答的。

最佳答案

另一种可能的实现:

import Control.Applicative

skipWhile1 p = skip p *> skipWhile p

这实际上可能比 @Uli 的答案更快,因为 takeWhile 构建结果字符串,而 skipWhile 则不会。懒惰可能会使它们等效(即,如果您不使用 takeWhile ,则可能实际上不会构建字符串);我目前无法进行测试来验证这一点。

关于haskell - 在 attoparsec 中实现skipWhile1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22613161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com