ExShopifySchema.Generator.Graphql.Introspection.Util.Enum (ExShopifySchema v2024.10.3)
View SourceUtility functions for working with enum values.
Summary
Functions
The safe map function is a wrapper around Enum.map that handles nil values gracefully.
Converts a map's keys from camelCase to snake_case recursively.
Converts a string to an existing atom. If the corresponding atom does not exist, it raises an error.
Functions
@spec safe_map(enumerable :: nil, fun :: (term() -> term())) :: []
@spec safe_map(enumerable :: Enumerable.t(element), fun :: (element -> value)) :: [ value ] when value: var
The safe map function is a wrapper around Enum.map that handles nil values gracefully.
Examples
iex> safe_map([1, 2, 3], fn x -> x * 2 end)
[2, 4, 6]
iex> safe_map(nil, fn x -> x * 2 end)
[]
Converts a map's keys from camelCase to snake_case recursively.
Examples
iex> snake_case_keys(%{"camelCaseKey" => "value"})
%{"camel_case_key" => "value"}
iex> snake_case_keys(%{"nestedMap" => %{"anotherKey" => "value"}})
%{"nested_map" => %{"another_key" => "value"}}
iex> snake_case_keys([%{"listItem" => "value"}])
[%{"list_item" => "value"}]
Converts a string to an existing atom. If the corresponding atom does not exist, it raises an error.
Examples
iex> string_to_atom!("code")
:code