{"id":22409068,"url":"https://github.com/typeclasses/assoc-list","last_synced_at":"2025-07-31T20:31:07.139Z","repository":{"id":33021607,"uuid":"149844269","full_name":"typeclasses/assoc-list","owner":"typeclasses","description":"An association list conceptually signifies a mapping, but is represented as a list (of key-value pairs)","archived":false,"fork":false,"pushed_at":"2022-03-14T20:13:11.000Z","size":72,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-28T14:09:53.479Z","etag":null,"topics":["association-list","haskell","haskell-library"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/assoc-list","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/typeclasses.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-22T04:11:44.000Z","updated_at":"2023-01-11T01:54:24.000Z","dependencies_parsed_at":"2022-08-07T19:30:24.625Z","dependency_job_id":null,"html_url":"https://github.com/typeclasses/assoc-list","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeclasses%2Fassoc-list","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeclasses%2Fassoc-list/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeclasses%2Fassoc-list/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeclasses%2Fassoc-list/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typeclasses","download_url":"https://codeload.github.com/typeclasses/assoc-list/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228295618,"owners_count":17897596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["association-list","haskell","haskell-library"],"created_at":"2024-12-05T12:06:30.450Z","updated_at":"2024-12-05T12:06:31.224Z","avatar_url":"https://github.com/typeclasses.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Association lists\n\nAn *association list* is a simple representation of a key-value mapping as a list of key-value pairs. The `assoc-list` package provides functions for working with these kinds of data structures.\n\n## Use case\n\nWe usually prefer to use [`Map`](https://hackage.haskell.org/package/containers) or [`HashMap`](https://hackage.haskell.org/package/unordered-containers) to represent finite mappings, because they have better performance characteristics and enforce the often-desirable requirement that each key be mapped to at most one value. But some use cases call for preserving the list-like aspect of data that has the semantics of a mapping.\n\nFor example, take the list of [header fields in an HTTP message](https://tools.ietf.org/html/rfc7230#section-3.2). Each header field is a key-value pair (the key is called the *field name*). Some field names may appear at most once among a message's header fields; others may appear repeatedly. The ordering of the header fields is significant only when a field name appears repeatedly.\n\nWhat data structure should we use to represent a collection of header fields? Since we often need to perform lookups by field name, we might consider `Map String [String]` (where the field names have been normalized to all upper or lower case, since HTTP field names are case-insensitive). If we are only *consuming* HTTP messages, this might be suitable. But what if we are writing a proxy server that consumes a request, makes some modifications to the header fields, then forwards the modified message to another server? We would have to convert the client's list of header fields to a [`Map`](https://hackage.haskell.org/package/containers), perform the manipulations on the `Map`, and then convert back to a list. In the process, we lose the original ordering of the lists, as well as the capitalization of the field names. This does not affect the semantics of the message, but may nevertheless be an undesirable side effect. If we do not want this to happen, then we can keep the data in list format. But we need `Map`-like operations over it, which is where the `assoc-list` library comes in.\n\n## Packages\n\nThis project consists of two packages whose contents are nearly the same:\n\n* [`assoc-list`](http://hackage.haskell.org/package/assoc-list)\n  * Defines an association list as `[(a, b)]`\n  * Module names take the form `Data.AssocList.List.[___]`\n* [`assoc-listlike`](http://hackage.haskell.org/package/assoc-listlike)\n  * Defines an association list more generally as [`ListLike`](https://hackage.haskell.org/package/ListLike)` l (a, b) =\u003e l`\n  * A concrete type for `AssocList a b` can be something like [`Seq`](https://hackage.haskell.org/package/containers)` (a, b)`\n  * Module names take the form `Data.AssocList.ListLike.[___]`\n\nFor example, compare the following two type signatures for `mapFirst`:\n\n* `Data.AssocList.List.Eq.mapFirst :: Eq a =\u003e a -\u003e (b -\u003e b) -\u003e [(a, b)] -\u003e [(a, b)]`\n* `Data.AssocList.ListLike.Eq.mapFirst :: (ListLike l (a, b), Eq a) =\u003e a -\u003e (b -\u003e b) -\u003e l -\u003e l`\n\n## Modules\n\n* `Data.AssocList.[___].Concept`\n  * Introduces foundational concepts\n  * For example, the definition of the `AssocList` type\n* `Data.AssocList.[___].Eq`\n  * Functions that involve `Eq` constraints on the keys\n  * For example, `lookupFirst :: Eq a =\u003e a -\u003e AssocList a b -\u003e Maybe b`\n* `Data.AssocList.[___].Equivalence`\n  * Most of the same functions as the `Eq` module, but with an `Equivalence` parameter instead of an `Eq` constraint\n  * For example, `lookupFirst :: Equivalence a -\u003e a -\u003e AssocList a b -\u003e Maybe b`\n  * An example use case for this module might be the list of [header fields in an HTTP message](https://tools.ietf.org/html/rfc7230#section-3.2), which is an association list where the keys are case-insensitive\n* `Data.AssocList.[___].Predicate`\n  * Most of the same functions as the `Eq` module, but specifying keys using a `Predicate` rather than a particular key\n  * For example, `lookupFirst :: Predicate a -\u003e AssocList a b -\u003e Maybe b`\n* `Data.AssocList.[___].Ord`\n  * Functions that involve `Ord` constraints on the keys\n  * For example, `sortKeys :: Ord a =\u003e AssocList a b -\u003e AssocList a b`\n* `Data.AssocList.[___].Comparison`\n  * The same functions as the `Ord` module, but with a `Comparison` parameter instead of an `Ord` constraint\n  * For example, `sortKeys :: Comparison a -\u003e AssocList a b -\u003e AssocList a b`\n\n## Related libraries\n\n* The `base` package has some very limited support for association lists:\n  * [`Data.List.lookup`](https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-List.html#v:lookup)` :: Eq a =\u003e a -\u003e [(a, b)] -\u003e Maybe b`.\n* The `hxt` (Haskell XML Toolbox) package defines a handful of functions in its [`Data.AssocList`](https://hackage.haskell.org/package/hxt-9.3.1.16/docs/Data-AssocList.html) module.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypeclasses%2Fassoc-list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypeclasses%2Fassoc-list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypeclasses%2Fassoc-list/lists"}