module Dhall.LSP.Util (
tshow,
lines',
rightToMaybe,
unlines'
) where
import Data.List.NonEmpty
import Data.Text
tshow :: Show a => a -> Text
tshow :: a -> Text
tshow = String -> Text
pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show
lines' :: Text -> NonEmpty Text
lines' :: Text -> NonEmpty Text
lines' Text
text =
case (Char -> Bool) -> Text -> [Text]
split (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\n') Text
text of
[] -> Text
"" Text -> [Text] -> NonEmpty Text
forall a. a -> [a] -> NonEmpty a
:| []
Text
l : [Text]
ls -> Text
l Text -> [Text] -> NonEmpty Text
forall a. a -> [a] -> NonEmpty a
:| [Text]
ls
unlines' :: [Text] -> Text
unlines' :: [Text] -> Text
unlines' = Text -> [Text] -> Text
intercalate Text
"\n"
rightToMaybe :: Either a b -> Maybe b
rightToMaybe :: Either a b -> Maybe b
rightToMaybe (Right b
b) = b -> Maybe b
forall a. a -> Maybe a
Just b
b
rightToMaybe (Left a
_) = Maybe b
forall a. Maybe a
Nothing