turtle-1.6.2: Shell programming, Haskell-style

Safe Haskell | None
Language | Haskell2010

Turtle.Line

Synopsis

- data Line
- lineToText :: Line -> Text
- textToLines :: Text -> NonEmpty Line
- linesToText :: [Line] -> Text
- textToLine :: Text -> Maybe Line
- unsafeTextToLine :: Text -> Line
- data NewlineForbidden = NewlineForbidden

# Documentation

data Line #

A line of text (does not contain newlines).

#### Instances

Instances details

Monoid Line # |
Instance details Defined in Turtle.Line Methods mempty :: Line # mappend :: Line -> Line -> Line # mconcat :: [Line] -> Line #
Semigroup Line # |
Instance details Defined in Turtle.Line Methods (<>) :: Line -> Line -> Line # sconcat :: NonEmpty Line -> Line # stimes :: Integral b => b -> Line -> Line #
IsString Line # |
Instance details Defined in Turtle.Line Methods fromString :: String -> Line #
Show Line # |
Instance details Defined in Turtle.Line Methods showsPrec :: Int -> Line -> ShowS # show :: Line -> String # showList :: [Line] -> ShowS #
Eq Line # |
Instance details Defined in Turtle.Line Methods (==) :: Line -> Line -> Bool # (/=) :: Line -> Line -> Bool #
Ord Line # |
Instance details Defined in Turtle.Line Methods compare :: Line -> Line -> Ordering # (<) :: Line -> Line -> Bool # (<=) :: Line -> Line -> Bool # (>) :: Line -> Line -> Bool # (>=) :: Line -> Line -> Bool # max :: Line -> Line -> Line # min :: Line -> Line -> Line #

lineToText :: Line -> Text #

Convert a line to a text value.

textToLines :: Text -> NonEmpty Line #

Split text into lines. The inverse of `linesToText`.

linesToText :: [Line] -> Text #

Merge lines into a single text value.

textToLine :: Text -> Maybe Line #

Try to convert a text value into a line. Precondition (checked): the argument does not contain newlines.

unsafeTextToLine :: Text -> Line #

Convert a text value into a line. Precondition (unchecked): the argument does not contain newlines.

data NewlineForbidden #

The `NewlineForbidden` exception is thrown when you construct a `Line` using an overloaded string literal or by calling `fromString` explicitly and the supplied string contains newlines. This is a programming error to do so: if you aren't sure that the input string is newline-free, do not rely on the ``IsString` `Line`` instance.

When debugging, it might be useful to look for implicit invocations of `fromString` for `Line`:

    >>> sh (do { line <- "Hello\nWorld"; echo line })
    *** Exception: NewlineForbidden

In the above example, `echo` expects its argument to be a `Line`, thus `line :: `Line``. Since we bind `line` in `Shell`, the string literal `"Hello\nWorld"` has type ``Shell` `Line``. The ``IsString` (`Shell` `Line`)` instance delegates the construction of a `Line` to the ``IsString` `Line`` instance, where the exception is thrown.

To fix the problem, use `textToLines`:

    >>> sh (do { line <- select (textToLines "Hello\nWorld"); echo line })
    Hello
    World

Constructors

NewlineForbidden |

#### Instances

Instances details

Exception NewlineForbidden # |
Instance details Defined in Turtle.Line Methods toException :: NewlineForbidden -> SomeException # fromException :: SomeException -> Maybe NewlineForbidden # displayException :: NewlineForbidden -> String # backtraceDesired :: NewlineForbidden -> Bool #
Show NewlineForbidden # |
Instance details Defined in Turtle.Line Methods showsPrec :: Int -> NewlineForbidden -> ShowS # show :: NewlineForbidden -> String # showList :: [NewlineForbidden] -> ShowS #