Folds over [Word8] and ByteString with the same function?

It turns out there is no instance Foldablefor ByteString. I would like to write a function that uses foldl'for [Word8]or ByteString, but I cannot. Because a ByteString, in different ways, is the same as [Word8]it seems that I should be able to.

Is there a package available that combines the two, or should I flip my class class?

+4
source share
2 answers

Take a look at the MonoFoldable class specified in the mono-traversable package .

It has instances for ByteStringand [a].

+9
source

ErikR . . lens bytes:

λ> import Data.ByteString.Lens
λ> import Control.Lens
λ> :t foldrOf bytes
foldrOf bytes
  :: IsByteString s => (GHC.Word.Word8 -> r -> r) -> r -> s -> r

, , - lens: Data.Foldable Data.Traversable, Foldable Traversable, , ?

+7

Source: https://habr.com/ru/post/1648944/


All Articles