packages feed

readable 0.2 → 0.2.0.1

raw patch · 2 files changed

+17/−8 lines, 2 filesdep ~bytestringdep ~text

Dependency ranges changed: bytestring, text

Files

readable.cabal view
@@ -1,10 +1,10 @@ name:           readable-version:        0.2+version:        0.2.0.1 synopsis:       Reading from Text and ByteString  description:   Provides a Readable type class for reading data types from ByteString and-  Text.+  Text.  Also includes efficient implementations for common data types.  license:        BSD3 license-file:   LICENSE@@ -28,8 +28,8 @@    build-depends:     base        >= 4    && < 5,-    bytestring  >= 0.9,-    text        >= 0.11+    bytestring  >= 0.9  && < 0.11,+    text        >= 0.11 && < 1.3    ghc-prof-options: -prof -auto-all   ghc-options: -Wall -fwarn-tabs
src/Data/Readable.hs view
@@ -5,8 +5,8 @@ The Read type class is very useful for building data types from String representations.  But String has high overhead, so sometimes it isn't suitable for applications where space usage and performance are important.  This-library provides a simpler version of Read's functionality for Text and UTF8-encoded ByteStrings.+library provides a simpler version of Read's functionality for Text and+ByteStrings.  -} @@ -32,9 +32,18 @@ class Readable a where     -- | Reads data from a Text representation.     fromText :: MonadPlus m => Text -> m a-    -- | Reads data from a UTF8 encoded ByteString.+    -- | Reads data from a UTF8 encoded ByteString.  The default+    -- implementation of this function simply decodes with UTF-8 and then+    -- calls the fromText function.  If decoding fails, mzero will be+    -- returned.  You can provide your own implementation if you need+    -- different behavior.     fromBS   :: MonadPlus m => ByteString -> m a-    fromBS = fromText . decodeUtf8+    fromBS = fromText <=< hushPlus . decodeUtf8'+++hushPlus :: MonadPlus m => Either a b -> m b+hushPlus (Left _) = mzero+hushPlus (Right b) = return b   ------------------------------------------------------------------------------