Copyright | (C) 2021 Koz Ross |
---|---|
License | Apache 2.0 |
Maintainer | Koz Ross <koz.ross@retro-freedom.nz> |
Stability | stable |
Portability | GHC only |
Safe Haskell | None |
Language | Haskell2010 |
A wrapper for partial type class instances and functions.
This module is designed for qualified importing:
import qualified Text.Ascii.Unsafe as Unsafe
Synopsis
- newtype Unsafe (a :: Type) = Unsafe {
- safe :: a
- head :: Unsafe AsciiText -> AsciiChar
- last :: Unsafe AsciiText -> AsciiChar
- tail :: Unsafe AsciiText -> Unsafe AsciiText
- init :: Unsafe AsciiText -> Unsafe AsciiText
- foldl1 :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> AsciiChar
- foldl1' :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> AsciiChar
- foldr1 :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> AsciiChar
- foldr1' :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> AsciiChar
- maximum :: Unsafe AsciiText -> AsciiChar
- minimum :: Unsafe AsciiText -> AsciiChar
- scanl1 :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> Unsafe AsciiText
- scanr1 :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> Unsafe AsciiText
- index :: Unsafe AsciiText -> Int -> AsciiChar
Types
newtype Unsafe (a :: Type) Source #
A wrapper for a type, designating that partial type class methods or other functions are available for it.
The role of Unsafe'
s type argument is set to nominal. Among other things,
it means that this type can't be coerced or derived through. This ensures
clear indication when (and to what extent) non-total operations occur in any
code using them.
Since: 1.0.1
Instances
Text functions
head :: Unsafe AsciiText -> AsciiChar Source #
Yield the first character of the text.
Requirements: Text is not empty.
>>>
head . Unsafe $ [ascii| "catboy" |]
'0x63'
Complexity: \(\Theta(1)\)
Since: 1.0.1
last :: Unsafe AsciiText -> AsciiChar Source #
Yield the last character of the text.
Requirements: Text is not empty.
>>>
last . Unsafe $ [ascii| "catboy" |]
'0x79'
Complexity: \(\Theta(1)\)
Since: 1.0.1
tail :: Unsafe AsciiText -> Unsafe AsciiText Source #
Yield the text without its first character.
Requirements: Text is not empty.
>>>
tail . Unsafe $ [ascii| "catboy" |]
"atboy"
Complexity: \(\Theta(1)\)
Since: 1.0.1
init :: Unsafe AsciiText -> Unsafe AsciiText Source #
Yield the text without its last character.
Requirements: Text is not empty.
>>>
init . Unsafe $ [ascii| "catboy" |]
"catbo"
Complexity: \(\Theta(1)\)
Since: 1.0.1
foldl1 :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> AsciiChar Source #
Left-associative fold of a text without a base case.
Requirements: Text is not empty.
Complexity: \(\Theta(n)\)
Since: 1.0.1
foldl1' :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> AsciiChar Source #
Left-associative fold of a text without a base case, strict in the accumulator.
Requirements: Text is not empty.
Complexity: \(\Theta(n)\)
Since: 1.0.1
foldr1 :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> AsciiChar Source #
Right-associative fold of a text without a base case.
Requirements: Text is not empty.
Complexity: \(\Theta(n)\)
Since: 1.0.1
foldr1' :: (AsciiChar -> AsciiChar -> AsciiChar) -> Unsafe AsciiText -> AsciiChar Source #
Right-associative fold of a text without a base case, strict in the accumulator.
Requirements: Text is not empty.
Complexity: \(\Theta(n)\)
Since: 1.0.1
maximum :: Unsafe AsciiText -> AsciiChar Source #
Yield the character in the text whose byte representation is numerically the largest.
Requirements: Text is not empty.
>>>
maximum . Unsafe $ [ascii| "catboy" |]
'0x79'>>>
maximum . Unsafe $ [ascii| "nyan~" |]
'0x7e'
Complexity: \(\Theta(n)\)
Since: 1.0.1
minimum :: Unsafe AsciiText -> AsciiChar Source #
Yield the character in the text whose byte representation is numerically the smallest.
Requirements: Text is not empty.
>>>
minimum . Unsafe $ [ascii| "catboy" |]
'0x61'>>>
minimum . Unsafe $ [ascii| " nyan" |]
'0x20'
Complexity: \(\Theta(n)\)
Since: 1.0.1
index :: Unsafe AsciiText -> Int -> AsciiChar Source #
Yield the character at the given position.
Requirements: The position must be at least 0, and at most the length of the text - 1.
>>>
index (Unsafe [ascii| "catboy" |]) 0
'0x63'>>>
index (Unsafe $ [ascii| "catboy" |]) 4
'0x6f'
Complexity: \(\Theta(1)\)
Since: 1.0.1