ESC
No recent searches
Search by
Standard Library  /  Char

Char

Utilities for working with the Char type.

Edit on GitHub

The Char type represents a single Unicode scalar value.

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

Values

Functions and constants included in the Char module.

Char.min

Added in 0.3.0 No other changes yet.
min : Number

The minimum valid Unicode scalar value.

Char.max

Added in 0.3.0 No other changes yet.
max : Number

The maximum valid Unicode scalar value.

Char.isValid

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:

charCode: The number to check

Returns:

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

Examples:

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

Char.code

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

Determines the Unicode scalar value for a character.

Parameters:

char: The character

Returns:

Number: The Unicode scalar value for the given character

Examples:

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

Char.fromCode

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

Creates a character from the given Unicode scalar value.

Parameters:

usv: The Unicode scalar value

Returns:

Char: The character for the given Unicode scalar value

Throws:

InvalidArgument(String)

  • When the Unicode scalar value is invalid

Examples:

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

Char.succ

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

Returns the next valid character by Unicode scalar value.

Parameters:

char: The character

Returns:

Char: The next valid character by Unicode scalar value

Throws:

Failure(String)

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

Examples:

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

Char.pred

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

Returns the previous valid character by Unicode scalar value.

Parameters:

char: The character

Returns:

Char: The previous valid character by Unicode scalar value

Throws:

Failure(String)

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

Examples:

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

Char.toString

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

Converts the given character to a string.

Parameters:

char: The character to convert

Returns:

String: A string containing the given character

Examples:

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

Char.(<)

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:

x: The first character
y: The second character

Returns:

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

Examples:

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

Char.(<=)

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:

x: The first character
y: The second character

Returns:

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

Examples:

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

Char.(>)

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:

x: The first character
y: The second character

Returns:

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

Examples:

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

Char.(>=)

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:

x: The first character
y: The second character

Returns:

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

Examples:

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

Char.isAsciiDigit

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

Checks if the character is an ASCII digit.

Parameters:

char: The character to check

Returns:

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

Examples:

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

Char.isAsciiAlpha

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

Checks if the character is an ASCII alphabetical character.

Parameters:

char: The character to check

Returns:

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

Examples:

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

Char.toAsciiLowercase

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:

char: The character to convert

Returns:

Char: The lowercased character

Examples:

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

Char.toAsciiUppercase

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:

char: The character to convert

Returns:

Char: The uppercased character

Examples:

assert Char.toAsciiUppercase('b') == 'B'

Sign up for farm-to-inbox developer news

You can unsubscribe at any time. Read our privacy policy.

Copyright © 2024 The Grain Programming Language