git.iko.soy/rowtype-yoga/purescript-unique
on master help sign in
.editorconfignew file+13
since splitsnapshots
unifiedsplit
@@ -0,0 +1,13 @@
1+# https://editorconfig.org
2+root = true
3+
4+[*]
5+indent_style = space
6+indent_size = 2
7+end_of_line = lf
8+charset = utf-8
9+trim_trailing_whitespace = true
10+insert_final_newline = true
11+
12+[*.md]
13+trim_trailing_whitespace = false
.eslintrc.jsondeleted−28
@@ -1,28 +0,0 @@
1−{
2− "parserOptions": {
3− "ecmaVersion": 5
4− },
5− "extends": "eslint:recommended",
6− "env": {
7− "commonjs": true
8− },
9− "rules": {
10− "strict": [2, "global"],
11− "block-scoped-var": 2,
12− "consistent-return": 2,
13− "eqeqeq": [2, "smart"],
14− "guard-for-in": 2,
15− "no-caller": 2,
16− "no-extend-native": 2,
17− "no-loop-func": 2,
18− "no-new": 2,
19− "no-param-reassign": 2,
20− "no-return-assign": 2,
21− "no-unused-expressions": 2,
22− "no-use-before-define": 2,
23− "radix": [2, "always"],
24− "indent": [2, 2, { "SwitchCase": 1 }],
25− "quotes": [2, "double"],
26− "semi": [2, "always"]
27− }
28−}
.github/ISSUE_TEMPLATE/bug-report.mdnew file+23
@@ -0,0 +1,23 @@
1+---
2+name: Bug report
3+about: Report an issue
4+title: ""
5+labels: bug
6+assignees: ""
7+---
8+
9+**Describe the bug**
10+
11+A clear and concise description of the bug.
12+
13+**To Reproduce**
14+
15+A minimal code example (preferably a runnable example on [Try PureScript](https://try.purescript.org)!) or steps to reproduce the issue.
16+
17+**Expected behavior**
18+
19+A clear and concise description of what you expected to happen.
20+
21+**Additional context**
22+
23+Add any other context about the problem here.
.github/ISSUE_TEMPLATE/change-request.mdnew file+24
@@ -0,0 +1,24 @@
1+---
2+name: Change request
3+about: Propose an improvement to this library
4+title: ""
5+labels: ""
6+assignees: ""
7+---
8+
9+**Is your change request related to a problem? Please describe.**
10+
11+A clear and concise description of the problem.
12+
13+Examples:
14+
15+- It's frustrating to have to [...]
16+- I was looking for a function to [...]
17+
18+**Describe the solution you'd like**
19+
20+A clear and concise description of what a good solution to you looks like, including any solutions you've already considered.
21+
22+**Additional context**
23+
24+Add any other context about the change request here.
.github/ISSUE_TEMPLATE/config.ymlnew file+8
@@ -0,0 +1,8 @@
1+blank_issues_enabled: false
2+contact_links:
3+ - name: PureScript Discourse
4+ url: https://discourse.purescript.org/
5+ about: Ask and answer questions on the PureScript discussion forum.
6+ - name: PureScript Discord
7+ url: https://purescript.org/chat
8+ about: Ask and answer questions on the PureScript chat.
.github/PULL_REQUEST_TEMPLATE.mdnew file+12
@@ -0,0 +1,12 @@
1+**Description of the change**
2+
3+Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR.
4+
5+---
6+
7+**Checklist:**
8+
9+- [ ] Added the change to the changelog's "Unreleased" section with a link to this PR and your username
10+- [ ] Linked any existing issues or proposals that this pull request should close
11+- [ ] Updated or added relevant documentation in the README and/or documentation directory
12+- [ ] Added a test for the contribution (if applicable)
.gitignore+9−13
@@ -1,13 +1,9 @@
1+.*
1−!/.gitignore
2+!.gitignore
2−!/.eslintrc.json
3+!.github
3−!/.travis.yml
4+!.editorconfig
4−/bower_components/
5+!.tidyrc.json
5−/node_modules/
6+
6−/.pulp-cache/
7−/output/
7+output
8−/generated-docs/
8+generated-docs
9−/.psc-package/
9+bower_components
10−/.psc*
11−/.purs*
12−/.psa*
13−/.spago
CHANGELOG.mdnew file+80
@@ -0,0 +1,80 @@
1+# Changelog
2+
3+Notable changes are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4+
5+## [Unreleased]
6+
7+Breaking changes:
8+
9+New features:
10+
11+Bugfixes:
12+
13+Other improvements:
14+- Updated the project for its new home in the Rowtype Yoga organization. ([50e18df](https://github.com/rowtype-yoga/purescript-unique/commit/50e18dfe14082186abc103b3c969343cf998cad0) by @nsaunders)
15+
16+## [0.6.1] - 2023-03-18
17+
18+New features:
19+- Added `hashUnique` function. (#4 by @nsaunders)
20+
21+Other improvements:
22+- Changed `Unique`'s runtime representation to a [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt). (#4 by @nsaunders)
23+- Updated the project to the standards of the [purescript-contrib](https://github.com/purescript-contrib) organization. ([8ec352b](https://github.com/rowtype-yoga/purescript-unique/commit/8ec352ba1f7076c57c776872c2bc8ce7eb530e44) by @nsaunders)
24+
25+## [0.6.0] - 2023-03-02
26+
27+Breaking changes:
28+- Updated to v0.15 of the compiler, dropping support for previous versions. ([7999c18](https://github.com/rowtype-yoga/purescript-unique/commit/7999c1815adeb9011124c7d54902b55f18c8f295) by @nsaunders)
29+
30+## [0.5.1] - 2023-03-02
31+
32+Other improvements:
33+- Added `purs.json` file to facilitate package name transfer. ([4c40891](https://github.com/rowtype-yoga/purescript-unique/commit/4c40891f563c3e5f212fe3b0cef4c0c28dd917b8) by @nsaunders)
34+- Added `LICENSE` file, determined from `bower.json`. ([2f3305c](https://github.com/rowtype-yoga/purescript-unique/commit/2f3305cb511e6c270c25d53e6ebaaf3c193646ae) by @nsaunders)
35+
36+## [0.5.0] - 2017-04-26
37+
38+Breaking changes:
39+- Updated to v0.11 of the compiler, dropping support for previous versions. ([33214fa](https://github.com/rowtype-yoga/purescript-unique/commit/33214faf821843aad95a019ad0a4a28d2b305189) by @mechairoi)
40+
41+## [0.4.0] - 2017-01-06
42+
43+Other improvements:
44+- Updated dependencies. ([03a24af](https://github.com/rowtype-yoga/purescript-unique/commit/03a24af23dd9a64e08ff8a9f8d119437d2d9cf44) by @mechairoi)
45+
46+## [0.3.0] - 2016-06-28
47+
48+Breaking changes:
49+- Updated to v0.9 of the compiler, dropping support for previous versions. ([3a58d82](https://github.com/rowtype-yoga/purescript-unique/commit/3a58d82f1d9b5942cc29f3a31979a10978797204) by @mechairoi)
50+
51+## [0.2.3] - 2016-05-04
52+
53+Breaking changes:
54+- Updated to v0.8 of the compiler, dropping support for previous versions. ([42fecfe](https://github.com/rowtype-yoga/purescript-unique/commit/42fecfef16b3f54e7bf52ba8e882202f5f73fe6b) by @mechairoi)
55+
56+## [0.2.2] - 2016-02-12
57+
58+Bugfixes:
59+- Fixed `bower.json`. ([5048080](https://github.com/rowtype-yoga/purescript-unique/commit/5048080a43a552e5a4786aff4bd4ae93816ade0f) by @mechairoi)
60+
61+Other improvements:
62+- Updated to use Pursuit for docs. ([de69519](https://github.com/rowtype-yoga/purescript-unique/commit/de695190c6bf43d827f0e63c0c99a6e080b262cc) by @mechairoi)
63+
64+## [0.2.1] - 2016-02-12
65+
66+No significant changes in this release.
67+
68+## [0.2.0] - 2016-02-12
69+
70+Breaking changes:
71+- Renamed `Uniq` effect to `UNIQ`. ([4eeac9f](https://github.com/rowtype-yoga/purescript-unique/commit/4eeac9f11f79b85bf8086d869ffa8fa56d9a9ec0) by @mechairoi)
72+
73+## [0.1.0] - 2015-08-09
74+
75+Breaking changes:
76+- Updated to v0.7 of the compiler, dropping support for previous versions. ([d2b2873](https://github.com/rowtype-yoga/purescript-unique/commit/d2b2873559a8c1bfe7dd3194a1614a77eac1a01e) by @mechairoi)
77+
78+## [0.0.1] - 2015-08-09
79+
80+Initial release
CONTRIBUTING.mdnew file+50
@@ -0,0 +1,50 @@
1+Contributing
2+============
3+
4+Welcome, and thanks for your interest in Unique. Whether you are new to PureScript or here to teach us new tricks, we're glad to have you and look forward to your contributions. Listed below are a few ways you can help.
5+
6+Asking questions
7+----------------
8+If you have a question, please [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new?labels=question) to discuss it. This might help us to find a defect; reveal an opportunity to improve the documentation or developer experience; or help someone facing a similar issue in the future.
9+
10+Reporting bugs
11+--------------
12+Please [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new?labels=bug&template=bug-report.md) to discuss any defects you find.
13+
14+Enhancements
15+------------
16+Please [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new?labels=enhancement&template=change-request.md) to discuss potential enhancements to the library. When submitting design ideas, please note that, for the most part, this library is intended as a direct port of the Haskell [`Data.Unique`](https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-Unique.html) module.
17+
18+Improving documentation
19+-----------------------
20+Please share any suggestions for improving or adding to the documentation by [submitting a pull request](https://github.com/rowtype-yoga/purescript-unique/compare) or [opening an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new?labels=documentation).
21+
22+Sharing resources
23+-----------------
24+If you have created a tutorial, auxiliary library, interesting code example, or other resource related to Unique, please [share it with the PureScript community](https://discourse.purescript.org). Increasing awareness will bring more users (and potential contributors) to the project.
25+
26+Submitting code
27+---------------
28+Pull requests are welcome, but we ask that you [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new) to discuss your plans before making any significant investment of your valuable time.
29+
30+### Development environment
31+
32+You can use [Nix](https://github.com/NixOS/nix) to create a development environment with all required tooling. Simply run `nix-shell` in the root project directory, and you'll have everything you need to get started.
33+
34+### Making changes
35+
36+* After making any changes, run `purs-tidy format-in-place src test` to format the code.
37+* Unit test(s) should accompany each change.
38+
39+### Preparing your submission
40+
41+Please verify your changes before submitting a pull request using the following commands:
42+1. `purs-tidy check src test`, which ensures that modules in the `src` and `test` directories conform to the project's formatting standards; and
43+1. `spago -x test.dhall test`, which runs the unit tests.
44+
45+### Submitting a pull request
46+
47+When you are ready to [submit a pull request](https://github.com/rowtype-yoga/purescript-unique/compare), please make sure to include:
48+1. a brief description of the change;
49+1. a link to the related issue, if applicable; and
50+1. any design considerations you feel are important.
LICENSE+1
@@ -1,6 +1,7 @@
1MIT License
1MIT License
2
2
3Copyright (c) 2015-2017 mechairoi
3Copyright (c) 2015-2017 mechairoi
4+Copyright (c) The University of Glasgow (Documentation)
4
5
5Permission is hereby granted, free of charge, to any person obtaining a copy
6Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7of this software and associated documentation files (the "Software"), to deal
README.md+39−4
@@ -1,8 +1,43 @@
1−# purescript-unique
1+# Unique
2
2
3−[![Build Status](https://travis-ci.org/mechairoi/purescript-unique.svg?branch=master)](https://travis-ci.org/mechairoi/purescript-unique)
3+[![CI](https://github.com/rowtype-yoga/purescript-unique/workflows/CI/badge.svg?branch=master)](https://github.com/rowtype-yoga/purescript-unique/actions?query=workflow%3ACI+branch%3Amaster)
4+[![Release](https://img.shields.io/github/release/rowtype-yoga/purescript-unique.svg)](https://github.com/rowtype-yoga/purescript-unique/releases)
5+[![Pursuit](https://pursuit.purescript.org/packages/purescript-unique/badge)](https://pursuit.purescript.org/packages/purescript-unique)
6+[![Maintainer: nsaunders](https://img.shields.io/badge/maintainer-nsaunders-teal.svg)](https://github.com/nsaunders)
4
7
5Data.Unique for PureScript.
8Data.Unique for PureScript.
6
9
7−## Documentations
10+## Installation
11+
12+Install `unique` with [Spago](https://github.com/purescript/spago):
13+
14+```sh
15+spago install unique
16+```
17+
18+## Quick start
19+
20+The quick start hasn't been written yet (contributions are welcome!). The quick start covers a common, minimal use case for the library, whereas longer examples and tutorials are kept in the [docs directory](./docs).
21+
22+## Documentation
23+
24+`unique` documentation is stored in a few places:
25+
8−- [purescript-unique on Pursuit](https://pursuit.purescript.org/packages/purescript-unique)
26+1. Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-unique).
27+2. Written documentation is kept in the [docs directory](./docs).
28+3. Usage examples can be found in [the test suite](./test).
29+
30+If you get stuck, there are several ways to get help:
31+
32+- [Open an issue](https://github.com/rowtype-yoga/purescript-unique/issues) if you have encountered a bug or problem.
33+- Ask general questions on the [PureScript Discourse](https://discourse.purescript.org) forum or the [PureScript Discord](https://discord.com/invite/sMqwYUbvz6) chat.
34+
35+## Contributing
36+
37+You can contribute to `unique` in several ways:
38+
39+1. If you encounter a problem or have a question, please [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues). We'll do our best to work with you to resolve or answer it.
40+
41+2. If you would like to contribute code, tests, or documentation, please [read the contributor guide](./CONTRIBUTING.md). It's a short, helpful introduction to contributing to this library, including development instructions.
42+
43+3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the [PureScript Discourse](https://discourse.purescript.org)! Writing libraries and learning resources are a great way to help this library succeed.
bower.json+2−1
@@ -18,7 +18,8 @@
18 ],
18 ],
19 "dependencies": {
19 "dependencies": {
20 "purescript-prelude": "^6.0.0",
20 "purescript-prelude": "^6.0.0",
21− "purescript-effect": "^4.0.0"
21+ "purescript-effect": "^4.0.0",
22+ "purescript-refs": "^6.0.0"
22 },
23 },
23 "devDependencies": {
24 "devDependencies": {
24 "purescript-console": "^6.0.0",
25 "purescript-console": "^6.0.0",
docs/README.mdnew file+3
@@ -0,0 +1,3 @@
1+# Unique Documentation
2+
3+This directory contains documentation for `unique`. If you are interested in contributing new documentation, please read the [contributor guidelines](../CONTRIBUTING.md) and [What Nobody Tells You About Documentation](https://documentation.divio.com) for help getting started.
purs.json+5−4
@@ -4,18 +4,19 @@
4 {
4 {
5 "email": "nick@saunde.rs",
5 "email": "nick@saunde.rs",
6 "keytype": "ssh-ed25519",
6 "keytype": "ssh-ed25519",
7− "public": "AAAAC3NzaC1lZDI1NTE5AAAAICm0Ar7rHAWONOM4qA5q777/CQaN6cHvcBq3VXB7d5Yw"
7+ "public": "AAAAC3NzaC1lZDI1NTE5AAAAIONVUgzC6fBZMCob5Ua0BShtF9QlriJV1IyZVvr8m8Gd"
8 }
8 }
9 ],
9 ],
10− "version": "0.6.0",
10+ "version": "0.6.1",
11 "license": "MIT",
11 "license": "MIT",
12 "location": {
12 "location": {
13− "githubOwner": "mechairoi",
13+ "githubOwner": "nsaunders",
14 "githubRepo": "purescript-unique"
14 "githubRepo": "purescript-unique"
15 },
15 },
16 "description": "Data.Unique for PureScript",
16 "description": "Data.Unique for PureScript",
17 "dependencies": {
17 "dependencies": {
18 "prelude": ">=6.0.0 <7.0.0",
18 "prelude": ">=6.0.0 <7.0.0",
19− "effect": ">=4.0.0 <5.0.0"
19+ "effect": ">=4.0.0 <5.0.0",
20+ "refs": ">=6.0.0 <7.0.0"
20 }
21 }
21}
22}
spago.dhall+1−1
@@ -1,5 +1,5 @@
1{ name = "unique"
1{ name = "unique"
2−, dependencies = [ "effect", "prelude" ]
2+, dependencies = [ "effect", "prelude", "refs" ]
3, packages = ./packages.dhall
3, packages = ./packages.dhall
4, sources = [ "src/**/*.purs" ]
4, sources = [ "src/**/*.purs" ]
5}
5}
src/Data/Unique.js+23−21
@@ -1,27 +1,29 @@
1−/* global exports */
1+export var zero = BigInt("0");
2−"use strict";
3
2
4−// module Data.Unique
3+var one = BigInt("1");
5
4
6−var MAX_SAFE_INTEGER = 9007199254740991;
5+export function eqImpl(a) {
7−var uniqueSource = [];
6+ return function(b) {
7+ return a === b;
8+ };
9+}
8
10
9−function iter(i) {
11+export function ordImpl(lt) {
10− if (uniqueSource.length === i) {
12+ return function (eq) {
11− for (var j = 0; j < i; ++j) uniqueSource[j] = 0;
13+ return function (gt) {
12− uniqueSource[i] = 1;
14+ return function (x) {
13− } else {
15+ return function (y) {
14− if (uniqueSource[i] === MAX_SAFE_INTEGER) {
16+ return x < y ? lt : x === y ? eq : gt;
15− uniqueSource[i] = 0;
17+ };
16− iter(i + 1);
18+ };
17− } else {
18− uniqueSource[i]++;
19− }
19+ };
20− }
20+ };
21}
21}
22
22
23−export function newUnique() {
23+export function addOne(x) {
24− iter(0);
24+ return x + one;
25− return uniqueSource.length === 1 ? uniqueSource[0] + "" : uniqueSource.join(",");
26−};
25+}
27
26
27+export function hashUnique(x) {
28+ return parseInt(BigInt.asIntN(32, x));
29+}
src/Data/Unique.purs+34−13
@@ -1,20 +1,41 @@
1−module Data.Unique
1+module Data.Unique (Unique, hashUnique, newUnique) where
2− ( newUnique
2+
3− , Unique
3+import Prelude hiding (zero)
4− ) where
5
4
6import Effect (Effect)
5import Effect (Effect)
7−import Prelude (class Ord, class Eq, class Show, compare, (==))
6+import Effect.Ref (Ref)
7+import Effect.Ref as Ref
8+import Effect.Unsafe (unsafePerformEffect)
9+
10+-- | An abstract unique object. Objects of type `Unique` may be compared for
11+-- | equality and ordering and hashed into `Int`.
12+foreign import data Unique :: Type
13+
14+foreign import eqImpl :: Unique -> Unique -> Boolean
15+
16+instance Eq Unique where
17+ eq = eqImpl
18+
19+foreign import ordImpl :: Ordering -> Ordering -> Ordering -> Unique -> Unique -> Ordering
20+
21+instance Ord Unique where
22+ compare = ordImpl LT EQ GT
8
23
9−newtype Unique = Unique String
24+foreign import addOne :: Unique -> Unique
10
25
11−foreign import newUnique :: Effect Unique
26+foreign import zero :: Unique
12
27
13−instance showUnique :: Show Unique where
28+-- | Hashes a `Unique` into an `Int`. Two `Unique`s may hash to the same value,
14− show (Unique a) = a
29+-- | although in practice this is unlikely. The `Int` returned makes a good hash
30+-- | key.
31+foreign import hashUnique :: Unique -> Int
15
32
16−instance eqUnique :: Eq Unique where
33+uniqSource :: Ref Unique
17− eq (Unique a) (Unique b) = a == b
34+uniqSource = unsafePerformEffect (Ref.new zero)
18
35
19−instance ordUnique :: Ord Unique where
36+-- | Creates a new object of type `Unique`. The value returned will not compare
20− compare (Unique a) (Unique b) = compare a b
37+-- | equal to any other value of type `Unique` returned by previous calls to
38+-- | `newUnique`. There is no limit on the number of times `newUnique` may be
39+-- | called.
40+newUnique :: Effect Unique
41+newUnique = Ref.modify addOne uniqSource
test/Main.purs+5−3
@@ -1,7 +1,7 @@
1module Test.Main where
1module Test.Main where
2
2
3−import Prelude ((==), ($), (/=), discard, bind, Unit)
3+import Prelude
4−import Data.Unique (newUnique)
4+import Data.Unique (hashUnique, newUnique)
5import Test.Assert (assert)
5import Test.Assert (assert)
6import Effect (Effect)
6import Effect (Effect)
7import Effect.Console (log)
7import Effect.Console (log)
@@ -11,5 +11,7 @@ main = do
11 log "Test Data.Unique"
11 log "Test Data.Unique"
12 a <- newUnique
12 a <- newUnique
13 b <- newUnique
13 b <- newUnique
14− assert $ a /= b
15 assert $ a == a
14 assert $ a == a
15+ assert $ a < b
16+ assert $ hashUnique a == hashUnique a
17+ assert $ hashUnique a /= hashUnique b