We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent af1ee53 commit 991cc25Copy full SHA for 991cc25
lib/util/helpers.ex
@@ -0,0 +1,24 @@
1
+defmodule Util.Helpers do
2
+ @moduledoc """
3
+ Miscellaneous helpers
4
+ """
5
+
6
+ def non_empty_value_or_default(map, key, default) do
7
+ case Map.get(map, key) do
8
+ val when is_integer(val) and val > 0 -> {:ok, val}
9
+ val when is_binary(val) and val != "" -> {:ok, val}
10
+ val when is_list(val) and length(val) > 0 -> {:ok, val}
11
+ _ -> {:ok, default}
12
+ end
13
14
15
+ def not_empty_string(map, key, error_atom \\ "") do
16
17
+ value when is_binary(value) and value != "" ->
18
+ {:ok, value}
19
+ error_val ->
20
+ "'#{key}' - invalid value: '#{error_val}', it must be a not empty string."
21
+ |> Util.ToTuple.error(error_atom)
22
23
24
+end
0 commit comments