Char

GitHub   Edit on GitHub

Utilities for working with the Char type.

The Char type represents a single Unicode scalar value.

Added in 0.3.0 No other changes yet.
1
from "char" include Char
1
'a'
1
'1'
1
'🌾'

Values

Functions and constants included in the Char module.

Char.min

Added in 0.3.0 No other changes yet.
1
min : Number

The minimum valid Unicode scalar value.

Char.max

Added in 0.3.0 No other changes yet.
1
max : Number

The maximum valid Unicode scalar value.

Char.isValid

Added in 0.3.0 No other changes yet.
1
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

Returns:

type description
Bool true if the number refers to a valid Unicode scalar value or false otherwise

Examples:

1
Char.isValid(0) == true
1
Char.isValid(-1) == false

Char.code

Added in 0.3.0 No other changes yet.
1
code : (char: Char) => Number

Determines the Unicode scalar value for a character.

Parameters:

param type description
char Char The character

Returns:

type description
Number The Unicode scalar value for the given character

Examples:

1
Char.code('a') == 97
1
Char.code('🌾') == 127806

Char.fromCode

Added in 0.3.0 No other changes yet.
1
fromCode : (usv: Number) => Char

Creates a character from the given Unicode scalar value.

Parameters:

param type description
usv Number The Unicode scalar value

Returns:

type description
Char The character for the given Unicode scalar value

Throws:

InvalidArgument(String)

  • When the Unicode scalar value is invalid

Examples:

1
Char.fromCode(97) == 'a'
1
Char.fromCode(127806) == '🌾'

Char.succ

Added in 0.3.0 No other changes yet.
1
succ : (char: Char) => Char

Returns the next valid character by Unicode scalar value.

Parameters:

param type description
char Char The character

Returns:

type description
Char The next valid character by Unicode scalar value

Throws:

Failure(String)

  • When the input character is the maximum valid Unicode scalar value

Examples:

1
Char.succ('a') == 'b'
1
Char.succ('1') == '2'

Char.pred

Added in 0.3.0 No other changes yet.
1
pred : (char: Char) => Char

Returns the previous valid character by Unicode scalar value.

Parameters:

param type description
char Char The character

Returns:

type description
Char The previous valid character by Unicode scalar value

Throws:

Failure(String)

  • When the input character is the minimum valid Unicode scalar value

Examples:

1
Char.pred('b') == 'a'
1
Char.pred('2') == '1'

Char.toString

Added in 0.3.0 No other changes yet.
1
toString : (char: Char) => String

Converts the given character to a string.

Parameters:

param type description
char Char The character to convert

Returns:

type description
String A string containing the given character

Examples:

1
Char.toString('a') == "a"
1
Char.toString('🌾') == "🌾"

Char.(<)

Added in 0.6.0 No other changes yet.
1
(<) : (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

Returns:

type description
Bool true if the first character is less than the second character or false otherwise

Examples:

1
2
use Char.{ (<) }
assert 'a' < 'b'
1
2
use Char.{ (<) }
assert '1' < '2'

Char.(<=)

Added in 0.6.0 No other changes yet.
1
(<=) : (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

Returns:

type description
Bool true if the first character is less than or equal to the second character or false otherwise

Examples:

1
2
use Char.{ (<=) }
assert 'a' <= 'b'
1
2
use Char.{ (<=) }
assert '1' <= '2'
1
2
use Char.{ (<=) }
assert 'a' <= 'a'

Char.(>)

Added in 0.6.0 No other changes yet.
1
(>) : (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

Returns:

type description
Bool true if the first character is greater than the second character or false otherwise

Examples:

1
2
use Char.{ (>) }
assert 'b' > 'a'
1
2
use Char.{ (>) }
assert '2' > '1'

Char.(>=)

Added in 0.6.0 No other changes yet.
1
(>=) : (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

Returns:

type description
Bool true if the first character is greater than or equal to the second character or false otherwise

Examples:

1
2
use Char.{ (>=) }
assert 'b' >= 'a'
1
2
use Char.{ (>=) }
assert '2' >= '1'
1
2
use Char.{ (>=) }
assert 'a' >= 'a'

Char.isAsciiDigit

Added in 0.6.0 No other changes yet.
1
isAsciiDigit : (char: Char) => Bool

Checks if the character is an ASCII digit.

Parameters:

param type description
char Char The character to check

Returns:

type description
Bool true if the character is an ASCII digit or false otherwise

Examples:

1
assert Char.isAsciiDigit('1')
1
assert !Char.isAsciiDigit('a')

Char.isAsciiAlpha

Added in 0.6.0 No other changes yet.
1
isAsciiAlpha : (char: Char) => Bool

Checks if the character is an ASCII alphabetical character.

Parameters:

param type description
char Char The character to check

Returns:

type description
Bool true if the character is an ASCII alphabetical or false otherwise

Examples:

1
assert Char.isAsciiAlpha('a')
1
assert !Char.isAsciiAlpha('1')

Char.toAsciiLowercase

Added in 0.6.0 No other changes yet.
1
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

Returns:

type description
Char The lowercased character

Examples:

1
assert Char.toAsciiLowercase('B') == 'b'

Char.toAsciiUppercase

Added in 0.6.0 No other changes yet.
1
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

Returns:

type description
Char The uppercased character

Examples:

1
assert Char.toAsciiUppercase('b') == 'B'
This is a notification!