Char
Utilities for working with the Char type.
Edit on GitHubThe Char type represents a single Unicode scalar value.
Added in 0.3.0
No other changes yet.
from "char" include Char
'a'
'1'
'🌾'
Functions and constants included in the Char module.
Added in 0.3.0
No other changes yet.
min : Number
The minimum valid Unicode scalar value.
Added in 0.3.0
No other changes yet.
max : Number
The maximum valid Unicode scalar value.
Added in 0.3.0
No other changes yet.
isValid : (charCode: Number) => Bool
Determines whether the given character code is a valid Unicode scalar value.
Parameters:
| param | type | description |
|---|---|---|
charCode | Number | The number to check |
charCode: The number to checkReturns:
| type | description |
|---|---|
Bool | true if the number refers to a valid Unicode scalar value or false otherwise |
Bool: true if the number refers to a valid Unicode scalar value or false otherwiseExamples:
Char.isValid(0) == true
Char.isValid(-1) == false
Added in 0.3.0
No other changes yet.
code : (char: Char) => Number
Determines the Unicode scalar value for a character.
Parameters:
| param | type | description |
|---|---|---|
char | Char | The character |
char: The characterReturns:
| type | description |
|---|---|
Number | The Unicode scalar value for the given character |
Number: The Unicode scalar value for the given characterExamples:
Char.code('a') == 97
Char.code('🌾') == 127806
Added in 0.3.0
No other changes yet.
fromCode : (usv: Number) => Char
Creates a character from the given Unicode scalar value.
Parameters:
| param | type | description |
|---|---|---|
usv | Number | The Unicode scalar value |
usv: The Unicode scalar valueReturns:
| type | description |
|---|---|
Char | The character for the given Unicode scalar value |
Char: The character for the given Unicode scalar valueThrows:
InvalidArgument(String)
- When the Unicode scalar value is invalid
Examples:
Char.fromCode(97) == 'a'
Char.fromCode(127806) == '🌾'
Added in 0.3.0
No other changes yet.
succ : (char: Char) => Char
Returns the next valid character by Unicode scalar value.
Parameters:
| param | type | description |
|---|---|---|
char | Char | The character |
char: The characterReturns:
| type | description |
|---|---|
Char | The next valid character by Unicode scalar value |
Char: The next valid character by Unicode scalar valueThrows:
Failure(String)
- When the input character is the maximum valid Unicode scalar value
Examples:
Char.succ('a') == 'b'
Char.succ('1') == '2'
Added in 0.3.0
No other changes yet.
pred : (char: Char) => Char
Returns the previous valid character by Unicode scalar value.
Parameters:
| param | type | description |
|---|---|---|
char | Char | The character |
char: The characterReturns:
| type | description |
|---|---|
Char | The previous valid character by Unicode scalar value |
Char: The previous valid character by Unicode scalar valueThrows:
Failure(String)
- When the input character is the minimum valid Unicode scalar value
Examples:
Char.pred('b') == 'a'
Char.pred('2') == '1'
Added in 0.3.0
No other changes yet.
toString : (char: Char) => String
Converts the given character to a string.
Parameters:
| param | type | description |
|---|---|---|
char | Char | The character to convert |
char: The character to convertReturns:
| type | description |
|---|---|
String | A string containing the given character |
String: A string containing the given characterExamples:
Char.toString('a') == "a"
Char.toString('🌾') == "🌾"
Added in 0.6.0
No other changes yet.
(<) : (x: Char, y: Char) => Bool
Checks if the first character is less than the second character by Unicode scalar value.
Parameters:
| param | type | description |
|---|---|---|
x | Char | The first character |
y | Char | The second character |
x: The first charactery: The second characterReturns:
| type | description |
|---|---|
Bool | true if the first character is less than the second character or false otherwise |
Bool: true if the first character is less than the second character or false otherwiseExamples:
use Char.{ (<) }
assert 'a' < 'b'
use Char.{ (<) }
assert '1' < '2'
Added in 0.6.0
No other changes yet.
(<=) : (x: Char, y: Char) => Bool
Checks if the first character is less than or equal to the second character by Unicode scalar value.
Parameters:
| param | type | description |
|---|---|---|
x | Char | The first character |
y | Char | The second character |
x: The first charactery: The second characterReturns:
| type | description |
|---|---|
Bool | true if the first character is less than or equal to the second character or false otherwise |
Bool: true if the first character is less than or equal to the second character or false otherwiseExamples:
use Char.{ (<=) }
assert 'a' <= 'b'
use Char.{ (<=) }
assert '1' <= '2'
use Char.{ (<=) }
assert 'a' <= 'a'
Added in 0.6.0
No other changes yet.
(>) : (x: Char, y: Char) => Bool
Checks if the first character is greater than the second character by Unicode scalar value.
Parameters:
| param | type | description |
|---|---|---|
x | Char | The first character |
y | Char | The second character |
x: The first charactery: The second characterReturns:
| type | description |
|---|---|
Bool | true if the first character is greater than the second character or false otherwise |
Bool: true if the first character is greater than the second character or false otherwiseExamples:
use Char.{ (>) }
assert 'b' > 'a'
use Char.{ (>) }
assert '2' > '1'
Added in 0.6.0
No other changes yet.
(>=) : (x: Char, y: Char) => Bool
Checks if the first character is greater than or equal to the second character by Unicode scalar value.
Parameters:
| param | type | description |
|---|---|---|
x | Char | The first character |
y | Char | The second character |
x: The first charactery: The second characterReturns:
| type | description |
|---|---|
Bool | true if the first character is greater than or equal to the second character or false otherwise |
Bool: true if the first character is greater than or equal to the second character or false otherwiseExamples:
use Char.{ (>=) }
assert 'b' >= 'a'
use Char.{ (>=) }
assert '2' >= '1'
use Char.{ (>=) }
assert 'a' >= 'a'
Added in 0.6.0
No other changes yet.
isAsciiDigit : (char: Char) => Bool
Checks if the character is an ASCII digit.
Parameters:
| param | type | description |
|---|---|---|
char | Char | The character to check |
char: The character to checkReturns:
| type | description |
|---|---|
Bool | true if the character is an ASCII digit or false otherwise |
Bool: true if the character is an ASCII digit or false otherwiseExamples:
assert Char.isAsciiDigit('1')
assert !Char.isAsciiDigit('a')
Added in 0.6.0
No other changes yet.
isAsciiAlpha : (char: Char) => Bool
Checks if the character is an ASCII alphabetical character.
Parameters:
| param | type | description |
|---|---|---|
char | Char | The character to check |
char: The character to checkReturns:
| type | description |
|---|---|
Bool | true if the character is an ASCII alphabetical or false otherwise |
Bool: true if the character is an ASCII alphabetical or false otherwiseExamples:
assert Char.isAsciiAlpha('a')
assert !Char.isAsciiAlpha('1')
Added in 0.6.0
No other changes yet.
toAsciiLowercase : (char: Char) => Char
Converts the character to ASCII lowercase if it is an ASCII uppercase character.
Parameters:
| param | type | description |
|---|---|---|
char | Char | The character to convert |
char: The character to convertReturns:
| type | description |
|---|---|
Char | The lowercased character |
Char: The lowercased characterExamples:
assert Char.toAsciiLowercase('B') == 'b'
Added in 0.6.0
No other changes yet.
toAsciiUppercase : (char: Char) => Char
Converts the character to ASCII uppercase if it is an ASCII lowercase character.
Parameters:
| param | type | description |
|---|---|---|
char | Char | The character to convert |
char: The character to convertReturns:
| type | description |
|---|---|
Char | The uppercased character |
Char: The uppercased characterExamples:
assert Char.toAsciiUppercase('b') == 'B'