Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

Result

Functions

error
(
input
:
a
)
:
Result(a, b)

Returns a new error result.

(Result.error("error")
|> Result.isError()) == true
flatMap
(
input
:
Result(error, a)
func
:
Function(a, Result(error, b))
)
:
Result(error, b)

Maps over the value of the result to an other result and flattens it.

(Result.error("error")
|> Result.flatMap(\item : String => Result::Ok(item + "1"))) == Result.error("error")

(Result.ok("ok")
|> Result.map(\item : String => Result::Ok(item + "1"))) == Result.ok("ok1")
isError
(
input
:
Result(a, b)
)
:
Bool

Returns true if the result is an error.

(Result.error("error")
|> Result.isError()) == true
isOk
(
input
:
Result(a, b)
)
:
Bool

Returns true if the result is ok.

(Result.ok("ok")
|> Result.isOk()) == true
join
(
input
:
Result(error, Result(error, value))
)
:
Result(error, value)

Joins two results together.

Result.join(Result::Ok(Result::Ok("Hello"))) == Result::Ok("Hello")
Result.join(Result::Err("Error") == Result::Err("Error")
map
(
input
:
Result(a, b)
func
:
Function(b, c)
)
:
Result(a, c)

Maps over the value of the result.

(Result.error("error")
|> Result.map(\item : String => item + "1")) == Result.error("error")

(Result.ok("ok")
|> Result.map(\item : String => item + "1")) == Result.ok("ok1")
mapError
(
input
:
Result(a, b)
func
:
Function(a, c)
)
:
Result(c, b)

Maps over the error of the result.

(Result.error("error")
|> Result.mapError(\item : String => item + "1")) == Result.error("error1")

(Result.ok("ok")
|> Result.mapError(\item : String => item + "1")) == Result.ok("ok")
ok
(
input
:
a
)
:
Result(b, a)

Returns a new ok result.

(Result.ok("ok")
|> Result.isOk()) == true
toMaybe
(
result
:
Result(a, b)
)
:
Maybe(b)

Converts the result into a maybe.

(Result.ok("blah")
|> Result.toMaybe()) == Maybe.just("blah")

(Result.error("blah")
|> Result.toMaybe()) == Maybe.nothing()
withDefault
(
input
:
Result(a, b)
defaultValue
:
b
)
:
b

Returns the value of the result or the default value if it's an error.

(Result.error("error")
|> Result.withDefault("a")) == "a"

(Result.ok("ok")
|> Result.withDefault("a")) == "ok"
withError
(
input
:
Result(a, b)
defaultError
:
a
)
:
a

Returns the error of the result or the default value if it's an ok.

(Result.error("error")
|> Result.withError("a")) == "error"

(Result.ok("ok")
|> Result.withError("a")) == "a"