universum
universum copied to clipboard
Do something with 'fromStrict' and 'toStrict'
Those functions can be polymorphic.
Also we can add fromLazy
and toLazy
for convenience.
Also either deprecate toLText
or add toLByteString
or only add toLByteString
and remove fromStrict
and toStrict
from exports.
Initially was raised by @gromakovsky.
I tried to convert from Text
to LByteString
with universum
and was really confused... The only way to do this is to write:
import qualified Data.ByteString.Lazy as BSL (fromStrict)
t2b :: Text -> LByteString
t2b = BSL.fromStrict . encodeUtf8
Discuss please.
class LazyStrict l s | l -> s, s -> l where
toLazy :: s -> l
toStrict :: l -> s
fromLazy :: LazyStrict l s => l -> s
fromLazy = toStrict
fromStrict :: LazyStrict l s => s -> l
fromStrict = toLazy
instance LazyStrict L.ByteString S.ByteString
instance LazyStrict L.Text S.Text
something like this?
@int-index Yes, this looks quite good to me.
t2b :: Text -> LByteString
t2b = BSL.fromStrict . encodeUtf8
It's strange that you need to do BSL.fromStrict
, because encodeUtf8
is polymorphic and there is instance ConvertUtf8 Text LByteString
.
Also either deprecate
toLText
or addtoLByteString
or only addtoLByteString
I say we deprecate and eventually delete toLText
Let's also:
- Delete the re-export of
Data.Text.Lazy.toStrict
andData.Text.Lazy.fromStrict
fromUniversum.String.Reexport
- Remember to update the rules in
.hlint.yaml