///|
/// Run a raising function that raises `BerError` and convert the outcome to
/// a `Result`.
pub fn[T] result_of_ber(f : () -> T raise BerError) -> Result[T, BerError] {
Ok(f()) catch {
e => Err(e)
}
}
///|
/// Run a raising `Unit` function that raises `BerError`, converting the
/// outcome to a `Result`.
pub fn result_of_unit_ber(
f : () -> Unit raise BerError,
) -> Result[Unit, BerError] {
try {
f()
Ok(())
} catch {
e => Err(e)
}
}
///|
/// Return a new array with the elements reversed.
pub fn[T] reverse_array(arr : Array[T]) -> Array[T] {
let out : Array[T] = []
let mut i = arr.length() - 1
while i >= 0 {
out.push(arr[i])
i = i - 1
}
out
}