diff --git a/lib/wuunder_utils/map.ex b/lib/wuunder_utils/maps.ex similarity index 81% rename from lib/wuunder_utils/map.ex rename to lib/wuunder_utils/maps.ex index 22a65bc..78a4b54 100644 --- a/lib/wuunder_utils/map.ex +++ b/lib/wuunder_utils/maps.ex @@ -1,8 +1,8 @@ -defmodule WuunderUtils.Map do +defmodule WuunderUtils.Maps do @moduledoc """ Contains a set of helpers to deal with some complex stuff with Maps and Structs """ - alias WuunderUtils.Number + alias WuunderUtils.Numbers alias WuunderUtils.Presence @type map_key() :: atom() | binary() @@ -18,25 +18,25 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.get_field(%{value: 20}, :value) + iex> WuunderUtils.Maps.get_field(%{value: 20}, :value) 20 - iex> WuunderUtils.Map.get_field(%{"value" => 20}, :value) + iex> WuunderUtils.Maps.get_field(%{"value" => 20}, :value) 20 - iex> WuunderUtils.Map.get_field(%{value: 20}, "value") + iex> WuunderUtils.Maps.get_field(%{value: 20}, "value") nil - iex> WuunderUtils.Map.get_field(%{value: 20}, "non-existent") + iex> WuunderUtils.Maps.get_field(%{value: 20}, "non-existent") nil - iex> WuunderUtils.Map.get_field(%{value: 20}, :weight) + iex> WuunderUtils.Maps.get_field(%{value: 20}, :weight) nil - iex> WuunderUtils.Map.get_field(%{value: 20}, :weight, 350) + iex> WuunderUtils.Maps.get_field(%{value: 20}, :weight, 350) 350 - iex> WuunderUtils.Map.get_field(%{value: 20}, "currency", "EUR") + iex> WuunderUtils.Maps.get_field(%{value: 20}, "currency", "EUR") "EUR" """ @@ -65,19 +65,19 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.get_field_as_decimal(%{value: "50"}, :value) + iex> WuunderUtils.Maps.get_field_as_decimal(%{value: "50"}, :value) Decimal.new("50") - iex> WuunderUtils.Map.get_field_as_decimal(%{value: Decimal.new("1337.5")}, :value) + iex> WuunderUtils.Maps.get_field_as_decimal(%{value: Decimal.new("1337.5")}, :value) Decimal.new("1337.5") - iex> WuunderUtils.Map.get_field_as_decimal(%{value: 50}, :value) + iex> WuunderUtils.Maps.get_field_as_decimal(%{value: 50}, :value) Decimal.new("50") - iex> WuunderUtils.Map.get_field_as_decimal(%{value: 50}, :weight) + iex> WuunderUtils.Maps.get_field_as_decimal(%{value: 50}, :weight) Decimal.new("0") - iex> WuunderUtils.Map.get_field_as_decimal(%{value: nil}, :value) + iex> WuunderUtils.Maps.get_field_as_decimal(%{value: nil}, :value) Decimal.new("0") """ @@ -85,7 +85,7 @@ defmodule WuunderUtils.Map do def get_field_as_decimal(map, key) when is_map(map) and is_valid_map_key(key) do map |> get_field(key) - |> Number.to_decimal() + |> Numbers.to_decimal() end @doc """ @@ -98,16 +98,16 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.put_field(%{value: 20}, :weight, 350) + iex> WuunderUtils.Maps.put_field(%{value: 20}, :weight, 350) %{value: 20, weight: 350} - iex> WuunderUtils.Map.put_field(%{value: 20}, "weight", 350) + iex> WuunderUtils.Maps.put_field(%{value: 20}, "weight", 350) %{:value => 20, "weight" => 350} - iex> WuunderUtils.Map.put_field(%{"weight" => 350}, :value, 25) + iex> WuunderUtils.Maps.put_field(%{"weight" => 350}, :value, 25) %{"weight" => 350, "value" => 25} - iex> WuunderUtils.Map.put_field(%{"weight" => 350}, "value", 25) + iex> WuunderUtils.Maps.put_field(%{"weight" => 350}, "value", 25) %{"weight" => 350, "value" => 25} """ @@ -129,16 +129,16 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.delete_field(%{length: 255, weight: 100}, :length) + iex> WuunderUtils.Maps.delete_field(%{length: 255, weight: 100}, :length) %{weight: 100} - iex> WuunderUtils.Map.delete_field(%{length: 255, weight: 100}, "length") + iex> WuunderUtils.Maps.delete_field(%{length: 255, weight: 100}, "length") %{weight: 100, length: 255} - iex> WuunderUtils.Map.delete_field(%{"value" => 50, "currency" => "EUR"}, "currency") + iex> WuunderUtils.Maps.delete_field(%{"value" => 50, "currency" => "EUR"}, "currency") %{"value" => 50} - iex> WuunderUtils.Map.delete_field(%{"value" => 50, "currency" => "EUR"}, :currency) + iex> WuunderUtils.Maps.delete_field(%{"value" => 50, "currency" => "EUR"}, :currency) %{"value" => 50} """ @@ -159,13 +159,13 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.has_only_atom_keys?(%{a: 1, b: 2}) + iex> WuunderUtils.Maps.has_only_atom_keys?(%{a: 1, b: 2}) true - iex> WuunderUtils.Map.has_only_atom_keys?(%{:a => 1, "b" => 2}) + iex> WuunderUtils.Maps.has_only_atom_keys?(%{:a => 1, "b" => 2}) false - iex> WuunderUtils.Map.has_only_atom_keys?(%{"a" => 1, "b" => 2}) + iex> WuunderUtils.Maps.has_only_atom_keys?(%{"a" => 1, "b" => 2}) false """ @@ -183,13 +183,13 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.alias_field(%{country: "NL"}, :country, :country_code) + iex> WuunderUtils.Maps.alias_field(%{country: "NL"}, :country, :country_code) %{country_code: "NL"} - iex> WuunderUtils.Map.alias_field(%{"country" => "NL"}, :country, :country_code) + iex> WuunderUtils.Maps.alias_field(%{"country" => "NL"}, :country, :country_code) %{"country_code" => "NL"} - iex> WuunderUtils.Map.alias_field(%{street_name: "Straatnaam"}, :street, :street_address) + iex> WuunderUtils.Maps.alias_field(%{street_name: "Straatnaam"}, :street, :street_address) %{street_name: "Straatnaam"} """ @@ -213,7 +213,7 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.alias_fields(%{country: "NL", street: "Straat", number: 666}, %{country: :country_code, street: :street_name, number: :house_number}) + iex> WuunderUtils.Maps.alias_fields(%{country: "NL", street: "Straat", number: 666}, %{country: :country_code, street: :street_name, number: :house_number}) %{country_code: "NL", house_number: 666, street_name: "Straat"} """ @@ -235,7 +235,7 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.from_struct(%TestStruct{ + iex> WuunderUtils.Maps.from_struct(%TestStruct{ ...> first_name: "Peter", ...> last_name: "Pan", ...> date_of_birth: ~D[1980-01-02], @@ -253,7 +253,7 @@ defmodule WuunderUtils.Map do country: %{code: "UK"} } - iex> WuunderUtils.Map.from_struct( + iex> WuunderUtils.Maps.from_struct( ...> %TestStruct{ ...> first_name: "Peter", ...> last_name: "Pan", @@ -274,7 +274,7 @@ defmodule WuunderUtils.Map do country: "COUNTRY:UK" } - iex> WuunderUtils.Map.from_struct( + iex> WuunderUtils.Maps.from_struct( ...> %TestStruct{ ...> address: %TestSchema{ ...> street: "Straat", @@ -339,13 +339,13 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.put_when(%{street: "Straat"}, 1 == 1, :number, 13) + iex> WuunderUtils.Maps.put_when(%{street: "Straat"}, 1 == 1, :number, 13) %{number: 13, street: "Straat"} - iex> WuunderUtils.Map.put_when(%{street: "Straat"}, fn -> "value" == "value" end, :number, 13) + iex> WuunderUtils.Maps.put_when(%{street: "Straat"}, fn -> "value" == "value" end, :number, 13) %{number: 13, street: "Straat"} - iex> WuunderUtils.Map.put_when(%{street: "Straat"}, 10 > 20, :number, 13) + iex> WuunderUtils.Maps.put_when(%{street: "Straat"}, 10 > 20, :number, 13) %{street: "Straat"} """ @@ -365,13 +365,13 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.put_if_present(%{street: "Straat"}, :street, "Laan") + iex> WuunderUtils.Maps.put_if_present(%{street: "Straat"}, :street, "Laan") %{street: "Laan"} - iex> WuunderUtils.Map.put_if_present(%{street: "Straat"}, :street, nil) + iex> WuunderUtils.Maps.put_if_present(%{street: "Straat"}, :street, nil) %{street: "Straat"} - iex> WuunderUtils.Map.put_if_present(%{street: "Straat"}, :street, " ") + iex> WuunderUtils.Maps.put_if_present(%{street: "Straat"}, :street, " ") %{street: "Straat"} """ @@ -384,13 +384,13 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.put_if_not_nil(%{street: "Straat"}, :street, "Laan") + iex> WuunderUtils.Maps.put_if_not_nil(%{street: "Straat"}, :street, "Laan") %{street: "Laan"} - iex> WuunderUtils.Map.put_if_not_nil(%{street: "Straat"}, :street, nil) + iex> WuunderUtils.Maps.put_if_not_nil(%{street: "Straat"}, :street, nil) %{street: "Straat"} - iex> WuunderUtils.Map.put_if_not_nil(%{street: "Straat"}, :street, " ") + iex> WuunderUtils.Maps.put_if_not_nil(%{street: "Straat"}, :street, " ") %{street: " "} """ @spec put_if_not_nil(map(), map_key(), any()) :: map() @@ -404,19 +404,19 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.present?(nil) + iex> WuunderUtils.Maps.present?(nil) false - iex> WuunderUtils.Map.present?(%{}) + iex> WuunderUtils.Maps.present?(%{}) false - iex> WuunderUtils.Map.present?(%{a: 1}) + iex> WuunderUtils.Maps.present?(%{a: 1}) true - iex> WuunderUtils.Map.present?(%TestStruct{}) + iex> WuunderUtils.Maps.present?(%TestStruct{}) true - iex> WuunderUtils.Map.present?(%Ecto.Association.NotLoaded{}) + iex> WuunderUtils.Maps.present?(%Ecto.Association.NotLoaded{}) false """ @@ -437,7 +437,7 @@ defmodule WuunderUtils.Map do ## Example - iex> WuunderUtils.Map.flatten_map(%{ + iex> WuunderUtils.Maps.flatten_map(%{ ...> test: "123", ...> order_lines: [ ...> %{sku: "123", description: "test"}, @@ -456,7 +456,7 @@ defmodule WuunderUtils.Map do "meta.data" => "test" } - iex> WuunderUtils.Map.flatten_map( + iex> WuunderUtils.Maps.flatten_map( ...> %{ ...> test: "123", ...> order_lines: [ @@ -521,7 +521,7 @@ defmodule WuunderUtils.Map do ## Examples - iex> WuunderUtils.Map.delete_all( + iex> WuunderUtils.Maps.delete_all( ...> %{ ...> shipment: %{ ...> id: "shipment-id", diff --git a/lib/wuunder_utils/number.ex b/lib/wuunder_utils/numbers.ex similarity index 66% rename from lib/wuunder_utils/number.ex rename to lib/wuunder_utils/numbers.ex index bc03ead..40ef3e4 100644 --- a/lib/wuunder_utils/number.ex +++ b/lib/wuunder_utils/numbers.ex @@ -1,4 +1,4 @@ -defmodule WuunderUtils.Number do +defmodule WuunderUtils.Numbers do @moduledoc """ Helper functions for floats, ints and Decimal's """ @@ -11,22 +11,22 @@ defmodule WuunderUtils.Number do ## Examples - iex> WuunderUtils.Number.parse_int("10005") + iex> WuunderUtils.Numbers.parse_int("10005") 10005 - iex> WuunderUtils.Number.parse_int(10005) + iex> WuunderUtils.Numbers.parse_int(10005) 10005 - iex> WuunderUtils.Number.parse_int(10.5) + iex> WuunderUtils.Numbers.parse_int(10.5) 10.5 - iex> WuunderUtils.Number.parse_int("10.50") + iex> WuunderUtils.Numbers.parse_int("10.50") 10 - iex> WuunderUtils.Number.parse_int("TEST10.50") + iex> WuunderUtils.Numbers.parse_int("TEST10.50") nil - iex> WuunderUtils.Number.parse_int("10TEST2") + iex> WuunderUtils.Numbers.parse_int("10TEST2") 10 """ @@ -50,22 +50,22 @@ defmodule WuunderUtils.Number do ## Examples - iex> WuunderUtils.Number.parse_float("10005") + iex> WuunderUtils.Numbers.parse_float("10005") 10005.0 - iex> WuunderUtils.Number.parse_float(10005) + iex> WuunderUtils.Numbers.parse_float(10005) 10005 - iex> WuunderUtils.Number.parse_float(10.5) + iex> WuunderUtils.Numbers.parse_float(10.5) 10.5 - iex> WuunderUtils.Number.parse_float("10.50") + iex> WuunderUtils.Numbers.parse_float("10.50") 10.5 - iex> WuunderUtils.Number.parse_float("TEST10.50") + iex> WuunderUtils.Numbers.parse_float("TEST10.50") nil - iex> WuunderUtils.Number.parse_float("10TEST2") + iex> WuunderUtils.Numbers.parse_float("10TEST2") 10.0 """ @spec parse_float(any()) :: integer() | float() | nil @@ -86,10 +86,10 @@ defmodule WuunderUtils.Number do ## Examples - iex> WuunderUtils.Number.to_decimal("15") + iex> WuunderUtils.Numbers.to_decimal("15") Decimal.new("15") - iex> WuunderUtils.Number.to_decimal("15") + iex> WuunderUtils.Numbers.to_decimal("15") Decimal.new("15") """ @spec to_decimal(any()) :: Decimal.t() @@ -106,16 +106,16 @@ defmodule WuunderUtils.Number do ## Examples - iex> WuunderUtils.Number.add_decimal(nil, nil) + iex> WuunderUtils.Numbers.add_decimal(nil, nil) Decimal.new("0") - iex> WuunderUtils.Number.add_decimal(nil, Decimal.new("15.5")) + iex> WuunderUtils.Numbers.add_decimal(nil, Decimal.new("15.5")) Decimal.new("15.5") - iex> WuunderUtils.Number.add_decimal(Decimal.new("6.5"), Decimal.new("15.5")) + iex> WuunderUtils.Numbers.add_decimal(Decimal.new("6.5"), Decimal.new("15.5")) Decimal.new("22.0") - iex> WuunderUtils.Number.add_decimal(Decimal.new("15.5"), nil) + iex> WuunderUtils.Numbers.add_decimal(Decimal.new("15.5"), nil) Decimal.new("15.5") """ @@ -131,28 +131,28 @@ defmodule WuunderUtils.Number do ## Examples - iex> WuunderUtils.Number.present?(-1) + iex> WuunderUtils.Numbers.present?(-1) true - iex> WuunderUtils.Number.present?(1) + iex> WuunderUtils.Numbers.present?(1) true - iex> WuunderUtils.Number.present?(Decimal.new("1")) + iex> WuunderUtils.Numbers.present?(Decimal.new("1")) true - iex> WuunderUtils.Number.present?(0.000001) + iex> WuunderUtils.Numbers.present?(0.000001) true - iex> WuunderUtils.Number.present?(0.0) + iex> WuunderUtils.Numbers.present?(0.0) false - iex> WuunderUtils.Number.present?(0) + iex> WuunderUtils.Numbers.present?(0) false - iex> WuunderUtils.Number.present?(Decimal.new("0")) + iex> WuunderUtils.Numbers.present?(Decimal.new("0")) false - iex> WuunderUtils.Number.present?(Decimal.new("0.0")) + iex> WuunderUtils.Numbers.present?(Decimal.new("0.0")) false """ @spec present?(Decimal.t() | number() | nil) :: boolean() diff --git a/lib/wuunder_utils/presence.ex b/lib/wuunder_utils/presence.ex index f4b1315..9341fc1 100644 --- a/lib/wuunder_utils/presence.ex +++ b/lib/wuunder_utils/presence.ex @@ -2,9 +2,9 @@ defmodule WuunderUtils.Presence do @moduledoc """ Acts as proxy module towards present? functions of String and Map """ - alias WuunderUtils.Number - alias WuunderUtils.String - alias WuunderUtils.Map + alias WuunderUtils.Numbers + alias WuunderUtils.Strings + alias WuunderUtils.Maps import Decimal, only: [is_decimal: 1] @@ -39,9 +39,9 @@ defmodule WuunderUtils.Presence do """ @spec present?(t()) :: boolean() - def present?(value) when is_number(value) or is_decimal(value), do: Number.present?(value) - def present?(map) when is_map(map), do: Map.present?(map) - def present?(value) when is_binary(value) or is_nil(value), do: String.present?(value) + def present?(value) when is_number(value) or is_decimal(value), do: Numbers.present?(value) + def present?(map) when is_map(map), do: Maps.present?(map) + def present?(value) when is_binary(value) or is_nil(value), do: Strings.present?(value) def present?([]), do: false def present?([_head | _tail]), do: true diff --git a/lib/wuunder_utils/result.ex b/lib/wuunder_utils/results.ex similarity index 72% rename from lib/wuunder_utils/result.ex rename to lib/wuunder_utils/results.ex index e8a0787..9555f7f 100644 --- a/lib/wuunder_utils/result.ex +++ b/lib/wuunder_utils/results.ex @@ -1,4 +1,4 @@ -defmodule WuunderUtils.Result do +defmodule WuunderUtils.Results do @moduledoc """ A set of handy helpers to deal with {:ok, _} or {:error, _} tuples """ @@ -8,19 +8,19 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.all_ok?([ + iex> WuunderUtils.Results.all_ok?([ ...> {:ok, %Shipment{id: 1}}, ...> {:ok, %Shipment{id: 2}} ...> ]) true - iex> WuunderUtils.Result.all_ok?(:ok) + iex> WuunderUtils.Results.all_ok?(:ok) true - iex> WuunderUtils.Result.all_ok?({:ok, %Shipment{id: 2}}) + iex> WuunderUtils.Results.all_ok?({:ok, %Shipment{id: 2}}) true - iex> WuunderUtils.Result.all_ok?([{:ok, %Shipment{id: 2}}, {:error, %Shipment{id: 3}}]) + iex> WuunderUtils.Results.all_ok?([{:ok, %Shipment{id: 2}}, {:error, %Shipment{id: 3}}]) false """ @@ -34,19 +34,19 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.all_error?([ + iex> WuunderUtils.Results.all_error?([ ...> {:error, %Shipment{id: 1}}, ...> {:error, %Shipment{id: 2}} ...> ]) true - iex> WuunderUtils.Result.all_error?(:error) + iex> WuunderUtils.Results.all_error?(:error) true - iex> WuunderUtils.Result.all_error?({:error, %Shipment{id: 2}}) + iex> WuunderUtils.Results.all_error?({:error, %Shipment{id: 2}}) true - iex> WuunderUtils.Result.all_error?([{:ok, %Shipment{id: 2}}, {:error, %Shipment{id: 3}}]) + iex> WuunderUtils.Results.all_error?([{:ok, %Shipment{id: 2}}, {:error, %Shipment{id: 3}}]) false """ @@ -60,16 +60,16 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.has_ok?(:ok) + iex> WuunderUtils.Results.has_ok?(:ok) true - iex> WuunderUtils.Result.has_ok?({:ok, "hello world"}) + iex> WuunderUtils.Results.has_ok?({:ok, "hello world"}) true - iex> WuunderUtils.Result.has_ok?([{:ok, "hello world"}, {:error, :faulty}]) + iex> WuunderUtils.Results.has_ok?([{:ok, "hello world"}, {:error, :faulty}]) true - iex> WuunderUtils.Result.has_ok?([{:error, "connection lost"}, {:error, :faulty}]) + iex> WuunderUtils.Results.has_ok?([{:error, "connection lost"}, {:error, :faulty}]) false """ @@ -83,7 +83,7 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.has_error?([ + iex> WuunderUtils.Results.has_error?([ ...> {:ok, %Shipment{id: 1}}, ...> {:ok, %Shipment{id: 2}}, ...> {:error, :creation_error}, @@ -91,13 +91,13 @@ defmodule WuunderUtils.Result do ...> ]) true - iex> WuunderUtils.Result.has_error?(:error) + iex> WuunderUtils.Results.has_error?(:error) true - iex> WuunderUtils.Result.has_error?({:error, :creating_error}) + iex> WuunderUtils.Results.has_error?({:error, :creating_error}) true - iex> WuunderUtils.Result.has_error?({:ok, %Shipment{id: 1}}) + iex> WuunderUtils.Results.has_error?({:ok, %Shipment{id: 1}}) false """ @@ -117,7 +117,7 @@ defmodule WuunderUtils.Result do ...> {:error, :creation_error} ...> ] ...> - ...> WuunderUtils.Result.get_error(results) + ...> WuunderUtils.Results.get_error(results) :creation_error """ @@ -148,7 +148,7 @@ defmodule WuunderUtils.Result do ...> {:error, :creation_error} ...> ] ...> - ...> WuunderUtils.Result.get_errors(results) + ...> WuunderUtils.Results.get_errors(results) ["other-error", :creation_error] """ @@ -167,13 +167,13 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.get_error_as_result([{:ok, "value"}, {:error, "something went wrong"}]) + iex> WuunderUtils.Results.get_error_as_result([{:ok, "value"}, {:error, "something went wrong"}]) {:error, "something went wrong"} - iex> WuunderUtils.Result.get_error_as_result({:ok, "value"}) + iex> WuunderUtils.Results.get_error_as_result({:ok, "value"}) nil - iex> WuunderUtils.Result.get_error_as_result("some-value") + iex> WuunderUtils.Results.get_error_as_result("some-value") nil """ @@ -192,10 +192,10 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.get_errors_as_result({:error, "some-value"}) + iex> WuunderUtils.Results.get_errors_as_result({:error, "some-value"}) {:error, ["some-value"]} - iex> WuunderUtils.Result.get_errors_as_result([{:error, "value-1"}, {:error, "value-2"}, {:ok, "value"}]) + iex> WuunderUtils.Results.get_errors_as_result([{:error, "value-1"}, {:error, "value-2"}, {:ok, "value"}]) {:error, ["value-1", "value-2"]} """ @@ -220,7 +220,7 @@ defmodule WuunderUtils.Result do ...> {:error, :creation_error} ...> ] ...> - ...> WuunderUtils.Result.get_ok(results) + ...> WuunderUtils.Results.get_ok(results) %Shipment{id: 1} """ @@ -251,7 +251,7 @@ defmodule WuunderUtils.Result do ...> {:error, :creation_error} ...> ] ...> - ...> WuunderUtils.Result.get_oks(results) + ...> WuunderUtils.Results.get_oks(results) [%Shipment{id: 1}, %Shipment{id: 2}] """ @@ -270,13 +270,13 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.get_ok_as_result({:ok, "some-value"}) + iex> WuunderUtils.Results.get_ok_as_result({:ok, "some-value"}) {:ok, "some-value"} - iex> WuunderUtils.Result.get_ok_as_result([{:ok, "value-1"}, {:error, "error"}, {:ok, "value-2"}]) + iex> WuunderUtils.Results.get_ok_as_result([{:ok, "value-1"}, {:error, "error"}, {:ok, "value-2"}]) {:ok, "value-1"} - iex> WuunderUtils.Result.get_ok_as_result({:error, "value"}) + iex> WuunderUtils.Results.get_ok_as_result({:error, "value"}) nil """ @@ -295,10 +295,10 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.get_oks_or_error_result([{:ok, "value"}, {:ok, "value-2"}, :ok]) + iex> WuunderUtils.Results.get_oks_or_error_result([{:ok, "value"}, {:ok, "value-2"}, :ok]) ["value", "value-2", nil] - iex> WuunderUtils.Result.get_oks_or_error_result([{:ok, "value"}, {:ok, "value-2"}, {:error, "faulty"}]) + iex> WuunderUtils.Results.get_oks_or_error_result([{:ok, "value"}, {:ok, "value-2"}, {:error, "faulty"}]) {:error, "faulty"} """ @@ -320,13 +320,13 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.get_oks_as_result({:ok, "some-value"}) + iex> WuunderUtils.Results.get_oks_as_result({:ok, "some-value"}) {:ok, ["some-value"]} - iex> WuunderUtils.Result.get_oks_as_result([{:ok, "value-1"}, {:ok, "value-2"}]) + iex> WuunderUtils.Results.get_oks_as_result([{:ok, "value-1"}, {:ok, "value-2"}]) {:ok, ["value-1", "value-2"]} - iex> WuunderUtils.Result.get_oks_as_result({:error, "value"}) + iex> WuunderUtils.Results.get_oks_as_result({:error, "value"}) [] """ @@ -346,13 +346,13 @@ defmodule WuunderUtils.Result do ## Example - iex> WuunderUtils.Result.get_as_result([{:ok, "value"}, {:ok, "value-2"}]) + iex> WuunderUtils.Results.get_as_result([{:ok, "value"}, {:ok, "value-2"}]) {:ok, "value"} - iex> WuunderUtils.Result.get_as_result([{:ok, "value"}, {:error, "value-2"}]) + iex> WuunderUtils.Results.get_as_result([{:ok, "value"}, {:error, "value-2"}]) {:error, "value-2"} - iex> WuunderUtils.Result.get_as_result([{:error, "value"}, {:error, "value-2"}]) + iex> WuunderUtils.Results.get_as_result([{:error, "value"}, {:error, "value-2"}]) {:error, "value"} """ @@ -379,7 +379,7 @@ defmodule WuunderUtils.Result do ...> {:error, :creation_error} ...> ] ...> - ...> WuunderUtils.Result.get_success(results) + ...> WuunderUtils.Results.get_success(results) %Shipment{id: 1} """ @@ -411,7 +411,7 @@ defmodule WuunderUtils.Result do ...> {:error, :creation_error} ...> ] ...> - ...> WuunderUtils.Result.get_successes(results) + ...> WuunderUtils.Results.get_successes(results) [%Shipment{id: 1}, %Shipment{id: 2}, %Shipment{id: 3}] """ @@ -429,19 +429,19 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.is_ok?({:ok, "value"}) + iex> WuunderUtils.Results.is_ok?({:ok, "value"}) true - iex> WuunderUtils.Result.is_ok?(:ok) + iex> WuunderUtils.Results.is_ok?(:ok) true - iex> WuunderUtils.Result.is_ok?("some-value") + iex> WuunderUtils.Results.is_ok?("some-value") false - iex> WuunderUtils.Result.is_ok?({:error, "error message"}) + iex> WuunderUtils.Results.is_ok?({:error, "error message"}) false - iex> WuunderUtils.Result.is_ok?([]) + iex> WuunderUtils.Results.is_ok?([]) false """ @@ -460,16 +460,16 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.is_success?({:ok, "value"}) + iex> WuunderUtils.Results.is_success?({:ok, "value"}) true - iex> WuunderUtils.Result.is_success?([]) + iex> WuunderUtils.Results.is_success?([]) true - iex> WuunderUtils.Result.is_success?(nil) + iex> WuunderUtils.Results.is_success?(nil) true - iex> WuunderUtils.Result.is_success?({:error, "error message"}) + iex> WuunderUtils.Results.is_success?({:error, "error message"}) false """ @@ -486,13 +486,13 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.is_error?({:error, "error message"}) + iex> WuunderUtils.Results.is_error?({:error, "error message"}) true - iex> WuunderUtils.Result.is_error?({:ok, "value"}) + iex> WuunderUtils.Results.is_error?({:ok, "value"}) false - iex> WuunderUtils.Result.is_error?([]) + iex> WuunderUtils.Results.is_error?([]) false """ @@ -508,19 +508,19 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.is_result?({:ok, "value"}) + iex> WuunderUtils.Results.is_result?({:ok, "value"}) true - iex> WuunderUtils.Result.is_result?({:error, "value"}) + iex> WuunderUtils.Results.is_result?({:error, "value"}) true - iex> WuunderUtils.Result.is_result?(:ok) + iex> WuunderUtils.Results.is_result?(:ok) true - iex> WuunderUtils.Result.is_result?(:error) + iex> WuunderUtils.Results.is_result?(:error) true - iex> WuunderUtils.Result.is_result?("value") + iex> WuunderUtils.Results.is_result?("value") false """ @@ -532,19 +532,19 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.get_result_code({:ok, "value"}) + iex> WuunderUtils.Results.get_result_code({:ok, "value"}) :ok - iex> WuunderUtils.Result.get_result_code(:ok) + iex> WuunderUtils.Results.get_result_code(:ok) :ok - iex> WuunderUtils.Result.get_result_code({:error, "value", "whatever"}) + iex> WuunderUtils.Results.get_result_code({:error, "value", "whatever"}) :error - iex> WuunderUtils.Result.get_result_code(:error) + iex> WuunderUtils.Results.get_result_code(:error) :error - iex> WuunderUtils.Result.get_result_code("value") + iex> WuunderUtils.Results.get_result_code("value") nil """ @@ -565,25 +565,25 @@ defmodule WuunderUtils.Result do ## Examples - iex> WuunderUtils.Result.get_result_value({:ok, "value-1"}) + iex> WuunderUtils.Results.get_result_value({:ok, "value-1"}) "value-1" - iex> WuunderUtils.Result.get_result_value({:ok, "value-1", "value-2"}) + iex> WuunderUtils.Results.get_result_value({:ok, "value-1", "value-2"}) {"value-1", "value-2"} - iex> WuunderUtils.Result.get_result_value({:error, :internal_server_error}) + iex> WuunderUtils.Results.get_result_value({:error, :internal_server_error}) :internal_server_error - iex> WuunderUtils.Result.get_result_value({:error, :error_a, :error_b, :error_c}) + iex> WuunderUtils.Results.get_result_value({:error, :error_a, :error_b, :error_c}) {:error_a, :error_b, :error_c} - iex> WuunderUtils.Result.get_result_value("any-value") + iex> WuunderUtils.Results.get_result_value("any-value") "any-value" - iex> WuunderUtils.Result.get_result_value(:ok) + iex> WuunderUtils.Results.get_result_value(:ok) nil - iex> WuunderUtils.Result.get_result_value(:error) + iex> WuunderUtils.Results.get_result_value(:error) nil """ @@ -626,7 +626,7 @@ defmodule WuunderUtils.Result do ...> nil ...> ] ...> - ...> WuunderUtils.Result.get_success_values(results) + ...> WuunderUtils.Results.get_success_values(results) ["value1", nil, {"value2", "value3"}, {"value4", "value5"}, nil] """ diff --git a/lib/wuunder_utils/string.ex b/lib/wuunder_utils/strings.ex similarity index 70% rename from lib/wuunder_utils/string.ex rename to lib/wuunder_utils/strings.ex index a4b85dd..55c1acf 100644 --- a/lib/wuunder_utils/string.ex +++ b/lib/wuunder_utils/strings.ex @@ -1,4 +1,4 @@ -defmodule WuunderUtils.String do +defmodule WuunderUtils.Strings do @moduledoc """ Contains a set of String helpers """ @@ -10,16 +10,16 @@ defmodule WuunderUtils.String do ## Examples - iex> WuunderUtils.String.uuid?("") + iex> WuunderUtils.Strings.uuid?("") false - iex> WuunderUtils.String.uuid?("39169cb3-03ea") + iex> WuunderUtils.Strings.uuid?("39169cb3-03ea") false - iex> WuunderUtils.String.uuid?("39169CB3-03EA-47E5-9B3C-BD4C53E7FE3F") + iex> WuunderUtils.Strings.uuid?("39169CB3-03EA-47E5-9B3C-BD4C53E7FE3F") true - iex> WuunderUtils.String.uuid?("39169cb3-03ea-47e5-9b3c-bd4c53e7fe3f") + iex> WuunderUtils.Strings.uuid?("39169cb3-03ea-47e5-9b3c-bd4c53e7fe3f") true """ @@ -33,10 +33,10 @@ defmodule WuunderUtils.String do ## Examples - iex> WuunderUtils.String.capitalize("this is sparta!") + iex> WuunderUtils.Strings.capitalize("this is sparta!") "This Is Sparta!" - iex> WuunderUtils.String.capitalize("is this spArTA?") + iex> WuunderUtils.Strings.capitalize("is this spArTA?") "Is This Sparta?" """ @@ -54,13 +54,13 @@ defmodule WuunderUtils.String do ## Examples - iex> WuunderUtils.String.empty?(nil) + iex> WuunderUtils.Strings.empty?(nil) true - iex> WuunderUtils.String.empty?(" ") + iex> WuunderUtils.Strings.empty?(" ") true - iex> WuunderUtils.String.empty?("a string") + iex> WuunderUtils.Strings.empty?("a string") false """ @@ -73,13 +73,13 @@ defmodule WuunderUtils.String do ## Examples - iex> WuunderUtils.String.present?(" ") + iex> WuunderUtils.Strings.present?(" ") false - iex> WuunderUtils.String.present?(nil) + iex> WuunderUtils.Strings.present?(nil) false - iex> WuunderUtils.String.present?("yes") + iex> WuunderUtils.Strings.present?("yes") true """ @@ -91,16 +91,16 @@ defmodule WuunderUtils.String do ## Examples - iex> WuunderUtils.String.empty_to_nil(nil) + iex> WuunderUtils.Strings.empty_to_nil(nil) nil - iex> WuunderUtils.String.empty_to_nil("") + iex> WuunderUtils.Strings.empty_to_nil("") nil - iex> WuunderUtils.String.empty_to_nil(" ") + iex> WuunderUtils.Strings.empty_to_nil(" ") nil - iex> WuunderUtils.String.empty_to_nil("this_is_a_string") + iex> WuunderUtils.Strings.empty_to_nil("this_is_a_string") "this_is_a_string" """ @spec empty_to_nil(String.t() | nil) :: nil | String.t() @@ -117,7 +117,7 @@ defmodule WuunderUtils.String do ## Examples - iex> WuunderUtils.String.clean(" well this is a sentence") + iex> WuunderUtils.Strings.clean(" well this is a sentence") "well this is a sentence" """ @@ -137,10 +137,10 @@ defmodule WuunderUtils.String do ## Examples - iex> WuunderUtils.String.as_string("this is a string") + iex> WuunderUtils.Strings.as_string("this is a string") "this is a string" - iex> WuunderUtils.String.as_string(%{a: 10}) + iex> WuunderUtils.Strings.as_string(%{a: 10}) "%{a: 10}" """ @@ -155,10 +155,10 @@ defmodule WuunderUtils.String do ## Examples - iex> WuunderUtils.String.truncate("this is a long string", 30) + iex> WuunderUtils.Strings.truncate("this is a long string", 30) "this is a long string" - iex> WuunderUtils.String.truncate("this is a long string", 10) + iex> WuunderUtils.Strings.truncate("this is a long string", 10) "this is ..." """ @spec truncate(String.t(), integer()) :: String.t() diff --git a/test/wuunder_utils/map_test.exs b/test/wuunder_utils/maps_test.exs similarity index 89% rename from test/wuunder_utils/map_test.exs rename to test/wuunder_utils/maps_test.exs index 1d4377b..d88b2a7 100644 --- a/test/wuunder_utils/map_test.exs +++ b/test/wuunder_utils/maps_test.exs @@ -1,4 +1,4 @@ -defmodule WuunderUtils.MapTest do +defmodule WuunderUtils.MapsTest do use ExUnit.Case defmodule TestStruct do @@ -26,5 +26,5 @@ defmodule WuunderUtils.MapTest do end end - doctest WuunderUtils.Map + doctest WuunderUtils.Maps end diff --git a/test/wuunder_utils/number_test.exs b/test/wuunder_utils/number_test.exs deleted file mode 100644 index 0eba821..0000000 --- a/test/wuunder_utils/number_test.exs +++ /dev/null @@ -1,4 +0,0 @@ -defmodule WuunderUtils.NumberTest do - use ExUnit.Case - doctest WuunderUtils.Number -end diff --git a/test/wuunder_utils/numbers_test.exs b/test/wuunder_utils/numbers_test.exs new file mode 100644 index 0000000..10210b8 --- /dev/null +++ b/test/wuunder_utils/numbers_test.exs @@ -0,0 +1,4 @@ +defmodule WuunderUtils.NumbersTest do + use ExUnit.Case + doctest WuunderUtils.Numbers +end diff --git a/test/wuunder_utils/result_test.exs b/test/wuunder_utils/results_test.exs similarity index 68% rename from test/wuunder_utils/result_test.exs rename to test/wuunder_utils/results_test.exs index b5c5d12..6d3e5c3 100644 --- a/test/wuunder_utils/result_test.exs +++ b/test/wuunder_utils/results_test.exs @@ -1,4 +1,4 @@ -defmodule WuunderUtils.ResultTest do +defmodule WuunderUtils.ResultsTest do use ExUnit.Case defmodule Shipment do @@ -9,5 +9,5 @@ defmodule WuunderUtils.ResultTest do end end - doctest WuunderUtils.Result + doctest WuunderUtils.Results end diff --git a/test/wuunder_utils/string_test.exs b/test/wuunder_utils/string_test.exs deleted file mode 100644 index af338a1..0000000 --- a/test/wuunder_utils/string_test.exs +++ /dev/null @@ -1,4 +0,0 @@ -defmodule WuunderUtils.StringTest do - use ExUnit.Case - doctest WuunderUtils.String -end diff --git a/test/wuunder_utils/strings_test.exs b/test/wuunder_utils/strings_test.exs new file mode 100644 index 0000000..bf60df4 --- /dev/null +++ b/test/wuunder_utils/strings_test.exs @@ -0,0 +1,4 @@ +defmodule WuunderUtils.StringsTest do + use ExUnit.Case + doctest WuunderUtils.Strings +end