y0hy0h/ordered-containers/2.0.3

Renamed to j-maas/ordered-containers. That is where the repository lives now. It has not been published as a package under the new name.

Versions published as y0hy0h/ordered-containers still install under that name. 5 versions of 5 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/j-maas/ordered-containers.

What we checked: The repo moved to github.com/j-maas/ordered-containers. Rebuilt with git archive from commit 2b7146399632 of https://github.com/j-maas/ordered-containers (zip prefix y0hy0h-ordered-containers-2b71463/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 2e4a9562f73c2fcc187ffb427a0cb255268373d7.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/y0hy0h/ordered-containers/zipball/2.0.3/

ordered-containers (deprecated)

build status elm package Passively maintained

Attention! This package is deprecated, use j-maas/elm-ordered-containers instead!

I renamed my GitHub account to be easier to spell and unfortunately this means that this Elm package also has to be renamed.

OrderedDict and OrderedSet that remember the order of insertion.

The default implementations, Dict and Set, do not keep track of their item's ordering. OrderedDict or OrderedSet, by contrast, will respect the insertion order when converting them to a List or iterating over their items (using foldlOrderedDict.foldl, foldrOrderedDict.foldr, or partitionOrderedDict.partition).

Examples

import OrderedSet
import Set

-- Remembers insertion order
OrderedSet.empty
    |> OrderedSet.insert 2
    |> OrderedSet.insert 1
    |> OrderedSet.insert 3
    |> OrderedSet.toList
--> [ 2, 1, 3 ]

-- Orders by keys
Set.empty
    |> Set.insert 2
    |> Set.insert 1
    |> Set.insert 3
    |> Set.toList
--> [ 1, 2, 3 ]
import Dict
import OrderedDict

-- Remembers insertion order
OrderedDict.empty
    |> OrderedDict.insert 3 "first"
    |> OrderedDict.insert 1 "second"
    |> OrderedDict.insert 2 "third"
    |> OrderedDict.toList
--> [ ( 3, "first" ), ( 1, "second" ), ( 2, "third" ) ]

-- Orders by keys
Dict.empty
    |> Dict.insert 3 "first"
    |> Dict.insert 1 "second"
    |> Dict.insert 2 "third"
    |> Dict.toList
--> [ ( 1, "second" ), ( 2, "third" ), ( 3, "first") ]

Comparison to Dict and Set

The API purposely includes all functions from the regular Dict and Set with the exception for the "Combine" functions (e.g., unionDict.union, diffDict.diff, etc.). Those are left out, because combining ordered collections does not have a single obvious solution. You can always write custom combination functions for your use case!

In addition to the regular API there is a method for efficiently converting back to a regular collection, namely OrderedDict.toDict and OrderedSet.toSet.

How it works

The OrderedDict, in addition to a plain Dict, keeps a List of all the keys in the order they are inserted.

This means that we sacrifice some space, but get the performance of Dict for its "Query" operations, while only introducing minor overhead to the rest.

As an alternative, pzp1997/assoc-list stores only a list while providing a Dict-like interface.

History and contributors

Originally, this package was based on rnon's ordered-containers and updated for Elm 0.19. Later, it was merged with wittjosiah's elm-ordered-dict and rewritten to handle re-insertion in a clearly documented way.

Maintenance

This project is passively maintened. I intend to respond to issues and pull requests, but am not dedicating time to develop new features.