LoginSignup
5
2

More than 5 years have passed since last update.

{ :ok, result }をパイプ中で処理するためのモジュール

Last updated at Posted at 2018-01-24

File.open()やTimex.parse()のような、タプルで結果を返す処理をパイプで処理するために、関数パターンマッチで:okや:errorを捉える関数を持つモジュールを用意すると、パイプの途中で止めなくて済む

defmodule Tpl do
    def ok( { :ok, result } ), do: result

    def error( { :error, result } ), do: result

    def both( { :ok, result } ), do: result
    def both( { :error, result } ), do: result
end

both()を使うと、:okと:errorの両方を次に流す

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2