{-# LANGUAGE Trustworthy #-}
module Data.Text.Short.Partial
( head
, tail
, init
, last
, index
, foldl1
, foldl1'
, foldr1
) where
import Data.Text.Short
import Data.Text.Short.Internal
import Prelude ()
head :: ShortText -> Char
head :: ShortText -> Char
head = Char
-> ((Char, ShortText) -> Char) -> Maybe (Char, ShortText) -> Char
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> Char
forall a. HasCallStack => [Char] -> a
error [Char]
"head: empty ShortText") (Char, ShortText) -> Char
forall a b. (a, b) -> a
fst (Maybe (Char, ShortText) -> Char)
-> (ShortText -> Maybe (Char, ShortText)) -> ShortText -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> Maybe (Char, ShortText)
uncons
tail :: ShortText -> ShortText
tail :: ShortText -> ShortText
tail = ShortText
-> ((Char, ShortText) -> ShortText)
-> Maybe (Char, ShortText)
-> ShortText
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> ShortText
forall a. HasCallStack => [Char] -> a
error [Char]
"tail: empty ShortText") (Char, ShortText) -> ShortText
forall a b. (a, b) -> b
snd (Maybe (Char, ShortText) -> ShortText)
-> (ShortText -> Maybe (Char, ShortText)) -> ShortText -> ShortText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> Maybe (Char, ShortText)
uncons
init :: ShortText -> ShortText
init :: ShortText -> ShortText
init = ShortText
-> ((ShortText, Char) -> ShortText)
-> Maybe (ShortText, Char)
-> ShortText
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> ShortText
forall a. HasCallStack => [Char] -> a
error [Char]
"init: empty ShortText") (ShortText, Char) -> ShortText
forall a b. (a, b) -> a
fst (Maybe (ShortText, Char) -> ShortText)
-> (ShortText -> Maybe (ShortText, Char)) -> ShortText -> ShortText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> Maybe (ShortText, Char)
unsnoc
last :: ShortText -> Char
last :: ShortText -> Char
last = Char
-> ((ShortText, Char) -> Char) -> Maybe (ShortText, Char) -> Char
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> Char
forall a. HasCallStack => [Char] -> a
error [Char]
"last: empty ShortText") (ShortText, Char) -> Char
forall a b. (a, b) -> b
snd (Maybe (ShortText, Char) -> Char)
-> (ShortText -> Maybe (ShortText, Char)) -> ShortText -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> Maybe (ShortText, Char)
unsnoc
index :: ShortText -> Int -> Char
index :: ShortText -> Int -> Char
index ShortText
st Int
i = case ShortText -> Int -> Maybe Char
indexMaybe ShortText
st Int
i of
Maybe Char
Nothing -> [Char] -> Char
forall a. HasCallStack => [Char] -> a
error [Char]
"index: not within ShortText"
Just Char
c -> Char
c