Bool
Functions for interacting with JavaScript booleans.
See: Boolean
t
RESCRIPT
type t = bool
Type representing a boolean.
toString
RESCRIPT
let toString: bool => string
Converts a boolean to a string.
Examples
RESCRIPTBool.toString(true) == "true"
Bool.toString(false) == "false"
fromString
RESCRIPT
let fromString: string => option<bool>
Converts a string to a boolean.
Examples
RESCRIPTBool.fromString("true") == Some(true)
Bool.fromString("false") == Some(false)
Bool.fromString("notAValidBoolean") == None
fromStringOrThrow
RESCRIPT
let fromStringOrThrow: string => bool
Converts a string to a boolean.
Throws an Invalid_argument
exception if the string is not a valid boolean.
Examples
RESCRIPTBool.fromStringOrThrow("true") == true
Bool.fromStringOrThrow("false") == false
switch Bool.fromStringOrThrow("notAValidBoolean") {
| exception Invalid_argument(_) => assert(true)
| _ => assert(false)
}
fromStringExn
Deprecated
RESCRIPT
let fromStringExn: string => bool
Converts a string to a boolean.
Beware, this function will throw an Invalid_argument
exception
if the string is not a valid boolean.
Examples
RESCRIPTBool.fromStringExn("true") == true
Bool.fromStringExn("false") == false
switch Bool.fromStringExn("notAValidBoolean") {
| exception Invalid_argument(_) => assert(true)
| _ => assert(false)
}
compare
RESCRIPT
let compare: (bool, bool) => Ordering.t
Compares two booleans, returns an Ordering.t
value.
Examples
RESCRIPTBool.compare(true, true) == Ordering.equal
Bool.compare(false, false) == Ordering.equal
Bool.compare(true, false) == Ordering.greater
Bool.compare(false, true) == Ordering.less
equal
RESCRIPT
let equal: (bool, bool) => bool