<div align="center">

# `useful`

A collection of useful functions for building `Elixir` Apps.

![GitHub Workflow Status](
[![contributions welcome](](



# Why? 🤷

We found ourselves copy-pasting a few useful "helper" functions
across our Elixir projects ... <br />
it wasn't
so we created this library.

# What? 💭

A library of useful functions that we need for building `Elixir` Apps.

# Who? 👤

This library is for our use on our various `Elixir` / `Phoenix` apps.
As with everything we do it's Open Source, Tested and Documented
so that _anyone_ can benefit from it.

# How? 💻

## Install ⬇️

Install by adding `useful` to your list of dependencies in `mix.exs`:

def deps do
    {:useful, "~> 0.4.0"}

## Function Reference 

### `atomize_map_keys/1`

Converts a `Map` that has strings as keys (or mixed keys)
to have only atom keys. e.g:

# map that has different types of keys:
my_map = %{"name" => "Alex", id: 1}
%{name: Alex, id: 1}

Works recursively for deeply nested maps:

person = %{"name" => "Alex", id: 1, details: %{"age" => 17, height: 185}}
%{name: Alex, id: 1, details: %{age: 17, height: 185}}

### `flatten_map/1`

Flatten a `Map` of any depth/nesting:

iex> map = %{name: "alex", data: %{age: 17, height: 185}}
iex> Useful.flatten_map(map)
%{data__age: 17, data__height: 185, name: "alex"}

**Note**: `flatten_map/1` converts all Map keys to `Atom`
as it's easier to work with atoms as keys
e.g: `map.person__name` instead of `map["person__name"]`.
We use the `__` (_double underscore_)
as the delimiter for the keys of nested maps,
because if we attempt to use `.` (_period character_)
we get an error:

iex(1)> :a.b
** (UndefinedFunctionError) function :a.b/0 is undefined (module :a is not available)

### `stringify_tuple/1`

Stringify a tuple of any length; useful in debugging.

iex> tuple = {:ok, :example}
iex> Useful.stringify_tuple(tuple)
"ok: example"

### `typeof/1`

Returns the type of a variable, e.g: "function" or "integer"
Inspired by 
from `JavaScript` land.

iex> myvar = 42
iex> Useful.typeof(myvar)

<br />

# Docs 📜

Detailed docs available at:

<br />

# Help Us Help You! 🙏 

If you need a specific helper function or utility 
(e.g: something you found useful in a different programming language),
[open an issue](
so that we can all benefit from useful functions.