string-interpolate-0.3.0.0: Haskell string/text/bytestring interpolation that just works

Copyright(c) William Yao 2019-2020
LicenseBSD-3
Maintainerwilliamyaoh@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Data.String.Interpolate

Description

This module provides three quasiquoters, i, __i, and iii, which:

  • handle all of String/Text/ByteString, both strict and lazy
  • can interpolate into anything that implements IsString
  • can interpolate anything that implements Show
  • are Unicode aware
  • are fast
  • handle multiline strings

i leaves newlines and whitespace intact as they are in the source code. __i strips leading indentation and surrounding blank lines, while leaving linebreaks intact. iii collapses newlines/whitespace into single spaces, putting all the output on a single line.

As an example,

{-# LANGUAGE OverloadedStrings #-}

import Data.Text
import Data.String.Interpolate ( i )

λ> age = 33 :: Int
λ> name = "Tatiana" :: Text
λ> [i|{"name": "#{name}", "age": #{age}}|] :: String
>>> "{\"name\": \"Tatiana\", \"age\": 33}"

λ> [i|
Name: #{name}
Age: #{age}
|] :: String
>>> "\nName: Tatiana\nAge: 33\n"

See the README at https://gitlab.com/williamyaoh/string-interpolate/blob/master/README.md for more details and examples.

Synopsis

Documentation

i :: QuasiQuoter Source #

The basic, no-frills interpolator. Will interpolate anything you wrap in #{}, and otherwise leaves what you write alone.

__i :: QuasiQuoter Source #

An interpolator that handles indentation. Will interpolate anything you wrap in #{}, remove leading indentation, and remove any blank lines before and after the content.

If the contained interpolation uses both tabs and spaces for indentation, __i will assume the indentation type it finds in the first nonblank line, ignoring indentation of the other type. Please don't use mixed indentation.

Note that only indentation you actually write in source code will be stripped; __i does not touch any lines or whitespace inserted by interpolations themselves.

There is no extra performance penalty for using __i.

iii :: QuasiQuoter Source #

An interpolator that strips excess whitespace. Will collapse any sequences of multiple spaces or whitespace into a single space, putting the output onto a single line with surrounding whitespace removed.

Note that only whitespace you actually write in source code will be collapsed; iii does not touch any lines or whitespace inserted by interpolations themselves.

There is no extra performance penalty for using iii.