Skip to content

prodis/miss-elixir

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Miss Elixir

Some functions that I miss in Elixir standard library (and maybe you too).

Miss Elixir


Hex.pm Docs Build Status Coverage Status License

Miss Elixir library brings in a non-intrusive way some extra functions that, for different reasons, are not part of the Elixir standard library.

None of the functions in Miss Elixir has the same name of functions present in the correspondent Elixir module.

Read about the motivation to create this Elixir library in this blog post.

Installation

The package can be installed by adding miss to your list of dependencies in mix.exs:

def deps do
  [
    {:miss, "~> 0.1.5"}
  ]
end

Usage

The order of the Miss namespace preceding the existing Elixir modules to be extended was made by intention. For example, Miss.String.

The modules in Miss Elixir are not intended to be used with aliases. Always use the entire namespace to make explicit that module/function does not belong to Elixir standard library.

# Do not do that!
alias Miss.Kernel
Kernel.div_rem(10, 2)

# Instead, use like that:
Miss.Kernel.div_rem(10, 2)

Navigate in the documentation of each module to find out all the available functions and detailed examples.

Below there are some examples.

String

iex> Miss.String.build(["string", 123, true])
"string123true"

iex> Miss.String.build("What ", "do you", " miss?")
"What do you miss?"

Map

iex> Miss.Map.rename_key(%{a: 1, b: 2, c: 3}, :b, :bbb)
%{a: 1, bbb: 2, c: 3}

iex> defmodule Post do
...>   defstruct [:title, :text, :date, :author, comments: []]
...>  end
...>
...>  defmodule Author do
...>    defstruct [:id, :name]
...>  end
...>
...>  defmodule Comment do
...>    defstruct [:text]
...>  end
...>
...> post = %Post{
...>   title: "My post",
...>   text: "Something really interesting",
...>   date: ~D[2010-09-01],
...>   author: %Author{
...>     id: 1234,
...>     name: "Pedro Bonamides"
...>   },
...>   comments: [
...>     %Comment{text: "Comment one"},
...>     %Comment{text: "Comment two"}
...>   ]
...> }
...> Miss.Map.from_nested_struct(post, [{Date, :skip}])
%{
  title: "My post",
  text: "Something really interesting",
  date: ~D[2010-09-01],
  author: %{
    id: 1234,
    name: "Pedro Bonamides"
  },
  comments: [
    %{text: "Comment one"},
    %{text: "Comment two"}
  ]
}

Kernel

iex> Miss.Kernel.div_rem(45, 2)
{22, 1}

iex> defmodule User do
...>   defstruct name: "User"
...> end
...>
...> Miss.Kernel.struct_list(User, [%{name: "Akira"}, %{name: "Fernando"}])
[%User{name: "Akira"}, %User{name: "Fernando"}]

List

iex> Miss.List.intersection([1, 2, 3, 4, 5], [0, 2, 4, 6, 8])
[2, 4]

Full documentation

The full documentation is available at https://hexdocs.pm/miss.

Contributing

See the contributing guide.

License

Miss Elixir is released under the Apache 2.0 License. See the LICENSE file.

Copyright © 2020-2021 Fernando Hamasaki de Amorim

Author

Fernando Hamasaki de Amorim (prodis)

Prodis

About

Some functions that I miss in Elixir standard library (and maybe you too).

Topics

Resources

License

Stars

Watchers

Forks