haskell - 是否有基于 ByteString 或 Text 的单子(monad)/应用映射(即 traverse/mapM)函数?

标签 haskell text dictionary traversal bytestring

ByteString 有标准(纯) map 函数和 Text :

map :: (Word8 -> Word8) -> ByteString -> ByteString
map :: (Char -> Char) -> Text -> Text

但我缺少他们的单子(monad)/应用对应物:

traverse :: (Applicative f) => (Word8 -> f Word8) -> ByteString -> f ByteString
traverse :: (Applicative f) => (Char -> f Char) -> Text -> f Text

(如果我们有 traverse,我们可以定义 mapM f = unwrapMonad . traverse (WrapMonad . f)。)

我尝试查看软件包,尝试使用 Hoogle,但没有找到它们。我是不是忽略了什么?或者是否有原因导致它们丢失(就像不可能/容易有效地定义它们)?

最佳答案

顺便说一句,Edward Kmett 的 lens 正是您所需要的。包裹;您想要的traverse版本很简单 Data.Bytestring.Lens.bytesData.Text.Lens.text .

编辑:澄清一下,上述函数属于 SimpleTraversal c e 类型(的概括) (分别用于 (c ~ Bytestring, e ~ Word8)(c ~ Text, e ~ Char) ),它是 forall f. (Applicative f) => (e -> f e) -> c -> f c 的类型同义词。

关于haskell - 是否有基于 ByteString 或 Text 的单子(monad)/应用映射(即 traverse/mapM)函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12953871/

相关文章:

python - 仅写入文件中某行的某些列(以空格分隔)

haskell - 如何使用 ghci 加载没有 .hs 扩展名的 runhaskell 脚本?

haskell - fix 函数是替代 while 循环的更好方法吗?

haskell - 使用列表理解提取列表中的每个元素

Android 9 应用程序菜单是深色背景上的深色文本

javascript - 将 setTimeout 与 Canvas 结合使用以打印数组中的文本

python - 为什么从字典创建集合时会出错

Perl:使用循环还是 Map/Grep?

python 3.4 : Pandas DataFrame not responding to ordered dictionary

haskell - 在 Haskell 中打印空列表