# MultiSort
[](https://github.com/grantwest/multi_sort/actions/workflows/ci.yml)
[](https://hex.pm/packages/multi_sort)
[](https://hexdocs.pm/multi_sort/)
[](https://hex.pm/packages/multi_sort)
[](https://opensource.org/licenses/0bsd)
[](https://github.com/grantwest/multi_sort/commits/master)
Easily sort by multiple fields in a readable manner. Inspired by Ecto/SQL order by.
Sort posts first by title and then by descending date:
```elixir
posts
|> MultiSort.by([
{:asc, &1.title}
# Pass Date module as third element because we need to use Date.compare/2 to compare dates
{:desc, &1.date, Date},
])
```
Sort posts first by category according to order list and then by title:
```elixir
post_category_order = [:business, :sports, :politics]
posts
|> MultiSort.by([
{:asc, &1.category, post_category_order},
{:asc, &1.title}
])
```
[See docs](https://hexdocs.pm/multi_sort/MultiSort.html) for more information and examples.