Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a Text to a bytestring Builder?

Tags:

haskell

The blaze-builder package provides a .Char.Utf8 module which includes fromText and fromLazyText for efficiently converting a value from the text package into a blaze-builder Builder value. With the new Builder API in bytestring, however, no such function exists (since bytestring does not depend on text). We could unpack the Text values and use stringUtf8, but that's almost certain to be much slower.

Another option would be to use blaze-builder, which is now actually just a wrapper around bytestring's Builder type, but I'm wondering if there's a more idiomatic way of approaching this.

like image 890
Michael Snoyman Avatar asked Sep 26 '22 16:09

Michael Snoyman


1 Answers

You can use encodeUtf8Builder function and the corresponding function for lazy text.

like image 70
Yuras Avatar answered Oct 03 '22 15:10

Yuras