Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
/ natural_order Public archive
forked from BinaryNoggin/natural_order

A Utility for Natural Sort in Elixir

License

Notifications You must be signed in to change notification settings

felt/natural_order

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NaturalOrder

A utility to compare strings in natural sort order.

Natural sort order is useful for humans. By default sorting Strings is a lot differently

Installation

def deps do
  [
    {:natural_order, "~> 0.3.0"}
  ]
end

Usage

To compare two strings directly.

  iex> NaturalOrder.compare("String2", "String11")
  :lt

  iex>  NaturalOrder.compare("String11", "String2")
  :gt

Using Enum.sort/2

   iex> Enum.sort(["String2", "String11", "String3"], NaturalOrder)
   ["String2", "String3",  "String11"]

   iex> Enum.sort(["String2", "String11", "String3"], {:asc, NaturalOrder})
   ["String2", "String3",  "String11"]

   iex> Enum.sort(["String2", "String11", "String3"], {:desc, NaturalOrder})
   ["String11", "String3",  "String2"]

The docs can be found at https://hexdocs.pm/mr_natural.

About

A Utility for Natural Sort in Elixir

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%