Current section

7 Versions

Jump to

Compare versions

4 files changed
+40 additions
-5 deletions
  @@ -1,16 +1,16 @@
1 1 {<<"links">>,
2 2 [{<<"GitHub">>,<<"https://github.com/RobertDober/ex_aequo_base">>}]}.
3 3 {<<"name">>,<<"ex_aequo_base">>}.
4 - {<<"version">>,<<"0.1.2">>}.
4 + {<<"version">>,<<"0.1.3">>}.
5 5 {<<"description">>,<<"Elixir code I use all over my places">>}.
6 6 {<<"elixir">>,<<"~> 1.17">>}.
7 7 {<<"app">>,<<"ex_aequo_base">>}.
8 8 {<<"files">>,
9 9 [<<"lib">>,<<"lib/ex_aequo_base">>,<<"lib/ex_aequo_base/io.ex">>,
10 10 <<"lib/ex_aequo_base/types.ex">>,<<"lib/ex_aequo_base/enum.ex">>,
11 - <<"lib/ex_aequo_base/text">>,<<"lib/ex_aequo_base/text/error.ex">>,
12 - <<"lib/ex_aequo_base/text.ex">>,<<"lib/ex_aequo_base.ex">>,<<"mix.exs">>,
13 - <<"README.md">>,<<"LICENSE">>]}.
11 + <<"lib/ex_aequo_base/fn.ex">>,<<"lib/ex_aequo_base/text">>,
12 + <<"lib/ex_aequo_base/text/error.ex">>,<<"lib/ex_aequo_base/text.ex">>,
13 + <<"lib/ex_aequo_base.ex">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE">>]}.
14 14 {<<"licenses">>,[<<"AGPL-3.0-or-later">>]}.
15 15 {<<"requirements">>,[]}.
16 16 {<<"build_tools">>,[<<"mix">>]}.
  @@ -0,0 +1,32 @@
1 + defmodule ExAequoBase.Fn do
2 + use ExAequoBase.Types
3 + @moduledoc ~S"""
4 + Functional Helpers
5 + """
6 +
7 + @doc ~S"""
8 + Runs the first function that does not return nil
9 +
10 + iex(1)> fns = [
11 + ...(1)> fn -> nil end,
12 + ...(1)> fn -> 42 end,
13 + ...(1)> fn -> "not reached" end
14 + ...(1)> ]
15 + ...(1)> select(fns)
16 + 42
17 +
18 + """
19 + @spec select(list(zero_fn_t())) :: any()
20 + def select(functions)
21 + def select([]) do
22 + {:error, "No functions matched"}
23 + end
24 + def select([f|fs]) do
25 + case f.() do
26 + nil -> select(fs)
27 + result -> result
28 + end
29 + end
30 +
31 + end
32 + # SPDX-License-Identifier: AGPL-3.0-or-later
  @@ -32,6 +32,9 @@ defmodule ExAequoBase.Types do
32 32 @type result_t(t) :: either(t, binary())
33 33
34 34 @type stream_t :: %IO.Stream{} | %File.Stream{}
35 +
36 + @type zero_fn_t :: (-> any())
37 + @type zero_fn_t(t) :: (-> t )
35 38 end
36 39 end
  @@ -1,6 +1,6 @@
1 1 defmodule ExAequoBase.MixProject do
2 2 use Mix.Project
3 - @version "0.1.2"
3 + @version "0.1.3"
4 4 @url "https://github.com/RobertDober/ex_aequo_base"
5 5
6 6 def project do