[英]Are there monadic/applicative map (i.e. traverse/mapM) functions over ByteString or Text?
ByteString和Text有标准(纯)映射函数:
map :: (Word8 -> Word8) -> ByteString -> ByteString
map :: (Char -> Char) -> Text -> Text
但我想念他们的单子/适用对象:
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.bytes
和Data.Text.Lens.text
。
编辑:为澄清(c ~ Bytestring, e ~ Word8)
上述函数是SimpleTraversal ce
类型的(广义化)(分别用于(c ~ Bytestring, e ~ Word8)
和(c ~ Text, e ~ Char)
(c ~ Bytestring, e ~ Word8)
),这是类型的同义词forall f. (Applicative f) => (e -> fe) -> c -> fc
forall f. (Applicative f) => (e -> fe) -> c -> fc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.