Skip to content

Sort by multiple fields in a readable manner. Inspired by Ecto/SQL order by.

License

Notifications You must be signed in to change notification settings

grantwest/multi_sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MultiSort

Build Status Version Hex Docs Download License Last Updated

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:

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:

post_category_order = [:business, :sports, :politics]
posts
|> MultiSort.by([
    {:asc, &1.category, post_category_order},
    {:asc, &1.title}
])

See docs for more information and examples.

About

Sort by multiple fields in a readable manner. Inspired by Ecto/SQL order by.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages