stringbuilder-0.5.1/0000755000000000000000000000000013237106467012571 5ustar0000000000000000stringbuilder-0.5.1/LICENSE0000644000000000000000000000206713237106467013603 0ustar0000000000000000Copyright (c) 2011-2018 Simon Hengel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. stringbuilder-0.5.1/stringbuilder.cabal0000644000000000000000000000160713237106467016436 0ustar0000000000000000name: stringbuilder version: 0.5.1 synopsis: A writer monad for multi-line string literals description: category: Testing license: MIT license-file: LICENSE copyright: (c) 2011-2018 Simon Hengel author: Simon Hengel maintainer: Simon Hengel build-type: Simple cabal-version: >= 1.8 source-repository head type: git location: https://github.com/sol/stringbuilder library ghc-options: -Wall hs-source-dirs: src build-depends: base == 4.* exposed-modules: Data.String.Builder test-suite spec type: exitcode-stdio-1.0 main-is: Spec.hs ghc-options: -Wall hs-source-dirs: test build-depends: base , stringbuilder , hspec >= 1.3 , QuickCheck stringbuilder-0.5.1/Setup.lhs0000644000000000000000000000011413237106467014375 0ustar0000000000000000#!/usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain stringbuilder-0.5.1/test/0000755000000000000000000000000013237106467013550 5ustar0000000000000000stringbuilder-0.5.1/test/Spec.hs0000644000000000000000000000110113237106467014767 0ustar0000000000000000{-# LANGUAGE OverloadedStrings #-} module Main (main, spec) where import Test.Hspec import Test.QuickCheck import Data.String import Data.String.Builder main :: IO () main = hspec spec spec :: Spec spec = do describe "build" $ do it "can be used to construct multi-line string literals in a monadic way" $ do build $ do "foo" "bar" "baz" `shouldBe` "foo\nbar\nbaz\n" it "works for arbitrary input" $ do property $ \l -> (build . sequence_ . map fromString) l == unlines l stringbuilder-0.5.1/src/0000755000000000000000000000000013237106467013360 5ustar0000000000000000stringbuilder-0.5.1/src/Data/0000755000000000000000000000000013237106467014231 5ustar0000000000000000stringbuilder-0.5.1/src/Data/String/0000755000000000000000000000000013237106467015477 5ustar0000000000000000stringbuilder-0.5.1/src/Data/String/Builder.hs0000644000000000000000000000251313237106467017422 0ustar0000000000000000{-# LANGUAGE CPP, DeriveFunctor, TypeSynonymInstances, FlexibleInstances, TypeFamilies #-} -- | -- The `build` function can be used to construct multi-line string literals in -- a monadic way: -- -- > {-# LANGUAGE OverloadedStrings #-} -- > -- > import Data.String.Builder -- > -- > mystring :: String -- > mystring = build $ do -- > "foo" -- > "bar" -- > "baz" module Data.String.Builder ( -- * Functions build , literal -- * Types , Builder , BuilderM ) where import Control.Applicative import Control.Monad import Data.Monoid import Data.String -- | A writer monad for string literals. data BuilderM a = BuilderM a ShowS deriving Functor instance Applicative BuilderM where pure = return (<*>) = ap instance Monad BuilderM where return a = BuilderM a id BuilderM a xs >>= f = case f a of BuilderM b ys -> BuilderM b (xs . ys) type Builder = BuilderM () instance Monoid Builder where mempty = return () #if !MIN_VERSION_base(4,11,0) mappend = (>>) #else instance Semigroup Builder where (<>) = (>>) #endif -- | Add a literal string. literal :: String -> Builder literal = BuilderM () . showString instance (a ~ ()) => IsString (BuilderM a) where fromString s = literal s >> literal "\n" -- | Run a builder. build :: Builder -> String build (BuilderM () s) = s ""