Current section
Files
Jump to
Current section
Files
lib/yemux/result.ex
defmodule Yemux.Result do
@moduledoc ~S"""
Tools for Result tuples `{:ok|:error, any()}`
"""
@type t :: {:ok | :error, any()}
@doc ~S"""
iex(1)> and_ok({:ok, nil}, fn -> 42 end)
{:ok, 42}
iex(2)> and_ok({:error, 41}, fn -> 42 end)
{:error, 41}
"""
@spec and_ok(t(), any())::t()
def and_ok(result, non_result)
def and_ok({:ok, _}, non_result), do: {:ok, non_result.()}
def and_ok(error, _non_result), do: error
# @doc ~S"""
# iex(3)> unwrap({:ok, 42})
# 42
# iex(4)> unwrap({:error, 41})
# {:error, 41}
# """
# def unwrap(result)
# def unwrap({:ok, value}), do: value
# def unwrap(error), do: error
end
# SPDX-License-Identifier: Apache-2.0