Result module

The gleam/result standard library module contains functions for working with results. Gleam programs will make heavy use of this module to avoid excessive nested case expressions when calling multiple functions that can fail.

gleam/result 標準ライブラリモジュールには、結果を扱うための関数が含まれています。Gleam プログラムでは、失敗する可能性のある複数の関数を呼び出す際に、過剰な入れ子の case 式を避けるために、このモジュールを多用します。

map updates a value held within the Ok of a result by calling a given function on it. If the result is an error then the function is not called.

map は、与えられた関数を呼び出すことによって、結果の Ok 内に保持されている値を更新します。結果がエラーの場合はその関数は呼び出されません。

try runs a result returning function on the value held within an Ok of a result. If the result is an error then the function is not called. This is useful for chaining together multiple function calls that can fail, one after the other, stopping at the first error.

try は、結果の Ok 内に保持されている値に対して結果を返す関数を実行します。結果がエラーの場合はその関数は呼び出されません。これは、失敗する可能性のある複数の関数呼び出しを、最初のエラーで停止して、次々に連鎖させていくのに便利です。

unwrap extracts the success value from a result, or returning a default value if the result is an error.

unwrap は、結果から成功値を取り出します。結果がエラーの場合はデフォルト値を返します。

Result functions are often used with pipelines to chain together multiple calls to result returning functions.

Result 関数は、結果を返す関数への複数の呼び出しを連結するパイプラインでよく使用されます。