Giter Club home page Giter Club logo

ex_deep_sort's Introduction

DeepSort

Build Status Coverage Status hex.pm version hex.pm downloads

A hex module who does recursive sort over any enumerables.

why?

As we all know, different data types in Elixir can be compared using comparison operators so we don't need to worry about different data types in order to sort. The overall sorting order is defined below:

number < atom < reference < function < port < pid < tuple < map < list < bitstring

By this way, Enum.sort can do flat sorting jobs over enumerables. This package steps forward and it does recursive sort over any enumerables.

Examples

iex> DeepSort.sort([4, 2, 3, 1])
[1, 2, 3, 4]

iex> DeepSort.sort([4, 2, 3, 1], &>/2)
[4, 3, 2, 1]

iex> DeepSort.sort([4, 2, [3, 4, 1, 2], 1, "abc", :abc, [b: 1, a: 2, c: ["world", :hello, %{b: 2, a: 1, foo: "bar", baz: 1..5}, "hello", :bar]]])
[
  1,
  2,
  4,
  :abc,
  [1, 2, 3, 4],
  [
    a: 2,
    b: 1,
    c: ["world", :hello, %{a: 1, b: 2, baz: 1..5, foo: "bar"}, "hello", :bar]
  ],
  "abc"
]

iex> DeepSort.sort("AsDfdg") # String is not enumerable in Elixir
"AsDfdg"

iex> DeepSort.sort('AsDfdg') # But Charlist is enumerable
'ADdfgs'

iex> DeepSort.sort({:two, 1, "three"}) # Tuple is not enumerable
{:two, 1, "three"}

iex> DeepSort.sort(%{two: 1, one: 1, "3": "three"}) # However Map is enumerable
["3": "three", one: 1, two: 1]

The function is based on Enum.sort/2 but aims to do a recursive sort over any enumerables.

Docs

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

Installation

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

def deps do
  [
    {:deep_sort, "~> 1.1.1"} # change version to newest
  ]
end

License

MIT

ChangeLog

CHANGELOG

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.