diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7c68b07 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# https://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000..b79b995 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,19 @@ +--- +name: Bug report +about: Report an issue +title: "" +labels: bug +assignees: "" +--- + +**Describe the bug** +A clear and concise description of the bug. + +**To Reproduce** +A minimal code example (preferably a runnable example on [Try PureScript](https://try.purescript.org)!) or steps to reproduce the issue. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/change-request.md b/.github/ISSUE_TEMPLATE/change-request.md new file mode 100644 index 0000000..a2ee685 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/change-request.md @@ -0,0 +1,21 @@ +--- +name: Change request +about: Propose an improvement to this library +title: "" +labels: "" +assignees: "" +--- + +**Is your change request related to a problem? Please describe.** +A clear and concise description of the problem. + +Examples: + +- It's frustrating to have to [...] +- I was looking for a function to [...] + +**Describe the solution you'd like** +A clear and concise description of what a good solution to you looks like, including any solutions you've already considered. + +**Additional context** +Add any other context about the change request here. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..8d7661e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: PureScript Discourse + url: https://discourse.purescript.org/ + about: Ask and answer questions on the PureScript discussion forum. + - name: PureScript Discord + url: https://purescript.org/chat + about: Ask and answer questions on the PureScript chat. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..d8780f7 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,11 @@ +**Description of the change** +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. + +--- + +**Checklist:** + +- [ ] Added the change to the changelog's "Unreleased" section with a link to this PR and your username +- [ ] Linked any existing issues or proposals that this pull request should close +- [ ] Updated or added relevant documentation in the README and/or documentation directory +- [ ] Added a test for the contribution (if applicable) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fe9f2da --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-node@v7 + with: + node-version: 24 + + - name: Set up a PureScript toolchain + uses: purescript-contrib/setup-purescript@main + with: + purescript: "unstable" + spago: "latest" + purs-tidy: "latest" + + - name: Cache PureScript dependencies + uses: actions/cache@v6 + with: + key: ${{ runner.os }}-spago-${{ hashFiles('spago.yaml', 'spago.lock') }} + path: | + .spago + output + + - name: Install dependencies + run: spago install + + - name: Build source and tests + run: spago build + + - name: Run tests + run: spago test + + - name: Check formatting + run: purs-tidy check src test diff --git a/.gitignore b/.gitignore index 0d1e361..7e82b68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ -*~ -output/ -bower_components/ -node_modules/ -.psci -.psci_modules/ +.* +!.gitignore +!.github +!.editorconfig +!.tidyrc.json + +output +generated-docs +bower_components diff --git a/.tidyrc.json b/.tidyrc.json new file mode 100644 index 0000000..4f013c1 --- /dev/null +++ b/.tidyrc.json @@ -0,0 +1,10 @@ +{ + "importSort": "source", + "importWrap": "source", + "indent": 2, + "operatorsFile": null, + "ribbon": 1, + "typeArrowPlacement": "first", + "unicode": "never", + "width": null +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..43930d7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,92 @@ +# Changelog + +Notable changes to this project 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). + +## Unreleased + +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v13.2.1](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.2.1) - 2026-10-11 + +Other improvements: + +- Migrate to registry-backed Spago and update CI tooling. + +## [v13.2.0](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.2.0) - 2023-02-13 + +Other improvements: + +- Correct `Typed` `slice` and `subArray` docs (#51 by @jamesdbrock) + +## [v13.1.0](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.1.0) - 2022-12-01 + +New features: + +- `Data.ArrayBuffer.Cast` (#46 by @jamesdbrock) + +## [v13.0.0](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.0.0) - 2022-04-27 + +Breaking Changes: +- Migrate FFI to ES modules (#41 by @JordanMartinez) +- Replaced polymorphic proxies with monomorphic `Proxy` (#41 by @JordanMartinez) + +## v12.0.0 + +Delete the `TypedArray` polyfill which was preventing this +library from working with `purs bundle` v0.14.4. +https://github.com/purescript-contrib/purescript-arraybuffer/issues/34 + +### Breaking Changes + +May lose partial polyfill `TypedArray` support for only the methods present +in regular JavaScript Arrays. +https://web.archive.org/web/20171019084331/https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill + +## v11.0.3 + +Revert to v11.0.1. +https://github.com/purescript-contrib/purescript-arraybuffer/issues/37 + +## v11.0.2 + +Delete the `TypedArray` polyfill which was preventing this +library from working with `purs bundle` v0.14.4. +https://github.com/purescript-contrib/purescript-arraybuffer/issues/34 + +## v11.0.1 + +Regenerate `bower.json`. + +## v11.0.0 + +Jorge Acereda has graciously donated this package to __purescript-contrib__. + +For version 11, we have refactored this library so that it depends only on +other packages in __purescript-contrib__. + +https://github.com/purescript-contrib/governance/issues/40 + +We have removed the dependencies on these non-__purescript-contrib__ packages: + +* https://pursuit.purescript.org/packages/purescript-typelevel +* https://pursuit.purescript.org/packages/purescript-quickcheck-combinators + +In v11.0.0 of this package, we have also upgraded to PureScript v0.14. + +### Breaking Changes + +To upgrade to v11.0.0, you might need to do a few substitutions +to the type declarations in your own dependent code: + +* Replace the type `AProxy` with `Proxy` from the Prelude. +* Remove most of the `Nat` typeclass constraints. https://github.com/purescript-contrib/purescript-arraybuffer/issues/29 +* Replace any `BytesPerValue a b` typeclass constraints with `BytesPerType a`. + +We have also privatized `Typed.part'`. https://github.com/purescript-contrib/purescript-arraybuffer/issues/32 + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..bff4e66 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,5 @@ +# Contributing to Arraybuffer + +Thanks for your interest in contributing to `arraybuffer`! We welcome new contributions regardless of your level of experience or familiarity with PureScript. + +Every library in the Contributors organization shares a simple handbook that helps new contributors get started. With that in mind, please [read the short contributing guide on purescript-contrib/governance](https://github.com/purescript-contrib/governance/blob/main/contributing.md) before contributing to this library. diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..f6503c4 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2021 PureScript Contrib + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index edfcc5c..ea4f39e 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,102 @@ -# purescript-arraybuffer +# arraybuffer -ArrayBuffer bindings for PureScript. +[![CI](https://github.com/purescript-contrib/purescript-arraybuffer/workflows/CI/badge.svg?branch=main)](https://github.com/purescript-contrib/purescript-arraybuffer/actions?query=workflow%3ACI+branch%3Amain) +[![Release](https://img.shields.io/github/release/purescript-contrib/purescript-arraybuffer.svg)](https://github.com/purescript-contrib/purescript-arraybuffer/releases) +[![Pursuit](https://pursuit.purescript.org/packages/purescript-arraybuffer/badge)](https://pursuit.purescript.org/packages/purescript-arraybuffer) +[![Maintainer: jacereda](https://img.shields.io/badge/maintainer-jacereda-teal.svg)](https://github.com/jacereda) +[![Maintainer: jamesdbrock](https://img.shields.io/badge/maintainer-jamesdbrock-teal.svg)](https://github.com/jamesdbrock) + + +Bindings and implementation for mutable JavaScript `ArrayBuffer`s. + +An `ArrayBuffer` is a built-in JavaScript object for storage of a flat continuous +region of memory. + +The `Typed` module provides a view into an `ArrayBuffer` for array +access of aligned local-machine-endian types, for in-process flat memory operations. + +The `DataView` module provides a view into an `ArrayBuffer` for inter-process +flat memory operations. + +* [MDN `ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) +* [ECMA-262 `ArrayBuffer`](https://tc39.es/ecma262/multipage/structured-data.html#sec-arraybuffer-objects) ## Installation -``` - bower install purescript-arraybuffer +Install `arraybuffer` with [Spago](https://github.com/purescript/spago): + +```sh +spago install arraybuffer ``` ## Documentation -Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-arraybuffer). +`arraybuffer` documentation is stored in a few places: + +1. Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-arraybuffer). +2. Written documentation is kept in the [docs directory](./docs). +3. Usage examples can be found in [the test suite](./test). + +If you get stuck, there are several ways to get help: + +- [Open an issue](https://github.com/purescript-contrib/purescript-arraybuffer/issues) if you have encountered a bug or problem. +- Ask general questions on the [PureScript Discourse](https://discourse.purescript.org) forum or the [PureScript Discord](https://purescript.org/chat) chat. + +## Contributing + +You can contribute to `arraybuffer` in several ways: + +1. If you encounter a problem or have a question, please [open an issue](https://github.com/purescript-contrib/purescript-arraybuffer/issues). We'll do our best to work with you to resolve or answer it. + +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. + +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. + +## Usage +### Polyfill + +This library relies on runtime implementations of +[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) +and +[`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) +([Structured Data](https://tc39.es/ecma262/multipage/structured-data.html#sec-structured-data)), +and +[`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) +([Indexed Collections](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-indexed-collections)). + +If you want to be sure that those implementations are available in your target +runtime environment, you might want to consider using a polyfill such as +[__core-js__ Typed Arrays](https://github.com/zloirock/core-js#ecmascript-typed-arrays). + +## Related packages + +These are some other packages which provide more `ArrayBuffer` features. + +### Reading and Writing + +* [__arraybuffer-class__](https://pursuit.purescript.org/packages/purescript-arraybuffer-class) +* [__dynamic-buffers__](https://pursuit.purescript.org/packages/purescript-dynamic-buffers) +* [__parsing-dataview__](https://pursuit.purescript.org/packages/purescript-parsing-dataview) +* [__arraybuffer-builder__](https://pursuit.purescript.org/packages/purescript-arraybuffer-builder) + +### Node.js + +* [__node-buffer__](https://pursuit.purescript.org/packages/purescript-node-buffer) + +### UTF + +* [__web-encoding__](https://pursuit.purescript.org/packages/purescript-web-encoding) + +### Base64 + +* [__base64-codec__](https://pursuit.purescript.org/packages/purescript-base64-codec) + +## Development + +Run the tests with + +```sh +spago test +``` diff --git a/bower.json b/bower.json deleted file mode 100644 index bc72e02..0000000 --- a/bower.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "purescript-arraybuffer", - "version": "4.0.0", - "license": "MIT", - "repository": { - "type": "git", - "url": "git://github.com/jacereda/purescript-arraybuffer.git" - }, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "dependencies": { - "purescript-functions": "^2.0.0", - "purescript-arraybuffer-types": "^0.2.0", - "purescript-maybe": "^2.0.0", - "purescript-eff": "^2.0.0", - "purescript-uint": "^0.3.0" - }, - "devDependencies": { - "purescript-debug": "^2.0.0", - "purescript-quickcheck": "^3.0.0" - } -} diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..2e2f3dd --- /dev/null +++ b/docs/README.md @@ -0,0 +1,3 @@ +# Arraybuffer Documentation + +This directory contains documentation for `arraybuffer`. 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. diff --git a/spago.lock b/spago.lock new file mode 100644 index 0000000..b2ce779 --- /dev/null +++ b/spago.lock @@ -0,0 +1,1309 @@ +{ + "workspace": { + "packages": { + "arraybuffer": { + "path": "./", + "core": { + "dependencies": [ + { + "arraybuffer-types": ">=3.0.2 <4.0.0" + }, + { + "arrays": ">=7.2.0 <8.0.0" + }, + { + "effect": ">=4.0.0 <5.0.0" + }, + { + "float32": ">=2.0.0 <3.0.0" + }, + { + "functions": ">=6.0.0 <7.0.0" + }, + { + "gen": ">=4.0.0 <5.0.0" + }, + { + "maybe": ">=6.0.0 <7.0.0" + }, + { + "nullable": ">=6.0.0 <7.0.0" + }, + { + "prelude": ">=6.0.1 <7.0.0" + }, + { + "tailrec": ">=6.1.0 <7.0.0" + }, + { + "uint": ">=7.0.0 <8.0.0" + }, + { + "unfoldable": ">=6.0.0 <7.0.0" + } + ] + }, + "test": { + "dependencies": [ + "console", + "foldable-traversable", + "partial", + "quickcheck", + "quickcheck-laws", + "refs", + "tuples" + ] + } + } + }, + "package_set": { + "address": { + "registry": "81.4.0" + }, + "compiler": ">=0.15.15 <0.16.0", + "content": { + "abc-parser": "2.1.0", + "ace": "9.1.0", + "address-rfc2821": "0.1.1", + "aff": "8.0.0", + "aff-bus": "6.0.0", + "aff-coroutines": "9.0.0", + "aff-promise": "4.0.0", + "aff-retry": "2.0.0", + "affjax": "13.0.0", + "affjax-node": "1.0.0", + "affjax-web": "1.0.0", + "ansi": "7.0.0", + "apexcharts": "0.5.0", + "applicative-phases": "1.0.0", + "argonaut": "9.0.0", + "argonaut-aeson-generic": "0.4.1", + "argonaut-codecs": "9.1.0", + "argonaut-core": "7.0.0", + "argonaut-generic": "8.0.0", + "argonaut-traversals": "10.0.0", + "argparse-basic": "2.0.0", + "array-builder": "0.1.2", + "array-search": "0.6.0", + "arraybuffer": "13.2.0", + "arraybuffer-builder": "3.1.0", + "arraybuffer-types": "3.0.2", + "arrays": "7.3.0", + "arrays-extra": "0.6.2", + "arrays-zipper": "2.0.1", + "ask": "1.0.0", + "assert": "6.0.0", + "assert-multiple": "0.4.0", + "avar": "5.0.1", + "axon": "0.0.3", + "b64": "0.0.9", + "barbies": "1.0.1", + "barlow-lens": "1.0.0", + "baskerville-core": "0.1.3", + "baskerville-mycroft": "0.1.0", + "benchlib": "0.0.4", + "bifunctors": "6.1.0", + "bigints": "7.0.1", + "blessed": "1.0.0", + "bolson": "0.3.9", + "bookhound": "0.1.7", + "bower-json": "3.0.0", + "bytestrings": "9.0.0", + "call-by-name": "4.0.1", + "canvas": "6.0.0", + "canvas-action": "9.0.0", + "cartesian": "1.0.6", + "catenable-lists": "7.0.0", + "cbor-stream": "1.3.0", + "chameleon": "1.0.0", + "chameleon-halogen": "1.0.3", + "chameleon-react-basic": "1.1.0", + "chameleon-styled": "2.5.0", + "chameleon-transformers": "1.0.0", + "channel": "1.0.0", + "chartjs": "0.2.0", + "chartjs-halogen": "0.2.0", + "checked-exceptions": "3.1.1", + "choku": "1.0.2", + "classless": "0.1.1", + "classless-arbitrary": "0.1.1", + "classless-decode-json": "0.1.1", + "classless-encode-json": "0.1.3", + "classnames": "2.0.0", + "codec": "6.1.0", + "codec-argonaut": "10.0.0", + "codec-json": "2.0.0", + "colors": "7.0.1", + "compile-fail": "0.4.0", + "concur-core": "0.5.0", + "concur-react": "0.5.0", + "concurrent-queues": "3.0.0", + "console": "6.1.0", + "const": "6.0.0", + "contravariant": "6.0.0", + "control": "6.0.0", + "convertable-options": "1.0.0", + "coroutines": "7.0.0", + "css": "6.0.0", + "css-class-name-extractor": "0.0.4", + "css-frameworks": "1.1.0", + "csv-stream": "2.3.0", + "currency": "0.1.0", + "data-mvc": "0.0.2", + "datetime": "6.1.0", + "datetime-parsing": "0.2.0", + "debounce": "0.1.2", + "debug": "6.0.2", + "decimals": "7.1.0", + "default-values": "1.0.1", + "deku": "0.9.24", + "deno": "0.0.5", + "dissect": "1.0.0", + "distributive": "6.0.0", + "dodo-printer": "2.2.3", + "dom-filereader": "7.0.0", + "dom-indexed": "13.0.0", + "dom-simple": "0.4.0", + "dotenv": "4.0.3", + "droplet": "0.6.0", + "dts": "1.0.0", + "dual-numbers": "1.0.3", + "dynamic-buffer": "3.0.1", + "echarts-simple": "0.0.1", + "effect": "4.0.0", + "either": "6.1.0", + "elmish": "0.16.0", + "elmish-enzyme": "0.1.1", + "elmish-hooks": "0.12.0", + "elmish-html": "0.14.0", + "elmish-testing-library": "0.5.0", + "email-validate": "7.0.0", + "encoding": "0.0.10", + "enums": "6.0.1", + "env-names": "0.4.0", + "environment": "2.0.0", + "error": "2.0.0", + "eta-conversion": "0.3.2", + "exceptions": "6.1.0", + "exists": "6.0.0", + "exitcodes": "4.0.0", + "expect-inferred": "3.0.0", + "express": "0.9.1", + "ezfetch": "1.1.1", + "fahrtwind": "2.0.0", + "faker-ffi": "0.1.1", + "fakerjs": "0.0.1", + "fallback": "0.1.0", + "fast-vect": "1.2.0", + "fetch": "4.1.0", + "fetch-argonaut": "1.0.1", + "fetch-core": "5.1.0", + "fetch-yoga-json": "1.1.0", + "ffi-simple": "0.5.1", + "fft": "0.3.0", + "fft-js": "0.1.0", + "filterable": "5.0.0", + "fix-functor": "0.1.0", + "fixed-points": "7.0.0", + "fixed-precision": "5.0.0", + "flame": "1.6.0", + "float32": "2.0.0", + "fmt": "0.2.1", + "foldable-traversable": "6.0.0", + "foldable-traversable-extra": "0.0.6", + "foreign": "7.0.0", + "foreign-object": "4.1.0", + "foreign-readwrite": "3.4.0", + "forgetmenot": "0.1.0", + "fork": "6.0.0", + "form-urlencoded": "7.0.0", + "formatters": "7.0.0", + "framer-motion": "3.1.0", + "free": "7.1.0", + "freeap": "7.0.0", + "freer-free": "0.0.1", + "freet": "7.0.0", + "functions": "6.0.0", + "functor1": "3.0.0", + "functors": "5.0.0", + "fuzzy": "0.4.0", + "gen": "4.0.0", + "generate-values": "1.0.1", + "generic-router": "0.0.1", + "geojson": "0.0.5", + "geometria": "2.2.0", + "gesso": "1.0.1", + "gojs": "0.1.1", + "golden-test": "0.1.0", + "golem-fetch": "0.1.0", + "grain": "3.0.0", + "grain-router": "3.0.0", + "grain-virtualized": "3.0.0", + "graphql-client": "10.1.1", + "graphs": "8.1.0", + "group": "4.1.1", + "halogen": "7.0.0", + "halogen-bootstrap5": "5.3.2", + "halogen-canvas": "1.0.0", + "halogen-css": "10.0.0", + "halogen-declarative-canvas": "0.0.8", + "halogen-echarts-simple": "0.0.4", + "halogen-formless": "4.0.3", + "halogen-helix": "1.1.0", + "halogen-hooks": "0.6.3", + "halogen-hooks-extra": "0.9.0", + "halogen-infinite-scroll": "1.1.0", + "halogen-store": "0.5.4", + "halogen-storybook": "2.0.0", + "halogen-subscriptions": "2.0.0", + "halogen-svg-elems": "8.0.0", + "halogen-typewriter": "1.0.4", + "halogen-use-trigger-hooks": "1.0.0", + "halogen-vdom": "8.0.0", + "halogen-vdom-string-renderer": "0.5.0", + "halogen-widgets": "0.3.1", + "halogen-xterm": "2.0.0", + "harmonia": "0.2.0", + "heckin": "2.0.1", + "heterogeneous": "0.7.0", + "homogeneous": "0.4.0", + "http-methods": "6.1.0", + "httpurple": "4.0.0", + "huffman": "0.4.0", + "humdrum": "0.0.1", + "hylograph-canvas": "0.1.0", + "hylograph-components": "0.1.0", + "hylograph-d3-kernel": "0.1.0", + "hylograph-graph": "0.3.0", + "hylograph-layout": "0.3.0", + "hylograph-music": "0.4.0", + "hylograph-optics": "0.1.0", + "hylograph-selection": "0.5.3", + "hylograph-simulation": "0.6.0", + "hylograph-simulation-core": "0.1.0", + "hylograph-simulation-halogen": "0.5.1", + "hylograph-transitions": "0.1.0", + "hylograph-wasm-kernel": "0.1.0", + "hyrule": "2.3.9", + "i18next": "0.1.0", + "idb": "0.2.0", + "identity": "6.0.0", + "identy": "4.0.1", + "indexed-db": "1.0.0", + "indexed-monad": "3.0.0", + "ink": "0.0.1", + "int64": "3.0.0", + "integers": "6.0.0", + "interpolate": "5.0.2", + "intersection-observer": "1.0.1", + "invariant": "6.0.0", + "jarilo": "1.0.1", + "jelly": "0.10.0", + "jelly-router": "0.3.0", + "jelly-signal": "0.4.0", + "jest": "1.0.0", + "js-abort-controller": "1.0.0", + "js-bigints": "2.2.1", + "js-date": "8.0.0", + "js-fetch": "0.2.1", + "js-fileio": "3.0.0", + "js-intl": "1.3.0", + "js-iterators": "0.1.1", + "js-maps": "0.1.2", + "js-promise": "1.0.0", + "js-promise-aff": "1.0.0", + "js-temporal": "3.0.0", + "js-timers": "6.1.0", + "js-uri": "3.1.0", + "jsdom": "1.0.0", + "jsinc": "0.5.1", + "json": "1.1.0", + "json-codecs": "5.0.0", + "justifill": "0.5.0", + "jwt": "0.0.9", + "labeled-data": "0.2.0", + "language-cst-parser": "0.14.1", + "lazy": "6.0.0", + "lazy-joe": "1.0.0", + "lcg": "4.0.0", + "leibniz": "5.0.0", + "leveldb": "1.0.1", + "liminal": "1.0.1", + "linalg": "6.0.0", + "linear": "0.1.0", + "lists": "7.0.0", + "literals": "1.0.2", + "logging": "3.0.0", + "logging-journald": "0.4.0", + "lumi-components": "18.0.0", + "machines": "7.0.0", + "maps-eager": "0.5.0", + "marionette": "1.0.0", + "marionette-react-basic-hooks": "0.1.1", + "markdown-it-js": "0.1.0", + "marked": "0.1.0", + "matrices": "5.0.1", + "matryoshka": "1.0.0", + "maybe": "6.0.0", + "media-types": "6.0.0", + "meowclient": "1.0.0", + "midi": "4.0.0", + "milkdown": "0.1.0", + "milkis": "9.0.0", + "mimetype": "0.0.1", + "minibench": "4.0.1", + "mmorph": "7.0.0", + "monad-control": "5.0.0", + "monad-logger": "1.3.1", + "monad-loops": "0.5.0", + "monad-unlift": "1.0.1", + "monoid-extras": "0.0.1", + "monoidal": "0.16.0", + "mote": "3.0.0", + "motion": "4.0.0", + "motsunabe": "2.0.0", + "mvc": "0.0.1", + "mycroft": "0.1.1", + "mycroft-z3-wasm": "0.1.0", + "mysql": "6.0.1", + "n3": "0.1.0", + "nano-id": "1.1.0", + "nanoid": "0.1.0", + "naturals": "3.0.0", + "nested-functor": "0.2.1", + "newtype": "5.0.0", + "next-purs-rsc": "0.1.0", + "nextjs": "0.1.1", + "nextui": "0.2.0", + "node-buffer": "9.0.0", + "node-child-process": "11.1.0", + "node-event-emitter": "3.0.0", + "node-execa": "5.0.0", + "node-fs": "9.2.0", + "node-glob-basic": "2.0.0", + "node-http": "9.1.0", + "node-http2": "1.1.1", + "node-human-signals": "1.0.0", + "node-net": "5.1.0", + "node-os": "5.1.0", + "node-path": "5.0.1", + "node-process": "11.2.0", + "node-readline": "8.1.1", + "node-sqlite": "0.2.0", + "node-sqlite3": "8.0.0", + "node-stream-pipes": "2.1.6", + "node-streams": "9.0.1", + "node-tls": "0.3.1", + "node-url": "7.0.1", + "node-workerbees": "0.3.1", + "node-zlib": "0.4.0", + "nonempty": "7.0.0", + "now": "6.0.0", + "npm-package-json": "2.0.0", + "nqueens": "0.1.4", + "nullable": "6.0.0", + "numberfield": "0.2.2", + "numbers": "9.0.1", + "oak": "3.1.1", + "oak-debug": "1.2.2", + "object-maps": "0.3.0", + "ocarina": "1.5.4", + "oooooooooorrrrrrrmm-lib": "0.0.1", + "open-colors-scales-and-schemes": "1.0.0", + "open-drawing": "6.0.4", + "open-folds": "6.4.0", + "open-foreign-generic": "11.0.3", + "open-memoize": "6.2.0", + "open-mkdirp-aff": "1.2.0", + "open-pairing": "6.2.0", + "open-smolder": "12.0.2", + "options": "7.0.0", + "optparse": "5.0.1", + "ordered-collections": "3.2.0", + "ordered-set": "0.5.2", + "orders": "6.0.0", + "org-doc": "0.1.0", + "owoify": "1.2.0", + "pairs": "9.0.1", + "parallel": "7.0.0", + "parsing": "11.0.0", + "parsing-dataview": "3.2.4", + "partial": "4.0.0", + "pathy": "9.0.0", + "pha": "0.13.0", + "phaser": "0.7.0", + "phylio": "1.1.2", + "pipes": "8.0.0", + "pirates-charm": "0.0.1", + "play": "1.0.0", + "pmock": "1.1.0", + "point-free": "1.0.0", + "pointed-list": "0.5.1", + "polymorphic-vectors": "4.0.0", + "posix-types": "6.0.0", + "postgresql": "2.0.21", + "precise": "6.0.0", + "precise-datetime": "7.0.0", + "prelude": "6.0.2", + "prettier-printer": "3.0.0", + "printf": "0.1.0", + "priority-queue": "0.1.2", + "profunctor": "6.0.1", + "profunctor-lenses": "8.0.0", + "prospero": "0.1.0", + "protobuf": "4.4.0", + "ps-spa": "0.7.1", + "psa-utils": "8.0.0", + "psci-support": "6.0.0", + "punycode": "1.0.0", + "pursfmt": "0.17.0", + "qualified-do": "2.2.0", + "quantities": "12.2.0", + "quickcheck": "8.0.1", + "quickcheck-combinators": "0.1.3", + "quickcheck-laws": "7.0.0", + "quickcheck-utf8": "0.0.0", + "random": "6.0.0", + "rationals": "6.0.0", + "rdf": "0.1.0", + "react": "11.0.0", + "react-aria": "0.2.0", + "react-basic": "17.0.0", + "react-basic-classic": "3.0.0", + "react-basic-dnd": "10.1.0", + "react-basic-dom": "7.0.0", + "react-basic-dom-beta": "0.1.1", + "react-basic-emotion": "7.1.0", + "react-basic-hooks": "9.1.1", + "react-basic-storybook": "2.0.0", + "react-dnd-kit": "0.6.0", + "react-dom": "8.0.0", + "react-halo": "3.0.0", + "react-icons": "1.1.6", + "react-markdown": "0.1.0", + "react-testing-library": "4.0.1", + "react-virtuoso": "1.0.0", + "reactix": "0.6.1", + "read": "1.0.1", + "recharts": "1.1.0", + "record": "4.0.0", + "record-extra": "5.0.1", + "record-extra-srghma": "0.2.8", + "record-ptional-fields": "0.1.2", + "record-studio": "1.0.4", + "ref-lifted": "0.0.2", + "refs": "6.0.0", + "remotedata": "5.0.1", + "repr": "0.5.0", + "resize-arrays": "0.0.1", + "resize-observer": "1.0.0", + "resource": "2.0.1", + "resourcet": "1.0.0", + "result": "1.0.3", + "return": "0.2.0", + "ring-modules": "5.0.1", + "rito": "0.3.4", + "roman": "0.4.0", + "rough-notation": "1.0.2", + "routing": "11.0.0", + "routing-duplex": "0.7.0", + "run": "5.0.0", + "safe-coerce": "2.0.0", + "safely": "4.0.1", + "school-of-music": "1.3.0", + "selection-foldable": "0.2.0", + "selective-functors": "1.0.1", + "semirings": "7.0.0", + "seowebchecker": "1.0.4", + "shuffle": "2.0.0", + "sigil": "0.3.0", + "sigil-hats": "0.3.0", + "signal": "13.0.0", + "simple-emitter": "3.0.1", + "simple-i18n": "2.0.1", + "simple-json": "9.0.0", + "simple-json-generics": "0.2.1", + "simple-ulid": "3.0.0", + "sized-matrices": "1.0.0", + "sized-vectors": "5.0.2", + "slug": "3.2.0", + "small-ffi": "4.0.1", + "soundfonts": "4.1.0", + "sparse-matrices": "2.0.1", + "sparse-polynomials": "3.0.1", + "spec": "8.1.2", + "spec-discovery": "8.4.1", + "spec-mocha": "5.1.1", + "spec-node": "0.0.3", + "spec-quickcheck": "5.0.2", + "spec-reporter-xunit": "0.7.1", + "splitmix": "2.1.0", + "ssrs": "1.0.0", + "st": "6.2.0", + "statistics": "0.3.2", + "strictlypositiveint": "1.0.1", + "string-parsers": "8.0.0", + "strings": "6.0.1", + "strings-extra": "4.0.0", + "stringutils": "0.0.13", + "structured-logging": "1.0.0", + "substitute": "0.2.3", + "supabase": "0.1.0", + "supply": "0.2.0", + "svg-parser": "3.0.0", + "systemd-journald": "0.3.0", + "tagged": "4.0.2", + "tailrec": "6.1.0", + "tanstack-query": "3.0.0", + "tecton": "0.2.1", + "tecton-halogen": "0.2.0", + "temporal": "0.2.0", + "test-unit": "17.0.0", + "text-formatting": "0.1.0", + "thermite": "6.3.1", + "thermite-dom": "0.3.1", + "these": "6.0.0", + "threading": "0.0.3", + "tidy": "0.11.1", + "tidy-codegen": "4.0.1", + "tldr": "0.0.0", + "toestand": "0.9.0", + "tramaj-halogen": "0.4.1", + "tramaj-purs": "0.4.1", + "transformation-matrix": "1.0.1", + "transformers": "6.1.0", + "transit": "1.0.0", + "tree-rose": "4.0.2", + "trivial-unfold": "0.5.0", + "ts-bridge": "4.0.0", + "tuples": "7.0.0", + "two-or-more": "1.0.0", + "type-equality": "4.0.1", + "typedenv": "2.0.1", + "typelevel": "6.0.0", + "typelevel-lists": "2.1.0", + "typelevel-peano": "1.0.1", + "typelevel-prelude": "7.0.0", + "typelevel-regex": "0.0.3", + "typelevel-rows": "0.1.0", + "typisch": "0.4.0", + "uint": "7.0.0", + "ulid": "3.0.1", + "uncurried-transformers": "1.1.0", + "undefined": "2.0.0", + "undefined-is-not-a-problem": "1.1.0", + "unfoldable": "6.0.0", + "unicode": "6.0.0", + "unique": "0.6.1", + "unlift": "1.0.1", + "unordered-collections": "3.1.0", + "unsafe-coerce": "6.0.0", + "unsafe-reference": "5.0.0", + "untagged-to-tagged": "0.1.4", + "untagged-union": "1.0.0", + "uri": "9.0.0", + "url-immutable": "1.0.0", + "url-regex-safe": "0.1.1", + "uuid": "9.0.0", + "uuidv4": "1.0.0", + "validation": "6.0.0", + "variant": "8.0.0", + "variant-encodings": "2.0.0", + "variant-gen": "1.0.0", + "vectorfield": "1.0.1", + "vectors": "2.1.0", + "versions": "7.0.0", + "visx": "0.0.2", + "vitest": "2.0.1", + "wasm-base": "0.2.0", + "web-chain": "1.0.1", + "web-clipboard": "6.0.0", + "web-cssom": "2.0.0", + "web-cssom-view": "0.1.0", + "web-dom": "6.0.0", + "web-dom-parser": "8.0.0", + "web-dom-xpath": "3.0.0", + "web-encoding": "3.0.0", + "web-events": "4.0.0", + "web-fetch": "4.0.1", + "web-file": "4.0.0", + "web-geometry": "0.1.0", + "web-html": "4.1.1", + "web-pointerevents": "2.0.0", + "web-proletarian": "1.0.0", + "web-promise": "3.2.0", + "web-resize-observer": "2.1.0", + "web-router": "1.0.0", + "web-socket": "4.0.0", + "web-storage": "5.0.0", + "web-streams": "4.0.0", + "web-touchevents": "4.0.0", + "web-uievents": "5.0.0", + "web-url": "2.0.0", + "web-workers": "2.0.0", + "web-xhr": "5.0.1", + "webb-aff-list": "0.0.2", + "webb-array": "0.0.2", + "webb-channel": "0.0.3", + "webb-commandline": "0.0.3", + "webb-directory": "0.0.7", + "webb-file": "0.0.1", + "webb-map": "0.0.1", + "webb-monad": "0.0.2", + "webb-mutex": "0.0.7", + "webb-parsing": "0.0.5", + "webb-random": "0.0.1", + "webb-refer": "0.0.3", + "webb-set": "0.0.1", + "webb-slot": "0.0.1", + "webb-stateful": "0.0.3", + "webb-string": "0.0.1", + "webb-test": "0.0.1", + "webb-thread": "0.0.2", + "webb-writer": "0.0.3", + "webextension-polyfill": "0.1.0", + "webgpu": "0.0.1", + "which": "2.0.0", + "whine-core": "0.0.34", + "xterm": "1.0.0", + "yaml-next": "3.1.1", + "yoga-acp-om": "0.1.1", + "yoga-better-auth": "0.2.2", + "yoga-bun-yoga": "0.2.1", + "yoga-config": "0.2.1", + "yoga-country": "3.0.0", + "yoga-docker-compose": "0.1.1", + "yoga-dynamodb": "0.1.1", + "yoga-elasticsearch": "0.1.1", + "yoga-fastify": "0.5.4", + "yoga-fastify-om": "0.4.7", + "yoga-fetch": "1.0.1", + "yoga-fetch-om": "0.8.0", + "yoga-format": "1.0.0", + "yoga-heroui": "2.0.3", + "yoga-http-api": "0.3.4", + "yoga-jaeger": "0.1.1", + "yoga-json": "5.2.1", + "yoga-language": "1.0.0", + "yoga-next-fastify": "0.2.0", + "yoga-om": "2.2.1", + "yoga-om-layer": "2.1.0", + "yoga-om-strom": "0.4.3", + "yoga-om-workerbees": "0.1.2", + "yoga-opentelemetry": "0.2.0", + "yoga-options": "0.1.1", + "yoga-pino": "0.1.1", + "yoga-postgres": "6.0.0", + "yoga-react": "1.0.2", + "yoga-react-dom": "2.0.1", + "yoga-react-native": "0.2.1", + "yoga-react-om": "0.2.0", + "yoga-redis": "0.1.1", + "yoga-scylladb": "0.1.1", + "yoga-shadcn": "1.0.5", + "yoga-sql-types": "0.2.0", + "yoga-sqlite": "0.3.4", + "yoga-sqlite-om": "0.3.0", + "yoga-sse": "0.1.1", + "yoga-subtlecrypto": "0.1.0", + "yoga-test-docker": "0.1.2", + "yoga-timezone": "1.0.0", + "yoga-tree": "1.0.0", + "yoga-tree-svg": "0.1.0", + "yoga-tree-utils": "1.0.0", + "z3": "0.0.2", + "zipperarray": "2.0.0" + } + }, + "extra_packages": {} + }, + "packages": { + "arraybuffer-types": { + "type": "registry", + "version": "3.0.2", + "integrity": "sha256-p05cJnSkyeoB7VHzMyc2Eb1RwUaB7Nl0sQSqEGNEUD8=", + "dependencies": [] + }, + "arrays": { + "type": "registry", + "version": "7.3.0", + "integrity": "sha256-GD4z7LCi9wzi7FCQqbWhvs8paoUK9NO+HwgXZ+KP8Rk=", + "dependencies": [ + "bifunctors", + "control", + "foldable-traversable", + "functions", + "maybe", + "nonempty", + "partial", + "prelude", + "safe-coerce", + "st", + "tailrec", + "tuples", + "unfoldable", + "unsafe-coerce" + ] + }, + "bifunctors": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-CvZRb8uI75eKIqiYntR+k05Wk6tKlMS5w8sCA2AFna0=", + "dependencies": [ + "const", + "either", + "newtype", + "prelude", + "tuples" + ] + }, + "console": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-3T5PPz1mATZmV0C4GzkCkpLlCa5xG7u8ZNgnLrrrI1Q=", + "dependencies": [ + "effect", + "prelude" + ] + }, + "const": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-S+m0lQsxnji0z1XRUmkn+3RFuWJ5CXWuIr1u3i8Bfoc=", + "dependencies": [ + "invariant", + "newtype", + "prelude" + ] + }, + "contravariant": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-nuckEWqL80NaPmR/l9AUyrfycNh18XcvlZV9PAamwqc=", + "dependencies": [ + "const", + "either", + "newtype", + "prelude", + "tuples" + ] + }, + "control": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-0vxyYh5FL+ilxgLo954w1LqCUC0RSIivNNlb9CaNUQg=", + "dependencies": [ + "newtype", + "prelude" + ] + }, + "distributive": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-netyJK4B32PDYHD0tF2AenKgo3urzbI770ycM0pArAo=", + "dependencies": [ + "identity", + "newtype", + "prelude", + "tuples", + "type-equality" + ] + }, + "effect": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-DdqU3bncRTjgMVPPRlAuGHVeajSPEcRaRhNuio7if6s=", + "dependencies": [ + "prelude" + ] + }, + "either": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-tBHx3PgtH4GZOApZCDkcM7szRTYJinrUrVGWazQCUUg=", + "dependencies": [ + "control", + "invariant", + "maybe", + "prelude" + ] + }, + "enums": { + "type": "registry", + "version": "6.0.1", + "integrity": "sha256-sdZOmLX5+5pASGpvVyT0vSD5BBYQjZiayjV5XiPutso=", + "dependencies": [ + "control", + "either", + "gen", + "maybe", + "newtype", + "nonempty", + "partial", + "prelude", + "tuples", + "unfoldable" + ] + }, + "exceptions": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-nRrr+N0wk0TUFOWLR7e1n1oxcXo/X345bQUtoY9lW6A=", + "dependencies": [ + "effect", + "either", + "maybe", + "prelude" + ] + }, + "exists": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-vtLbrWNaI+pzx/2fw2AQnCovoLtcosClIhjO26QKkh8=", + "dependencies": [ + "unsafe-coerce" + ] + }, + "float32": { + "type": "registry", + "version": "2.0.0", + "integrity": "sha256-lO8pshPBj5ExM+/ZjZ8nXVltb37XGJdRP8vakl0LBTE=", + "dependencies": [ + "gen", + "maybe", + "prelude" + ] + }, + "foldable-traversable": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-NGGWyCio/xjce6fPP7y3wwg7CheqllID6aJudDxbWhA=", + "dependencies": [ + "bifunctors", + "const", + "control", + "either", + "functors", + "identity", + "maybe", + "newtype", + "orders", + "prelude", + "tuples" + ] + }, + "functions": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-0jgtOr+SFO4UScKc40oA/9Vdcf2rLn3h3vZlY0KfqVo=", + "dependencies": [ + "prelude" + ] + }, + "functors": { + "type": "registry", + "version": "5.0.0", + "integrity": "sha256-W1o/4wcp6S3chodYL8uixlXK2mfr1L+SzM1R+whqUco=", + "dependencies": [ + "bifunctors", + "const", + "contravariant", + "control", + "distributive", + "either", + "invariant", + "maybe", + "newtype", + "prelude", + "profunctor", + "tuples", + "unsafe-coerce" + ] + }, + "gen": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-kyOateeOtQa07vfTMYeSuCKdelgKE1R65fwKkZ10wsY=", + "dependencies": [ + "either", + "foldable-traversable", + "identity", + "maybe", + "newtype", + "nonempty", + "prelude", + "tailrec", + "tuples", + "unfoldable" + ] + }, + "identity": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-RY/iXPpxpqvKHYfJeFVNI1J06kohB9rbtWYuha8t0LE=", + "dependencies": [ + "control", + "invariant", + "newtype", + "prelude" + ] + }, + "integers": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-Y8yozC1uHRLcruobEyv5/bMKzE1BoKJ/olHv6o+bgm8=", + "dependencies": [ + "maybe", + "numbers", + "prelude" + ] + }, + "invariant": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-HyoT1I5qIHRq8RSZji6zZDvqnpVjLw748utrKwZtqsw=", + "dependencies": [ + "control", + "prelude" + ] + }, + "lazy": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-MHRC+1Pc+AjortBp4b/e1e6KpEpsDwaJBNBB7TOL+1I=", + "dependencies": [ + "control", + "foldable-traversable", + "invariant", + "prelude" + ] + }, + "lcg": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-bUYyfXYmjTn7zSpj2hTiePywzsuD80fCjkonsrpdGOw=", + "dependencies": [ + "effect", + "integers", + "maybe", + "numbers", + "partial", + "prelude", + "random" + ] + }, + "lists": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-/mGd7wLoU+wsTcqii7SSUByxsvwvjnu2PjwAD47yYb4=", + "dependencies": [ + "bifunctors", + "control", + "foldable-traversable", + "lazy", + "maybe", + "newtype", + "nonempty", + "partial", + "prelude", + "tailrec", + "tuples", + "unfoldable" + ] + }, + "maybe": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-8X6XEgtZ5lqfkEuc1hWOofnL6mwhk8gSJTxwvbR/SbY=", + "dependencies": [ + "control", + "invariant", + "newtype", + "prelude" + ] + }, + "newtype": { + "type": "registry", + "version": "5.0.0", + "integrity": "sha256-dt6w0cty4OS+Pjt9fsh3iU6ottqSU83mdAZkaEEvo6c=", + "dependencies": [ + "prelude", + "safe-coerce" + ] + }, + "nonempty": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-Ctkq8/+KiGqCE53Y/LvibA/coy7ev9HtRZU+GYS7yfQ=", + "dependencies": [ + "control", + "foldable-traversable", + "maybe", + "prelude", + "tuples", + "unfoldable" + ] + }, + "nullable": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-CDAZk+L9Sc0GCFTkE8n+qdp4Ys8avvnkU+m2hVALt7M=", + "dependencies": [ + "functions", + "maybe", + "prelude" + ] + }, + "numbers": { + "type": "registry", + "version": "9.0.1", + "integrity": "sha256-ZydYckgwRAnRaFC7pu6fADhzdwX+UqHZrfJyet64zls=", + "dependencies": [ + "functions", + "maybe", + "prelude" + ] + }, + "orders": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-nSMxZK7wxyDULkjZqvMyB71mVo6b0AyLLHosDVbv1XM=", + "dependencies": [ + "newtype", + "prelude" + ] + }, + "partial": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-mdrlJBAgFMh79hNRW39uv7c+BwnnaOrAMmdh7+VhEhs=", + "dependencies": [] + }, + "prelude": { + "type": "registry", + "version": "6.0.2", + "integrity": "sha256-IqykrDRquGUD/LRSad7y75hZv3bUsGQ4knc8tdez8Qw=", + "dependencies": [] + }, + "profunctor": { + "type": "registry", + "version": "6.0.1", + "integrity": "sha256-Ow0mJC+PIIRq/a3mzCWY5vxuTgR/e+Ee68+mWeSRnWY=", + "dependencies": [ + "control", + "distributive", + "either", + "exists", + "invariant", + "newtype", + "prelude", + "tuples" + ] + }, + "quickcheck": { + "type": "registry", + "version": "8.0.1", + "integrity": "sha256-SfW+maesCt0jnnFhfrgJZGPcWLj8oFcGbcDIVklmdzc=", + "dependencies": [ + "arrays", + "console", + "control", + "effect", + "either", + "enums", + "exceptions", + "foldable-traversable", + "gen", + "identity", + "integers", + "lazy", + "lcg", + "lists", + "maybe", + "newtype", + "nonempty", + "numbers", + "partial", + "prelude", + "record", + "st", + "strings", + "tailrec", + "transformers", + "tuples" + ] + }, + "quickcheck-laws": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-hDd4Q99TNlEz9sU0Cssm7n6+BswAq69HL8KqNP5UKOU=", + "dependencies": [ + "arrays", + "console", + "control", + "effect", + "enums", + "foldable-traversable", + "maybe", + "newtype", + "prelude", + "quickcheck" + ] + }, + "random": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-7sZRo6P9UIiXDZ9s2QL9T8h3wlIwLdQrR4+oZKOijQw=", + "dependencies": [ + "effect", + "integers", + "prelude" + ] + }, + "record": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-WQ8fqp4X1wTA70J4qUcPW4Z7DCwx6e5KJnT/EuTdWSc=", + "dependencies": [ + "functions", + "prelude", + "unsafe-coerce" + ] + }, + "refs": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-KKD5G9dR2SauuDGULUJsxjqDOEi1Jqm+2Sq5U2mY8YU=", + "dependencies": [ + "effect", + "prelude" + ] + }, + "safe-coerce": { + "type": "registry", + "version": "2.0.0", + "integrity": "sha256-EJrxtKt5xC7TYjBZrSBO/J7Aw3DmtilYjt4olpAXWVc=", + "dependencies": [ + "unsafe-coerce" + ] + }, + "st": { + "type": "registry", + "version": "6.2.0", + "integrity": "sha256-WI4MEkkwUd4pnwZQ3G8VKWgX5t1RSNJludm5e9boaRo=", + "dependencies": [ + "effect", + "partial", + "prelude", + "tailrec", + "unsafe-coerce" + ] + }, + "strings": { + "type": "registry", + "version": "6.0.1", + "integrity": "sha256-FNto2hoNW5Da6W6crIk77YXMagBvOGHZE1kO7eZ1vLM=", + "dependencies": [ + "arrays", + "control", + "either", + "enums", + "foldable-traversable", + "gen", + "integers", + "maybe", + "newtype", + "nonempty", + "partial", + "prelude", + "tailrec", + "tuples", + "unfoldable", + "unsafe-coerce" + ] + }, + "tailrec": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-xrorCfP0xV1wubs27idQCHQqdvSUuqmmL/am7Ji1wVU=", + "dependencies": [ + "bifunctors", + "effect", + "either", + "identity", + "maybe", + "partial", + "prelude", + "refs" + ] + }, + "transformers": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-QJmgNT/y7ljPHSsXaW4zxF/982BFiQ90KNL1g/NtEOQ=", + "dependencies": [ + "control", + "distributive", + "effect", + "either", + "exceptions", + "foldable-traversable", + "identity", + "lazy", + "maybe", + "newtype", + "prelude", + "st", + "tailrec", + "tuples", + "unfoldable" + ] + }, + "tuples": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-BKy7EfK8S1KeTCwyWqyW1wwcpSAQuh3IsczSVgS6fzY=", + "dependencies": [ + "control", + "invariant", + "prelude" + ] + }, + "type-equality": { + "type": "registry", + "version": "4.0.1", + "integrity": "sha256-BBqYOSnAKmayRvR5mtZoCf4SlYs2ipatD/+5nQx73aw=", + "dependencies": [] + }, + "uint": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-MCTYyDPFLoNLweSY1oEjKKo0xhqCGrAbiBQNdva1B3w=", + "dependencies": [ + "enums", + "gen", + "maybe", + "numbers", + "prelude" + ] + }, + "unfoldable": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-BK/6By1sKp/ztk+9CF3q43SV0QDTLVdsGqFerKHSmbg=", + "dependencies": [ + "foldable-traversable", + "maybe", + "partial", + "prelude", + "tuples" + ] + }, + "unsafe-coerce": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-0L1QsaY20OILjfU5TV72d3U/tSjhmL9hJ32WMp857Lk=", + "dependencies": [] + } + } +} diff --git a/spago.yaml b/spago.yaml new file mode 100644 index 0000000..33e6321 --- /dev/null +++ b/spago.yaml @@ -0,0 +1,37 @@ +package: + name: arraybuffer + description: Bindings and implementation for mutable JavaScript ArrayBuffers + publish: + version: 13.2.1 + license: MIT + location: + githubOwner: purescript-contrib + githubRepo: purescript-arraybuffer + build: + strict: true + dependencies: + - arraybuffer-types: ">=3.0.2 <4.0.0" + - arrays: ">=7.2.0 <8.0.0" + - effect: ">=4.0.0 <5.0.0" + - float32: ">=2.0.0 <3.0.0" + - functions: ">=6.0.0 <7.0.0" + - gen: ">=4.0.0 <5.0.0" + - maybe: ">=6.0.0 <7.0.0" + - nullable: ">=6.0.0 <7.0.0" + - prelude: ">=6.0.1 <7.0.0" + - tailrec: ">=6.1.0 <7.0.0" + - uint: ">=7.0.0 <8.0.0" + - unfoldable: ">=6.0.0 <7.0.0" + test: + main: Test.Main + dependencies: + - console + - foldable-traversable + - partial + - refs + - tuples + - quickcheck + - quickcheck-laws +workspace: + packageSet: + registry: 81.4.0 diff --git a/src/Data/ArrayBuffer/ArrayBuffer.js b/src/Data/ArrayBuffer/ArrayBuffer.js index f0ef661..9bb2fc1 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.js +++ b/src/Data/ArrayBuffer/ArrayBuffer.js @@ -1,36 +1,13 @@ -"use strict"; - // module Data.ArrayBuffer.ArrayBuffer -exports.create = function(s) { - return function() { +export function emptyImpl(s) { return new ArrayBuffer(s); - }; -} - -exports.byteLength = function(a) { - return a.byteLength; -} - -exports.sliceImpl = function(s, e, a) { - return function() { - return a.slice(s,e); - } -} +}; -exports.fromArray = function(s) { - return function() { - return (new Uint8Array(s)).buffer; - } +export function byteLength(a) { + return a.byteLength; } -exports.fromString = function(s) { - return function() { - var l = s.length; - var ab = new ArrayBuffer(l * 2); - var a = new Uint16Array(ab); - for (var i = 0; i < l; i++) - a[i] = s.charCodeAt(i); - return ab; - } +export function sliceImpl(a, s, e) { + return a.slice(s, e); } diff --git a/src/Data/ArrayBuffer/ArrayBuffer.purs b/src/Data/ArrayBuffer/ArrayBuffer.purs index 39b9e1c..fecb62b 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.purs +++ b/src/Data/ArrayBuffer/ArrayBuffer.purs @@ -1,26 +1,27 @@ -module Data.ArrayBuffer.ArrayBuffer where +-- | This module represents the functional bindings to JavaScript's `ArrayBuffer` +-- | objects. See [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) for details. +module Data.ArrayBuffer.ArrayBuffer + ( empty + , byteLength + , slice + ) where -import Control.Monad.Eff (Eff) -import Data.Function.Uncurried (Fn3, runFn3) import Data.ArrayBuffer.Types (ArrayBuffer, ByteOffset, ByteLength) - -foreign import data ARRAYBUFFER :: ! +import Data.Function.Uncurried (Fn3, runFn3) +import Effect (Effect) +import Effect.Uncurried (EffectFn1, runEffectFn1) -- | Create an `ArrayBuffer` with the given capacity. -foreign import create :: forall e. ByteLength -> Eff (arraybuffer :: ARRAYBUFFER | e) ArrayBuffer +empty :: ByteLength -> Effect ArrayBuffer +empty l = runEffectFn1 emptyImpl l + +foreign import emptyImpl :: EffectFn1 ByteLength ArrayBuffer -- | Represents the length of an `ArrayBuffer` in bytes. foreign import byteLength :: ArrayBuffer -> ByteLength -foreign import sliceImpl :: forall e. Fn3 ByteOffset ByteOffset ArrayBuffer (Eff (arraybuffer :: ARRAYBUFFER | e) ArrayBuffer) - -- | Returns a new `ArrayBuffer` whose contents are a copy of this ArrayBuffer's bytes from begin, inclusive, up to end, exclusive. -slice :: forall e. ByteOffset -> ByteOffset -> ArrayBuffer -> Eff (arraybuffer :: ARRAYBUFFER | e) ArrayBuffer -slice = runFn3 sliceImpl - --- | Convert an array into an `ArrayBuffer` representation. -foreign import fromArray :: forall e. Array Number -> Eff (arraybuffer :: ARRAYBUFFER | e) ArrayBuffer - --- | Convert a string into an `ArrayBuffer` representation. -foreign import fromString :: forall e. String -> Eff (arraybuffer :: ARRAYBUFFER | e) ArrayBuffer +slice :: ByteOffset -> ByteOffset -> ArrayBuffer -> ArrayBuffer +slice s e a = runFn3 sliceImpl a s e +foreign import sliceImpl :: Fn3 ArrayBuffer ByteOffset ByteOffset ArrayBuffer diff --git a/src/Data/ArrayBuffer/ArrayBuffer/Gen.purs b/src/Data/ArrayBuffer/ArrayBuffer/Gen.purs new file mode 100644 index 0000000..381931c --- /dev/null +++ b/src/Data/ArrayBuffer/ArrayBuffer/Gen.purs @@ -0,0 +1,10 @@ +module Data.ArrayBuffer.ArrayBuffer.Gen where + +import Control.Monad.Gen.Class (class MonadGen) +import Data.ArrayBuffer.Typed (buffer) +import Data.ArrayBuffer.Typed.Gen (genTypedArray, genUint8) +import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array) +import Prelude ((<$>)) + +genArrayBuffer :: forall m. MonadGen m => m ArrayBuffer +genArrayBuffer = buffer <$> (genTypedArray genUint8 :: m Uint8Array) diff --git a/src/Data/ArrayBuffer/Cast.purs b/src/Data/ArrayBuffer/Cast.purs new file mode 100644 index 0000000..10e5b0a --- /dev/null +++ b/src/Data/ArrayBuffer/Cast.purs @@ -0,0 +1,46 @@ +-- | `DataView` represents unaligned memory of unknown endianness. +-- | +-- | `ArrayView` represents arrays of aligned elements of +-- | local-machine endianness. +-- | For the cases of `Int8Array`, `Uint8Array`, `Uint8ClampedArray`, +-- | the elements +-- | are single bytes, so they are always aligned and they have no +-- | endianness. Therefore in those cases we can freely cast back and forth +-- | to `DataView`. +module Data.ArrayBuffer.Cast + ( fromInt8Array + , fromUint8Array + , fromUint8ClampedArray + , toInt8Array + , toUint8Array + , toUint8ClampedArray + ) where + +import Data.ArrayBuffer.DataView as DV +import Data.ArrayBuffer.Typed as AT +import Data.ArrayBuffer.Types (DataView, Uint8Array, Uint8ClampedArray, Int8Array) +import Effect (Effect) + +-- | Cast an `Int8Array` to a `DataView`. +fromInt8Array :: Int8Array -> Effect DataView +fromInt8Array x = DV.part (AT.buffer x) (AT.byteOffset x) (AT.byteLength x) + +-- | Cast a `DataView` to an `Int8Array`. +toInt8Array :: DataView -> Effect Int8Array +toInt8Array x = AT.part (DV.buffer x) (DV.byteOffset x) (DV.byteLength x) + +-- | Cast a `UInt8Array` to a `DataView`. +fromUint8Array :: Uint8Array -> Effect DataView +fromUint8Array x = DV.part (AT.buffer x) (AT.byteOffset x) (AT.byteLength x) + +-- | Cast a `DataView` to a `Uint8Array`. +toUint8Array :: DataView -> Effect Uint8Array +toUint8Array x = AT.part (DV.buffer x) (DV.byteOffset x) (DV.byteLength x) + +-- | Cast a `UInt8ClampedArray` to a `DataView`. +fromUint8ClampedArray :: Uint8ClampedArray -> Effect DataView +fromUint8ClampedArray x = DV.part (AT.buffer x) (AT.byteOffset x) (AT.byteLength x) + +-- | Cast a `DataView` to a `Uint8ClampedArray`. +toUint8ClampedArray :: DataView -> Effect Uint8ClampedArray +toUint8ClampedArray x = AT.part (DV.buffer x) (DV.byteOffset x) (DV.byteLength x) diff --git a/src/Data/ArrayBuffer/DataView.js b/src/Data/ArrayBuffer/DataView.js index c88f679..1eeb060 100644 --- a/src/Data/ArrayBuffer/DataView.js +++ b/src/Data/ArrayBuffer/DataView.js @@ -1,49 +1,41 @@ -"use strict"; - // module Data.ArrayBuffer.DataView -exports.whole = function(b) { - return function() { +export function whole(b) { return new DataView(b); - }; } -exports.sliceImpl = function(just, nothing, s, l, b) { - return function() { - return s + l <= b.byteLength? just(new DataView(b, s, l)) : nothing; - }; +export function remainderImpl(b, i) { + return new DataView(b,i); +} + +export function partImpl(b, i, j) { + return new DataView(b,i,j); } -exports.buffer = function(v) { - return v.buffer; +export function buffer(v) { + return v.buffer; } -exports.byteOffset = function(v) { - return v.byteOffset; +export function byteOffset(v) { + return v.byteOffset; } -exports.byteLength = function(v) { - return v.byteLength; +export function byteLength(v) { + return v.byteLength; } -exports.getterImpl = function(just, nothing, s, l, e, v, o) { - return function() { - return (o + l) <= v.byteLength? just(v[s].call(v,o,e)) : nothing; - }; +export function getterImpl(data, v, o) { + return ((o + data.bytesPerValue) >>> 0) <= v.byteLength + ? v[data.functionName].call(v,o,data.littleEndian) + : null; } -exports.setter = function(s) { - return function(e) { - return function(v) { - var f = v[s]; - return function(n) { - return function(o) { - return function() { - f.call(v,o,n,e); - }; - }; - }; - }; - }; +export function setterImpl(data, v, o, n) { + if (((o + data.bytesPerValue) >>> 0) <= v.byteLength) { + v[data.functionName].call(v,o,n,data.littleEndian); + return true; + } else { + return false; + } } diff --git a/src/Data/ArrayBuffer/DataView.purs b/src/Data/ArrayBuffer/DataView.purs index 3c6a720..badab60 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -1,62 +1,83 @@ -module Data.ArrayBuffer.DataView( whole - , slice - , buffer - , byteOffset - , byteLength - , Getter() - , getInt8 - , getInt16be - , getInt32be - , getUint8 - , getUint16be - , getUint32be - , getFloat32be - , getFloat64be - , getInt16le - , getInt32le - , getUint16le - , getUint32le - , getFloat32le - , getFloat64le - , Setter() - , setInt8 - , setInt16be - , setInt32be - , setUint8 - , setUint16be - , setUint32be - , setFloat32be - , setFloat64be - , setInt16le - , setInt32le - , setUint16le - , setUint32le - , setFloat32le - , setFloat64le - ) where - -import Prelude -import Data.ArrayBuffer.Types (ByteOffset, DataView, ByteLength, ArrayBuffer) -import Data.ArrayBuffer.ArrayBuffer(ARRAYBUFFER) -import Data.Function.Uncurried (Fn5, Fn7, runFn5, runFn7) -import Data.Maybe (Maybe(..)) -import Control.Monad.Eff (Eff) +-- | This module represents the functional bindings to JavaScript's `DataView` +-- | objects. See [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) for details. +module Data.ArrayBuffer.DataView + ( Endian(..) + , buffer + , byteLength + , byteOffset + , get + , getBE + , getFloat32be + , getFloat32le + , getFloat64be + , getFloat64le + , getInt16be + , getInt16le + , getInt32be + , getInt32le + , getInt8 + , getLE + , getUint16be + , getUint16le + , getUint32be + , getUint32le + , getUint8 + , part + , remainder + , set + , setBE + , setFloat32be + , setFloat32le + , setFloat64be + , setFloat64le + , setInt16be + , setInt16le + , setInt32be + , setInt32le + , setInt8 + , setLE + , setUint16be + , setUint16le + , setUint32be + , setUint32le + , setUint8 + , whole + ) where + +import Data.ArrayBuffer.Types (ArrayBuffer, ByteLength, ByteOffset, DataView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8) +import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerType, class ShowArrayViewType, byteWidth) +import Data.Float32 (Float32) as F +import Data.Maybe (Maybe) +import Data.Nullable (Nullable, toMaybe) +import Data.Symbol (class IsSymbol, reflectSymbol) import Data.UInt (UInt) +import Effect (Effect) +import Effect.Uncurried (EffectFn2, EffectFn3, EffectFn4, runEffectFn2, runEffectFn3, runEffectFn4) +import Prelude (class Eq, (<$>), (<>), (==)) +import Type.Proxy (Proxy(..)) --- | Type for all fetching functions. -type Getter r = forall e. DataView -> ByteOffset -> Eff (arraybuffer :: ARRAYBUFFER | e) (Maybe r) +-- | Endianness of a multi-byte type. Little-Endian or Big-Endian. +data Endian = LE | BE --- | Type for all storing functions. -type Setter r = forall e. DataView -> r -> ByteOffset -> Eff (arraybuffer :: ARRAYBUFFER | e) Unit +instance eqEndian :: Eq Endian where + eq LE LE = true + eq BE BE = true + eq _ _ = false -- | View mapping the whole `ArrayBuffer`. -foreign import whole :: forall e. ArrayBuffer -> Eff (arraybuffer :: ARRAYBUFFER | e) DataView +foreign import whole :: ArrayBuffer -> DataView -foreign import sliceImpl :: forall e. Fn5 (DataView -> Maybe DataView) (Maybe DataView) ByteOffset ByteLength ArrayBuffer (Eff (arraybuffer :: ARRAYBUFFER | e) (Maybe DataView)) +-- | View mapping the rest of an `ArrayBuffer` after an index. +remainder :: ArrayBuffer -> ByteOffset -> Effect DataView +remainder a o = runEffectFn2 remainderImpl a o + +foreign import remainderImpl :: EffectFn2 ArrayBuffer ByteOffset DataView -- | View mapping a region of the `ArrayBuffer`. -slice :: forall e. ByteOffset -> ByteLength -> ArrayBuffer -> Eff (arraybuffer :: ARRAYBUFFER | e) (Maybe DataView) -slice = runFn5 sliceImpl Just Nothing +part :: ArrayBuffer -> ByteOffset -> ByteLength -> Effect DataView +part a o l = runEffectFn3 partImpl a o l + +foreign import partImpl :: EffectFn3 ArrayBuffer ByteOffset ByteLength DataView -- | `ArrayBuffer` being mapped by the view. foreign import buffer :: DataView -> ArrayBuffer @@ -67,115 +88,266 @@ foreign import byteOffset :: DataView -> ByteOffset -- | Represents the length of this view. foreign import byteLength :: DataView -> ByteLength - -type Endianness = Boolean - -foreign import getterImpl :: forall e r. Fn7 (r -> Maybe r) (Maybe r) String ByteLength Endianness DataView ByteOffset (Eff (arraybuffer :: ARRAYBUFFER | e) (Maybe r)) - -getter :: forall e r. String -> ByteLength -> Endianness -> DataView -> ByteOffset -> Eff (arraybuffer :: ARRAYBUFFER | e) (Maybe r) -getter = runFn7 getterImpl Just Nothing - - -foreign import setter :: forall e r. String -> Endianness -> DataView -> r -> ByteOffset -> Eff (arraybuffer :: ARRAYBUFFER | e) Unit - +getter + :: forall t + . { functionName :: String + , bytesPerValue :: ByteLength + , littleEndian :: Boolean + } + -> DataView + -> ByteOffset + -> Effect (Maybe t) +getter data' dataView offset = + toMaybe <$> runEffectFn3 getterImpl + { functionName: data'.functionName + , littleEndian: data'.littleEndian + , bytesPerValue: data'.bytesPerValue + } + dataView + offset + +foreign import getterImpl + :: forall t + . EffectFn3 + { functionName :: String + , littleEndian :: Boolean + , bytesPerValue :: ByteLength + } + DataView + ByteOffset + (Nullable t) + +get + :: forall a name t + . BinaryValue a t + => BytesPerType a + => ShowArrayViewType a name + => IsSymbol name + => Endian + -> Proxy a + -> DataView + -> ByteOffset + -> Effect (Maybe t) +get endian prx = do + let + le = endian == LE + pnm = "get" <> reflectSymbol (Proxy :: Proxy name) + bpv = byteWidth prx + + getter + { functionName: pnm + , bytesPerValue: bpv + , littleEndian: le + } + +getBE + :: forall a name t + . BinaryValue a t + => BytesPerType a + => ShowArrayViewType a name + => IsSymbol name + => Proxy a + -> DataView + -> ByteOffset + -> Effect (Maybe t) +getBE = get BE + +getLE + :: forall a name t + . BinaryValue a t + => BytesPerType a + => ShowArrayViewType a name + => IsSymbol name + => Proxy a + -> DataView + -> ByteOffset + -> Effect (Maybe t) +getLE = get LE + +setter + :: forall t + . { functionName :: String + , bytesPerValue :: ByteLength + , littleEndian :: Boolean + } + -> DataView + -> ByteOffset + -> t + -> Effect Boolean +setter dataView offset t = runEffectFn4 setterImpl dataView offset t + +foreign import setterImpl + :: forall t + . EffectFn4 + { functionName :: String + , littleEndian :: Boolean + , bytesPerValue :: ByteLength + } + DataView + ByteOffset + t + Boolean + +set + :: forall a name t + . BinaryValue a t + => BytesPerType a + => ShowArrayViewType a name + => IsSymbol name + => Endian + -> Proxy a + -> DataView + -> ByteOffset + -> t + -> Effect Boolean +set endian prx = do + let + le = endian == LE + pnm = "set" <> reflectSymbol (Proxy :: Proxy name) + bpv = byteWidth prx + + setter + { functionName: pnm + , bytesPerValue: bpv + , littleEndian: le + } -- | Fetch int8 value at a certain index in a `DataView`. -getInt8 :: Getter Int -getInt8 = getter "getInt8" 1 false +getInt8 :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt8 = getLE (Proxy :: Proxy Int8) --- | Fetch int16 value at a certain index in a `DataView`. -getInt16be :: Getter Int -getInt16be = getter "getInt16" 2 false +-- | Fetch big-endian int16 value at a certain index in a `DataView`. +getInt16be :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt16be = getBE (Proxy :: Proxy Int16) -getInt16le :: Getter Int -getInt16le = getter "getInt16" 2 true +-- | Fetch little-endian int16 value at a certain index in a `DataView`. +getInt16le :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt16le = getLE (Proxy :: Proxy Int16) --- | Fetch int32 value at a certain index in a `DataView`. -getInt32be :: Getter Int -getInt32be = getter "getInt32" 4 false +-- | Fetch big-endian int32 value at a certain index in a `DataView`. +getInt32be :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt32be = getBE (Proxy :: Proxy Int32) -getInt32le :: Getter Int -getInt32le = getter "getInt32" 4 true +-- | Fetch little-endian int32 value at a certain index in a `DataView`. +getInt32le :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt32le = getLE (Proxy :: Proxy Int32) -- | Fetch uint8 value at a certain index in a `DataView`. -getUint8 :: Getter Int -getUint8 = getter "getUint8" 1 false - --- | Fetch uint16 value at a certain index in a `DataView`. -getUint16be :: Getter Int -getUint16be = getter "getUint16" 2 false - -getUint16le :: Getter Int -getUint16le = getter "getUint16" 2 true - --- | Fetch uint32 value at a certain index in a `DataView`. -getUint32be :: Getter UInt -getUint32be = getter "getUint32" 4 false - -getUint32le :: Getter UInt -getUint32le = getter "getUint32" 4 true - --- | Fetch float32 value at a certain index in a `DataView`. -getFloat32be :: Getter Number -getFloat32be = getter "getFloat32" 4 false - -getFloat32le :: Getter Number -getFloat32le = getter "getFloat32" 4 true - --- | Fetch float64 value at a certain index in a `DataView`. -getFloat64be :: Getter Number -getFloat64be = getter "getFloat64" 8 false - -getFloat64le :: Getter Number -getFloat64le = getter "getFloat64" 8 true +getUint8 :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint8 = getLE (Proxy :: Proxy Uint8) + +-- | Fetch big-endian uint16 value at a certain index in a `DataView`. +getUint16be :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint16be = getBE (Proxy :: Proxy Uint16) + +-- | Fetch little-endian uint16 value at a certain index in a `DataView`. +getUint16le :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint16le = getLE (Proxy :: Proxy Uint16) + +-- | Fetch big-endian uint32 value at a certain index in a `DataView`. +getUint32be :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint32be = getBE (Proxy :: Proxy Uint32) + +-- | Fetch little-endian uint32 value at a certain index in a `DataView`. +getUint32le :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint32le = getLE (Proxy :: Proxy Uint32) + +-- | Fetch big-endian float32 value at a certain index in a `DataView`. +getFloat32be :: DataView -> ByteOffset -> Effect (Maybe F.Float32) +getFloat32be = getBE (Proxy :: Proxy Float32) + +-- | Fetch little-endian float32 value at a certain index in a `DataView`. +getFloat32le :: DataView -> ByteOffset -> Effect (Maybe F.Float32) +getFloat32le = getLE (Proxy :: Proxy Float32) + +-- | Fetch big-endian float64 value at a certain index in a `DataView`. +getFloat64be :: DataView -> ByteOffset -> Effect (Maybe Number) +getFloat64be = getBE (Proxy :: Proxy Float64) + +-- | Fetch little-endian float64 value at a certain index in a `DataView`. +getFloat64le :: DataView -> ByteOffset -> Effect (Maybe Number) +getFloat64le = getLE (Proxy :: Proxy Float64) + +-- | Store big-endian value at a certain index in a `DataView`. +setBE + :: forall a name t + . BinaryValue a t + => BytesPerType a + => ShowArrayViewType a name + => IsSymbol name + => Proxy a + -> DataView + -> ByteOffset + -> t + -> Effect Boolean +setBE = set BE + +-- | Store little-endian value at a certain index in a `DataView`. +setLE + :: forall a name t + . BinaryValue a t + => BytesPerType a + => ShowArrayViewType a name + => IsSymbol name + => Proxy a + -> DataView + -> ByteOffset + -> t + -> Effect Boolean +setLE = set LE -- | Store int8 value at a certain index in a `DataView`. -setInt8 :: Setter Int -setInt8 = setter "setInt8" false +setInt8 :: DataView -> ByteOffset -> Int -> Effect Boolean +setInt8 = setLE (Proxy :: Proxy Int8) --- | Store int16 value at a certain index in a `DataView`. -setInt16be :: Setter Int -setInt16be = setter "setInt16" false +-- | Store big-endian int16 value at a certain index in a `DataView`. +setInt16be :: DataView -> ByteOffset -> Int -> Effect Boolean +setInt16be = setBE (Proxy :: Proxy Int16) -setInt16le :: Setter Int -setInt16le = setter "setInt16" true +-- | Store little-endian int16 value at a certain index in a `DataView`. +setInt16le :: DataView -> ByteOffset -> Int -> Effect Boolean +setInt16le = setLE (Proxy :: Proxy Int16) --- | Store int32 value at a certain index in a `DataView`. -setInt32be :: Setter Int -setInt32be = setter "setInt32" false +-- | Store big-endian int32 value at a certain index in a `DataView`. +setInt32be :: DataView -> ByteOffset -> Int -> Effect Boolean +setInt32be = setBE (Proxy :: Proxy Int32) -setInt32le :: Setter Int -setInt32le = setter "setInt32" true +-- | Store little-endian int32 value at a certain index in a `DataView`. +setInt32le :: DataView -> ByteOffset -> Int -> Effect Boolean +setInt32le = setLE (Proxy :: Proxy Int32) -- | Store uint8 value at a certain index in a `DataView`. -setUint8 :: Setter Int -setUint8 = setter "setUint8" false - --- | Store uint16 value at a certain index in a `DataView`. -setUint16be :: Setter Int -setUint16be = setter "setUint16" false +setUint8 :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint8 = setLE (Proxy :: Proxy Uint8) -setUint16le :: Setter Int -setUint16le = setter "setUint16" true +-- | Store big-endian uint16 value at a certain index in a `DataView`. +setUint16be :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint16be = setBE (Proxy :: Proxy Uint16) --- | Store uint32 value at a certain index in a `DataView`. -setUint32be :: Setter UInt -setUint32be = setter "setUint32" false +-- | Store little-endian uint16 value at a certain index in a `DataView`. +setUint16le :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint16le = setLE (Proxy :: Proxy Uint16) -setUint32le :: Setter UInt -setUint32le = setter "setUint32" true +-- | Store big-endian uint32 value at a certain index in a `DataView`. +setUint32be :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint32be = setBE (Proxy :: Proxy Uint32) --- | Store float32 value at a certain index in a `DataView`. -setFloat32be :: Setter Number -setFloat32be = setter "setFloat32" false +-- | Store little-endian uint32 value at a certain index in a `DataView`. +setUint32le :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint32le = setLE (Proxy :: Proxy Uint32) -setFloat32le :: Setter Number -setFloat32le = setter "setFloat32" true +-- | Store big-endian float32 value at a certain index in a `DataView`. +setFloat32be :: DataView -> ByteOffset -> F.Float32 -> Effect Boolean +setFloat32be = setBE (Proxy :: Proxy Float32) --- | Store float64 value at a certain index in a `DataView`. -setFloat64be :: Setter Number -setFloat64be = setter "setFloat64" false +-- | Store little-endian float32 value at a certain index in a `DataView`. +setFloat32le :: DataView -> ByteOffset -> F.Float32 -> Effect Boolean +setFloat32le = setLE (Proxy :: Proxy Float32) -setFloat64le :: Setter Number -setFloat64le = setter "setFloat64" true +-- | Store big-endian float64 value at a certain index in a `DataView`. +setFloat64be :: DataView -> ByteOffset -> Number -> Effect Boolean +setFloat64be = setBE (Proxy :: Proxy Float64) +-- | Store little-endian float64 value at a certain index in a `DataView`. +setFloat64le :: DataView -> ByteOffset -> Number -> Effect Boolean +setFloat64le = setLE (Proxy :: Proxy Float64) diff --git a/src/Data/ArrayBuffer/DataView/Gen.purs b/src/Data/ArrayBuffer/DataView/Gen.purs new file mode 100644 index 0000000..cd1c974 --- /dev/null +++ b/src/Data/ArrayBuffer/DataView/Gen.purs @@ -0,0 +1,37 @@ +module Data.ArrayBuffer.DataView.Gen where + +import Control.Monad.Gen (suchThat) +import Control.Monad.Gen.Class (class MonadGen, chooseInt) +import Control.Monad.Rec.Class (class MonadRec) +import Data.ArrayBuffer.ArrayBuffer.Gen (genArrayBuffer) +import Data.ArrayBuffer.DataView (whole, byteLength) +import Data.ArrayBuffer.Types (DataView, ByteOffset, ArrayViewType) +import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerType, byteWidth) +import Data.Unfoldable (replicateA) +import Prelude ((<$>), bind, (<=), (-), pure) +import Type.Proxy (Proxy(..)) + +genDataView :: forall m. MonadGen m => m DataView +genDataView = whole <$> genArrayBuffer + +-- | For generating some set of offsets residing inside the generated array, with some computable value +data WithOffsetAndValue (a :: ArrayViewType) t = + WithOffsetAndValue (Array ByteOffset) t DataView + +genWithOffsetAndValue + :: forall m a t + . MonadGen m + => MonadRec m + => BytesPerType a + => BinaryValue a t + => Int -- generated length + -> m DataView -- ^ Assumes generated length is at least the minimum length of one value + -> m t + -> m (WithOffsetAndValue a t) +genWithOffsetAndValue n gen genT = do + let b = byteWidth (Proxy :: Proxy a) + xs <- gen `suchThat` \xs -> b <= byteLength xs + let l = byteLength xs + os <- replicateA n (chooseInt 0 (l - b)) + t <- genT + pure (WithOffsetAndValue os t xs) diff --git a/src/Data/ArrayBuffer/Show.js b/src/Data/ArrayBuffer/Show.js deleted file mode 100644 index 44eab29..0000000 --- a/src/Data/ArrayBuffer/Show.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; - -// module Show - -exports.showImpl = function(a) { - return require('util').inspect(a); -} diff --git a/src/Data/ArrayBuffer/Show.purs b/src/Data/ArrayBuffer/Show.purs deleted file mode 100644 index c22eccf..0000000 --- a/src/Data/ArrayBuffer/Show.purs +++ /dev/null @@ -1,18 +0,0 @@ -module Data.ArrayBuffer.Show where - --- import Prelude -import Data.ArrayBuffer.Types (ArrayView) --- import Data.ArrayBuffer.ArrayBuffer as AB --- import Data.ArrayBuffer.DataView as DV --- import Data.ArrayBuffer.Typed as T - --- instance showArrayView :: Show (ArrayView a) where --- show = showImpl --- --- instance showDataView :: Show DataView where --- show = show <<< T.asInt8Array --- --- instance showArrayBuffer :: Show ArrayBuffer where --- show = show <<< DV.whole --- -foreign import showImpl :: forall a. ArrayView a -> String diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index 230741a..fc19771 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -1,97 +1,162 @@ -"use strict"; - // module Data.ArrayBuffer.Typed -exports.asInt8Array = function(v) { - return function() { - return new Int8Array(v.buffer, v.byteOffset, v.byteLength); - }; +export function buffer(v) { + return v.buffer; } -exports.asInt16Array = function(v) { - return function() { - return new Int16Array(v.buffer, v.byteOffset, v.byteLength >>> 1); - }; +export function byteOffset(v) { + return v.byteOffset; } -exports.asInt32Array = function(v) { - return function() { - return new Int32Array(v.buffer, v.byteOffset, v.byteLength >>> 2); - }; +export function byteLength(v) { + return v.byteLength; } -exports.asUint8Array = function(v) { - return function() { - return new Uint8Array(v.buffer, v.byteOffset, v.byteLength); +export function lengthImpl(v) { + return v.length; +}; + + +// Typed Arrays + + +function newArray (f) { + return function newArray_ (a,mb,mc) { + if (mb === null) + return new f(a); + var l = a.byteLength; + var eb = f.BYTES_PER_ELEMENT; + var off = Math.min(l, mb>>>0); + if (mc === null) + return new f(a,off); + var len = Math.min((l - off) / eb, mc); + return new f(a,off,len); }; } -exports.asUint16Array = function(v) { - return function() { - return new Uint16Array(v.buffer, v.byteOffset, v.byteLength >>> 1); - }; +export const newUint8ClampedArray = newArray(Uint8ClampedArray); +export const newUint32Array = newArray(Uint32Array); +export const newUint16Array = newArray(Uint16Array); +export const newUint8Array = newArray(Uint8Array); +export const newInt32Array = newArray(Int32Array); +export const newInt16Array = newArray(Int16Array); +export const newInt8Array = newArray(Int8Array); +export const newFloat32Array = newArray(Float32Array); +export const newFloat64Array = newArray(Float64Array); + +// ------ + +export function everyImpl(a, p) { + return a.every(p); } -exports.asUint32Array = function(v) { - return function() { - return new Uint32Array(v.buffer, v.byteOffset, v.byteLength >>> 2); - }; +export function someImpl(a, p) { + return a.some(p); } -exports.asUint8ClampedArray = function(v) { - return function() { - return new Uint8ClampedArray(v.buffer, v.byteOffset, v.byteLength); - }; +export function fillImpl(x, s, e, a) { + return a.fill(x,s,e); } -exports.asFloat32Array = function(v) { - return function() { - return new Float32Array(v.buffer, v.byteOffset, v.byteLength >>> 2); - }; +export function mapImpl(a, f) { + return a.map(f); } -exports.asFloat64Array = function(v) { - return function() { - return new Float64Array(v.buffer, v.byteOffset, v.byteLength >>> 3); - } +export function forEachImpl(a, f) { + a.forEach(f); } -exports.dataView = function(a) { - return a; +export function filterImpl(a, p) { + return a.filter(p); } -exports.setImpl = function(ra, off, a) { - return function() { - a.set(ra, off); - }; +export function includesImpl(a, x, mo) { + return mo === null ? a.includes(x) : a.includes(x,mo); } -exports.unsafeAtImpl = function(a, i) { - return function() { - return a[i]; - }; +export function reduceImpl(a, f, i) { + return a.reduce(f,i); } -exports.hasIndexImpl = function(a, i) { - return i in a; +export function reduce1Impl(a, f) { + return a.reduce(f); } -exports.toArray = function(a) { - return function() { - var l = a.length; - var ret = new Array(l); - for (var i = 0; i < l; i++) - ret[i] = a[i]; - return ret; - }; +export function reduceRightImpl(a, f, i) { + return a.reduceRight(f,i); +} + +export function reduceRight1Impl(a, f) { + return a.reduceRight(f); +} + +export function findImpl(a, f) { + return a.find(f); +} + +export function findIndexImpl(a, f) { + var r = a.findIndex(f); + return r === -1 ? null : r; +} + +export function indexOfImpl(a, x, mo) { + var r = mo === null ? a.indexOf(x) : a.indexOf(x,mo); + return r === -1 ? null : r; +} + +export function lastIndexOfImpl(a, x, mo) { + var r = mo === null ? a.lastIndexOf(x) : a.lastIndexOf(x,mo); + return r === -1 ? null : r; +} + +export function copyWithinImpl(a, t, s, me) { + if (me === null) { + a.copyWithin(t,s); + } else { + a.copyWithin(t,s,me); + } } -exports.toIntArray = function(a) { - return function() { +export function reverseImpl(a) { + a.reverse(); +} + +export function setImpl(a, off, b) { + a.set(b,off); +} + +export function sliceImpl(a, s, e) { + return a.slice(s,e); +} + +export function sortImpl(a) { + a.sort(); +} + +export function subArrayImpl(a, s, e) { + return a.subarray(s, e); +} + +export function toStringImpl(a) { + return a.toString(); +} + +export function joinImpl(a, s) { + return a.join(s); +} + +export function unsafeAtImpl(a, i) { + return a[i]; +} + +export function hasIndexImpl(a, i) { + return i in a; +} + +export function toArrayImpl(a) { var l = a.length; var ret = new Array(l); for (var i = 0; i < l; i++) - ret[i] = a[i]|0; + ret[i] = a[i]; return ret; - }; } diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 6001770..e46132d 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -1,88 +1,476 @@ -module Data.ArrayBuffer.Typed( asInt8Array - , asInt16Array - , asInt32Array - , asUint8Array - , asUint16Array - , asUint32Array - , asUint8ClampedArray - , asFloat32Array - , asFloat64Array - , dataView - , set - , unsafeAt - , hasIndex - , at - , toArray - , toIntArray - ) where +-- | This module represents the functional bindings to JavaScript's `TypedArray` and other +-- | objects. See [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) for details. +-- | +-- | #### Creation +-- | +-- | - `whole`, `remainder`, and `part` are functions for building a typed array accessible interface +-- | on top of an existing `ArrayBuffer` +-- | - `empty` and `fromArray` are functions for creating pure typed arrays +-- | +-- | #### Modification +-- | +-- | - `fill`, `set`, and `setTyped` are functions for assigning values from external sources +-- | - `map` and `traverse` allow you to create a new array from the existing values in another +-- | - `copyWithin` allows you to set values to the array that exist in other parts of the array +-- | - `filter` creates a new array without the values that don't pass a predicate +-- | - `reverse` modifies an existing array in-place, with all values reversed +-- | - `sort` modifies an existing array in-place, with all values sorted +-- | +-- | #### Access +-- | +-- | - `elem`, `all`, and `any` are functions for testing the contents of an array +-- | - `unsafeAt`, `hasIndex`, and `at` are used to get values from an array, with an index +-- | - `foldr`, `foldrM`, `foldr1`, `foldr1M`, `foldl`, `foldlM`, `foldl1`, `foldl1M` all can reduce an array +-- | - `find` and `findIndex` are searching functions via a predicate +-- | - `indexOf` and `lastIndexOf` are searching functions via equality +-- | - `slice` returns a new typed array with a new copied underlying `ArrayBuffer` +-- | - `subArray` returns a new typed array view of the same `ArrayBuffer` +-- | - `toString` prints to a CSV, `join` allows you to supply the delimiter +-- | - `toArray` returns an array of numeric values -import Prelude -import Data.ArrayBuffer.Types (ArrayView, ByteOffset, DataView, Float64Array, Float32Array, Uint8ClampedArray, Uint32Array, Uint16Array, Uint8Array, Int32Array, Int16Array, Int8Array) -import Data.ArrayBuffer.ArrayBuffer(ARRAYBUFFER) -import Data.Function.Uncurried (Fn2, Fn3, runFn2, runFn3) -import Data.Maybe (Maybe(..)) -import Control.Monad.Eff (Eff) +module Data.ArrayBuffer.Typed + ( Index + , Length + , buffer + , byteOffset + , byteLength + , length + , compare + , eq + , class TypedArray + , create + , whole + , remainder + , part + , empty + , fromArray + , fill + , set + , setTyped + , copyWithin + , map + , traverse + , traverse_ + , filter + , mapWithIndex + , traverseWithIndex + , traverseWithIndex_ + , filterWithIndex + , sort + , reverse + , elem + , all + , any + , allWithIndex + , anyWithIndex + , unsafeAt + , hasIndex + , at + , (!) + , reduce + , reduce1 + , foldl + , foldl1 + , reduceRight + , reduceRight1 + , foldr + , foldr1 + , foldlWithIndex + , foldrWithIndex + , find + , findIndex + , findWithIndex + , indexOf + , lastIndexOf + , slice + , subArray + , toString + , join + , toArray + ) where --- | Create typed int8 array viewing the buffer mapped by the `DataView` -foreign import asInt8Array :: forall e. DataView -> Eff (arraybuffer :: ARRAYBUFFER | e) Int8Array +import Data.Array (length) as A +import Data.ArrayBuffer.Types (ArrayView, ArrayViewType, ArrayBuffer, ByteOffset, ByteLength, Float64Array, Float32Array, Uint8ClampedArray, Uint32Array, Uint16Array, Uint8Array, Int32Array, Int16Array, Int8Array, Float64, Float32, Uint8Clamped, Uint32, Uint16, Uint8, Int32, Int16, Int8) +import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerType, byteWidth) +import Data.Float32 (Float32) as F +import Data.Function.Uncurried (Fn2, Fn3, mkFn2, runFn2, runFn3) +import Data.Maybe (Maybe, fromMaybe) +import Data.Nullable (Nullable, notNull, null, toMaybe, toNullable) +import Data.UInt (UInt) +import Effect (Effect) +import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4, mkEffectFn2, mkEffectFn3, runEffectFn1, runEffectFn2, runEffectFn3, runEffectFn4) +import Effect.Unsafe (unsafePerformEffect) +import Prelude (class Eq, class Ord, Ordering, Unit, flip, pure, ($), (&&), (*), (*>), (-), (<$>), (<*>), (<<<), (<=), (>=)) +import Prelude as Prelude +import Type.Proxy (Proxy(..)) --- | Create typed int16 array viewing the buffer mapped by the `DataView` -foreign import asInt16Array :: forall e. DataView -> Eff (arraybuffer :: ARRAYBUFFER | e) Int16Array +-- | `ArrayBuffer` being mapped by the typed array. +foreign import buffer :: forall a. ArrayView a -> ArrayBuffer --- | Create typed int32 array viewing the buffer mapped by the `DataView` -foreign import asInt32Array :: forall e. DataView -> Eff (arraybuffer :: ARRAYBUFFER | e) Int32Array +-- | Represents the offset of this view from the start of its `ArrayBuffer`. +foreign import byteOffset :: forall a. ArrayView a -> ByteOffset --- | Create typed uint8 array viewing the buffer mapped by the `DataView` -foreign import asUint8Array :: forall e. DataView -> Eff (arraybuffer :: ARRAYBUFFER | e) Uint8Array +-- | Represents the length of this typed array, in bytes. +foreign import byteLength :: forall a. ArrayView a -> ByteLength --- | Create typed uint16 array viewing the buffer mapped by the `DataView` -foreign import asUint16Array :: forall e. DataView -> Eff (arraybuffer :: ARRAYBUFFER | e) Uint16Array +-- | Represents the number of elements in this typed array. +length :: forall a. ArrayView a -> Length +length = lengthImpl --- | Create typed uint32 array viewing the buffer mapped by the `DataView` -foreign import asUint32Array :: forall e. DataView -> Eff (arraybuffer :: ARRAYBUFFER | e) Uint32Array +foreign import lengthImpl :: forall a. ArrayView a -> Length --- | Create typed uint8 clamped array viewing the buffer mapped by the `DataView` -foreign import asUint8ClampedArray :: forall e. DataView -> Eff (arraybuffer :: ARRAYBUFFER | e) Uint8ClampedArray +-- object creator implementations for each typed array --- | Create typed float32 array viewing the buffer mapped by the `DataView` -foreign import asFloat32Array :: forall e. DataView -> Eff (arraybuffer :: ARRAYBUFFER | e) Float32Array +foreign import newUint8ClampedArray :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint8ClampedArray +foreign import newUint32Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint32Array +foreign import newUint16Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint16Array +foreign import newUint8Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint8Array +foreign import newInt32Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Int32Array +foreign import newInt16Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Int16Array +foreign import newInt8Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Int8Array +foreign import newFloat32Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Float32Array +foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Float64Array --- | Create typed float64 array viewing the buffer mapped by the `DataView` -foreign import asFloat64Array :: forall e. DataView -> Eff (arraybuffer :: ARRAYBUFFER | e) Float64Array +-- | Value-oriented array index. +type Index = Int +-- | Value-oriented array length. +type Length = Int --- | Interpret typed array as a `DataView`. -foreign import dataView :: forall a. ArrayView a -> DataView +class BinaryValue a t <= TypedArray (a :: ArrayViewType) (t :: Type) | a -> t where + create :: forall x. EffectFn3 x (Nullable ByteOffset) (Nullable ByteLength) (ArrayView a) -foreign import setImpl :: forall a e. Fn3 (ArrayView a) ByteOffset (ArrayView a) (Eff (arraybuffer :: ARRAYBUFFER | e) Unit) +instance typedArrayUint8Clamped :: TypedArray Uint8Clamped UInt where + create = newUint8ClampedArray --- | Stores multiple values in the last typed array, reading input values from ther first typed array. -set :: forall a e. ArrayView a -> ByteOffset -> ArrayView a -> Eff (arraybuffer :: ARRAYBUFFER | e) Unit -set = runFn3 setImpl +instance typedArrayUint32 :: TypedArray Uint32 UInt where + create = newUint32Array -foreign import unsafeAtImpl :: forall a e. Fn2 (ArrayView a) Int (Eff (arraybuffer :: ARRAYBUFFER | e) Number) +instance typedArrayUint16 :: TypedArray Uint16 UInt where + create = newUint16Array + +instance typedArrayUint8 :: TypedArray Uint8 UInt where + create = newUint8Array + +instance typedArrayInt32 :: TypedArray Int32 Int where + create = newInt32Array + +instance typedArrayInt16 :: TypedArray Int16 Int where + create = newInt16Array + +instance typedArrayInt8 :: TypedArray Int8 Int where + create = newInt8Array + +instance typedArrayFloat32 :: TypedArray Float32 F.Float32 where + create = newFloat32Array + +instance typedArrayFloat64 :: TypedArray Float64 Number where + create = newFloat64Array + +-- | View mapping the whole `ArrayBuffer`. +whole :: forall a t. TypedArray a t => ArrayBuffer -> Effect (ArrayView a) +whole a = runEffectFn3 create a null null + +-- | View mapping the rest of an `ArrayBuffer` after an index. +remainder :: forall a b t. TypedArray a t => BytesPerType b => ArrayBuffer -> Index -> Effect (ArrayView a) +remainder a x = remainder' a o + where + o = x * byteWidth (Proxy :: Proxy b) + +remainder' :: forall a t. TypedArray a t => ArrayBuffer -> ByteOffset -> Effect (ArrayView a) +remainder' a x = runEffectFn3 create a (notNull x) null + +-- | View mapping a region of the `ArrayBuffer`. +part :: forall a t. TypedArray a t => BytesPerType a => ArrayBuffer -> Index -> Length -> Effect (ArrayView a) +part a x y = part' a o y + where + o = x * byteWidth (Proxy :: Proxy a) + +-- | The ByteOffset must be aligned. +-- | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#byteoffset_must_be_aligned +part' :: forall a t. TypedArray a t => ArrayBuffer -> ByteOffset -> Length -> Effect (ArrayView a) +part' a x y = runEffectFn3 create a (notNull x) (notNull y) + +-- | Creates an empty typed array, where each value is assigned 0. +empty :: forall a t. TypedArray a t => Length -> Effect (ArrayView a) +empty n = runEffectFn3 create n null null + +-- | Creates a typed array from an input array of values, to be binary serialized. +fromArray :: forall a t. TypedArray a t => Array t -> Effect (ArrayView a) +fromArray a = runEffectFn3 create a null null + +-- | Fill the array with a value. +fill :: forall a t. TypedArray a t => t -> Index -> Index -> ArrayView a -> Effect Unit +fill x s e a = runEffectFn4 fillImpl x s e a + +foreign import fillImpl :: forall a b. EffectFn4 b Index Index (ArrayView a) Unit + +-- | Stores multiple values into the typed array. +set :: forall a t. TypedArray a t => ArrayView a -> Maybe Index -> Array t -> Effect Boolean +set = setInternal A.length + +ap1 :: forall a b c. (a -> c) -> (a -> b -> c) +ap1 f = \x _ -> f x + +-- | Maps a new value over the typed array, creating a new `ArrayBuffer` and +-- | typed array as well. +map :: forall a t. TypedArray a t => (t -> t) -> ArrayView a -> ArrayView a +map = mapWithIndex' <<< ap1 + +-- | Apply a function to each element in an array, supplying a +-- | generated zero-based index integer along with the element, +-- | creating a typed array with the new elements. +mapWithIndex :: forall a t. TypedArray a t => (Index -> t -> t) -> ArrayView a -> ArrayView a +mapWithIndex = mapWithIndex' <<< flip + +mapWithIndex' :: forall a t. TypedArray a t => (t -> Index -> t) -> ArrayView a -> ArrayView a +mapWithIndex' f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 \x o -> pure (f x o))) + +foreign import mapImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Index b) (ArrayView a) + +-- | Traverses over each value, returning a new one. +traverse :: forall a t. TypedArray a t => (t -> Effect t) -> ArrayView a -> Effect (ArrayView a) +traverse = traverseWithIndex' <<< ap1 + +-- | Traverses over each value, returning a new one. +traverseWithIndex :: forall a t. TypedArray a t => (Index -> t -> Effect t) -> ArrayView a -> Effect (ArrayView a) +traverseWithIndex = traverseWithIndex' <<< flip + +traverseWithIndex' :: forall a t. TypedArray a t => (t -> Index -> Effect t) -> ArrayView a -> Effect (ArrayView a) +traverseWithIndex' f a = runEffectFn2 mapImpl a (mkEffectFn2 f) + +-- | Traverses over each value. +traverse_ :: forall a t. TypedArray a t => (t -> Effect Unit) -> ArrayView a -> Effect Unit +traverse_ = traverseWithIndex_' <<< ap1 + +-- | Traverses over each value. +traverseWithIndex_ :: forall a t. TypedArray a t => (Index -> t -> Effect Unit) -> ArrayView a -> Effect Unit +traverseWithIndex_ = traverseWithIndex_' <<< flip + +traverseWithIndex_' :: forall a t. TypedArray a t => (t -> Index -> Effect Unit) -> ArrayView a -> Effect Unit +traverseWithIndex_' f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) + +foreign import forEachImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Index Unit) Unit + +-- | Test a predicate to pass on all values. +all :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean +all = every <<< ap1 + +-- | Test a predicate to pass on all values. The predicate function +-- | receives the index and the element. +allWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect Boolean +allWithIndex = every <<< flip + +every :: forall a t. TypedArray a t => (t -> Index -> Boolean) -> ArrayView a -> Effect Boolean +every p a = runEffectFn2 everyImpl a (mkFn2 p) + +foreign import everyImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Index Boolean) Boolean + +-- | Test a predicate to pass on any value. +any :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean +any = some <<< ap1 + +-- | Test a predicate (that receives also an index) to pass on any value. +anyWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect Boolean +anyWithIndex = some <<< flip + +some :: forall a t. TypedArray a t => (t -> Index -> Boolean) -> ArrayView a -> Effect Boolean +some p a = runEffectFn2 someImpl a (mkFn2 p) + +foreign import someImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Index Boolean) Boolean + +-- | Returns a new typed array with all values that pass the predicate. +filter :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (ArrayView a) +filter = filterWithIndex' <<< ap1 + +-- | Returns a new typed array with all values that pass the +-- | predicate. The predicate function receives the index and the +-- | element. +filterWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect (ArrayView a) +filterWithIndex = filterWithIndex' <<< flip + +filterWithIndex' :: forall a t. TypedArray a t => (t -> Index -> Boolean) -> ArrayView a -> Effect (ArrayView a) +filterWithIndex' p a = runEffectFn2 filterImpl a (mkFn2 p) + +foreign import filterImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Index Boolean) (ArrayView a) + +-- | Tests if a value is an element of the typed array. +elem :: forall a t. TypedArray a t => t -> Maybe Index -> ArrayView a -> Effect Boolean +elem x mo a = runEffectFn3 includesImpl a x (toNullable mo) + +foreign import includesImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Index) Boolean -- | Fetch element at index. -unsafeAt :: forall a e. ArrayView a -> Int -> Eff (arraybuffer :: ARRAYBUFFER | e) Number -unsafeAt = runFn2 unsafeAtImpl +unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Index -> Effect t +unsafeAt a o = runEffectFn2 unsafeAtImpl a o + +-- | Folding from the left. +reduce :: forall a t b. TypedArray a t => (b -> t -> Index -> Effect b) -> b -> ArrayView a -> Effect b +reduce f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i -foreign import hasIndexImpl :: forall a. Fn2 (ArrayView a) Int Boolean +foreign import reduceImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Index c) c c + +-- | Folding from the left. Assumes the typed array is non-empty. +reduce1 :: forall a t. Partial => TypedArray a t => (t -> t -> Index -> Effect t) -> ArrayView a -> Effect t +reduce1 f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) + +foreign import reduce1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Index b) b + +-- | Folding from the right. +reduceRight :: forall a t b. TypedArray a t => (t -> b -> Index -> Effect b) -> b -> ArrayView a -> Effect b +reduceRight f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 \acc x o -> f x acc o) i + +foreign import reduceRightImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Index c) c c + +-- | Folding from the right. Assumes the typed array is non-empty. +reduceRight1 :: forall a t. Partial => TypedArray a t => (t -> t -> Index -> Effect t) -> ArrayView a -> Effect t +reduceRight1 f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 \acc x o -> f x acc o) + +foreign import reduceRight1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Index b) b + +-- | Returns the first value satisfying the predicate. +find :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (Maybe t) +find = findWithIndex' <<< ap1 + +-- | Returns the first value satisfying the predicate. The predicate +-- | receives the index and the element at that index. +findWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect (Maybe t) +findWithIndex = findWithIndex' <<< flip + +findWithIndex' :: forall a t. TypedArray a t => (t -> Index -> Boolean) -> ArrayView a -> Effect (Maybe t) +findWithIndex' f a = toMaybe <$> runEffectFn2 findImpl a (mkFn2 f) + +foreign import findImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Index Boolean) (Nullable b) + +-- | Returns the first index of the value satisfying the predicate. +findIndex :: forall a t. TypedArray a t => (t -> Index -> Boolean) -> ArrayView a -> Effect (Maybe Index) +findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkFn2 f) + +foreign import findIndexImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Index Boolean) (Nullable Index) + +-- | Returns the first index of the element, if it exists, from the left. +indexOf :: forall a t. TypedArray a t => t -> Maybe Index -> ArrayView a -> Effect (Maybe Index) +indexOf x mo a = toMaybe <$> runEffectFn3 indexOfImpl a x (toNullable mo) + +foreign import indexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Index) (Nullable Index) + +-- | Returns the first index of the element, if it exists, from the right. +lastIndexOf :: forall a t. TypedArray a t => t -> Maybe Index -> ArrayView a -> Effect (Maybe Index) +lastIndexOf x mo a = toMaybe <$> runEffectFn3 lastIndexOfImpl a x (toNullable mo) + +foreign import lastIndexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Index) (Nullable Index) + +-- | Fold a list from the left, accumulating the result using the +-- | specified function. +foldl :: forall a b t. TypedArray a t => (b -> t -> b) -> b -> ArrayView a -> Effect b +foldl f = reduce \a x _ -> pure $ f a x + +-- | Fold a list from the left, accumulating the result using the +-- | supplied function. The accumulating function receives the index, +-- | the accumulated value and the element. +foldlWithIndex :: forall a b t. TypedArray a t => (Index -> b -> t -> b) -> b -> ArrayView a -> Effect b +foldlWithIndex f = reduce \a x o -> pure $ f o a x + +-- | Fold a list from the right, accumulating the result using the +-- | specified function. +foldr :: forall a b t. TypedArray a t => (t -> b -> b) -> b -> ArrayView a -> Effect b +foldr f = reduceRight \a x _ -> pure $ f a x + +-- | Fold a list from the right, accumulating the result using the +-- | supplied function. The accumulating function receives the index, +-- | the element and the accumulated value. +foldrWithIndex :: forall a b t. TypedArray a t => (Index -> t -> b -> b) -> b -> ArrayView a -> Effect b +foldrWithIndex f = reduceRight \a x o -> pure $ f o a x + +-- | Folding from the left. Assumes the typed array is non-empty. +foldl1 :: forall a t. Partial => TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t +foldl1 f = reduce1 \a x _ -> pure $ f a x + +-- | Folding from the right. Assumes the typed array is non-empty. +foldr1 :: forall a t. Partial => TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t +foldr1 f = reduceRight1 \x a _ -> pure $ f a x + +-- | Internally copy values - see [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) for details. +copyWithin :: forall a. ArrayView a -> Index -> Index -> Maybe Index -> Effect Unit +copyWithin a t s me = runEffectFn4 copyWithinImpl a t s (toNullable me) + +foreign import copyWithinImpl :: forall a. EffectFn4 (ArrayView a) Index Index (Nullable Index) Unit + +-- | Reverses a typed array in-place. +reverse :: forall a. ArrayView a -> Effect Unit +reverse a = runEffectFn1 reverseImpl a + +foreign import reverseImpl :: forall a. EffectFn1 (ArrayView a) Unit + +setInternal :: forall a b. (b -> Length) -> ArrayView a -> Maybe Index -> b -> Effect Boolean +setInternal lenfn a mo b = do + let o = fromMaybe 0 mo + if o >= 0 && lenfn b <= length a - o then + runEffectFn3 setImpl a o b *> pure true + else + pure false + +foreign import setImpl :: forall a b. EffectFn3 (ArrayView a) Index b Unit + +-- | Stores multiple values in the typed array, reading input values from the second typed array. +setTyped :: forall a. ArrayView a -> Maybe Index -> ArrayView a -> Effect Boolean +setTyped = setInternal length + +-- | Copy part of the contents of a typed array into a new `ArrayBuffer`, +-- | between the start and end indices. +slice :: forall a. Index -> Index -> ArrayView a -> Effect (ArrayView a) +slice s e a = runEffectFn3 sliceImpl a s e + +foreign import sliceImpl :: forall a. EffectFn3 (ArrayView a) Index Index (ArrayView a) + +-- | Sorts the values in-place. +sort :: forall a. ArrayView a -> Effect Unit +sort a = runEffectFn1 sortImpl a + +foreign import sortImpl :: forall a. EffectFn1 (ArrayView a) Unit + +-- | Returns a new typed array view of the same `ArrayBuffer`, beginning at +-- | the index and ending at the second. +subArray :: forall a. Index -> Index -> ArrayView a -> ArrayView a +subArray s e a = runFn3 subArrayImpl a s e + +foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) Index Index (ArrayView a) + +-- | Prints array to a comma-separated string - see [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toString) for details. +toString :: forall a. ArrayView a -> Effect String +toString a = runEffectFn1 toStringImpl a + +foreign import toStringImpl :: forall a. EffectFn1 (ArrayView a) String + +-- | Prints array to a delimiter-separated string - see [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/join) for details. +join :: forall a. String -> ArrayView a -> Effect String +join s a = runEffectFn2 joinImpl a s + +foreign import joinImpl :: forall a. EffectFn2 (ArrayView a) String String -- | Determine if a certain index is valid. -hasIndex :: forall a. ArrayView a -> Int -> Boolean -hasIndex = runFn2 hasIndexImpl +hasIndex :: forall a. ArrayView a -> Index -> Boolean +hasIndex a o = runFn2 hasIndexImpl a o + +foreign import hasIndexImpl :: forall a. Fn2 (ArrayView a) Index Boolean -- | Fetch element at index. -at :: forall a e. ArrayView a -> Int -> Eff (arraybuffer :: ARRAYBUFFER | e) (Maybe Number) -at a n = if a `hasIndex` n - then do - x <- unsafeAt a n - pure $ Just x - else - pure $ Nothing +at :: forall a t. TypedArray a t => ArrayView a -> Index -> Effect (Maybe t) +at a n = toMaybe <$> runEffectFn2 unsafeAtImpl a n + +foreign import unsafeAtImpl :: forall a b. EffectFn2 (ArrayView a) Index b + +infixl 3 at as ! -- | Turn typed array into an array. -foreign import toArray :: forall a e. ArrayView a -> Eff (arraybuffer :: ARRAYBUFFER | e) (Array Number) +toArray :: forall a t. TypedArray a t => ArrayView a -> Effect (Array t) +toArray a = runEffectFn1 toArrayImpl a + +foreign import toArrayImpl :: forall a b. EffectFn1 (ArrayView a) (Array b) --- | Turn typed array into integer array. -foreign import toIntArray :: forall a e. ArrayView a -> Eff (arraybuffer :: ARRAYBUFFER | e) (Array Int) +-- | Compare 2 typed arrays. +compare :: forall a t. TypedArray a t => Ord t => ArrayView a -> ArrayView a -> Effect Ordering +compare a b = Prelude.compare <$> toArray a <*> toArray b +-- | Equality test for typed arrays. +eq :: forall a t. TypedArray a t => Eq t => ArrayView a -> ArrayView a -> Effect Boolean +eq a b = Prelude.eq <$> toArray a <*> toArray b diff --git a/src/Data/ArrayBuffer/Typed/Gen.purs b/src/Data/ArrayBuffer/Typed/Gen.purs new file mode 100644 index 0000000..b2091ff --- /dev/null +++ b/src/Data/ArrayBuffer/Typed/Gen.purs @@ -0,0 +1,68 @@ +-- | Functions for generating typed arrays and values. +module Data.ArrayBuffer.Typed.Gen where + +import Control.Monad.Gen.Class (class MonadGen, sized, chooseInt, chooseFloat) +import Data.ArrayBuffer.Typed (class TypedArray) +import Data.ArrayBuffer.Typed as TA +import Data.ArrayBuffer.Types (ArrayView) +import Data.ArrayBuffer.ValueMapping (class BytesPerType) +import Data.Float32 (Float32, fromNumber') as F +import Data.UInt (UInt) +import Data.UInt (fromInt) as UInt +import Data.UInt.Gen (genUInt) as UInt +import Data.Unfoldable (replicateA) +import Effect.Unsafe (unsafePerformEffect) +import Prelude (bind, bottom, negate, pure, top, ($), (-), (/), (<$>)) + +genTypedArray + :: forall m a t + . MonadGen m + => TypedArray a t + => m t + -> m (ArrayView a) +genTypedArray gen = sized \s -> do + n <- chooseInt 0 s + a <- replicateA n gen + pure (unsafePerformEffect $ TA.fromArray a) + +genUint8 :: forall m. MonadGen m => m UInt +genUint8 = UInt.fromInt <$> chooseInt 0 255 + +genInt8 :: forall m. MonadGen m => m Int +genInt8 = chooseInt (-128) 127 + +genUint16 :: forall m. MonadGen m => m UInt +genUint16 = UInt.fromInt <$> chooseInt 0 65535 + +genInt16 :: forall m. MonadGen m => m Int +genInt16 = chooseInt (-32768) 32767 + +genUint32 :: forall m. MonadGen m => m UInt +genUint32 = UInt.genUInt bottom top + +genInt32 :: forall m. MonadGen m => m Int +genInt32 = chooseInt bottom top + +genFloat32 :: forall m. MonadGen m => m F.Float32 +genFloat32 = F.fromNumber' <$> chooseFloat (-3.40282347e+38) 3.40282347e+38 + +genFloat64 :: forall m. MonadGen m => m Number +genFloat64 = chooseFloat ((-1.7976931348623157e+308) / div) (1.7976931348623157e+308 / div) + where + div = 4.0 + +-- | For generating some set of offsets residing inside the generated array +data WithIndices a = WithIndices (Array TA.Index) (ArrayView a) + +genWithIndices + :: forall m a + . MonadGen m + => BytesPerType a + => Int -- Number of offsets residing inside the generated array + -> m (ArrayView a) + -> m (WithIndices a) +genWithIndices n gen = do + xs <- gen + let l = TA.length xs + os <- replicateA n (chooseInt 0 (l - 1)) + pure (WithIndices os xs) diff --git a/src/Data/ArrayBuffer/ValueMapping.purs b/src/Data/ArrayBuffer/ValueMapping.purs new file mode 100644 index 0000000..8694a19 --- /dev/null +++ b/src/Data/ArrayBuffer/ValueMapping.purs @@ -0,0 +1,72 @@ +-- | This module represents type-level mappings between `ArrayViewType`s +-- | and meaningful data. +module Data.ArrayBuffer.ValueMapping + ( class BytesPerType + , byteWidth + , class BinaryValue + , class ShowArrayViewType + ) where + +import Data.ArrayBuffer.Types (ArrayViewType, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, Uint8Clamped) +import Data.Float32 (Float32) as F +import Data.UInt (UInt) +import Type.Proxy (Proxy) + +-- | Type-level map of each `ArrayViewType` to the number of bytes of storage +-- | it requires. +class BytesPerType (a :: ArrayViewType) where + byteWidth :: (Proxy a) -> Int + +instance bytesPerTypeInt8 :: BytesPerType Int8 where + byteWidth _ = 1 + +instance bytesPerTypeInt16 :: BytesPerType Int16 where + byteWidth _ = 2 + +instance bytesPerTypeInt32 :: BytesPerType Int32 where + byteWidth _ = 4 + +instance bytesPerTypeUint8 :: BytesPerType Uint8 where + byteWidth _ = 1 + +instance bytesPerTypeUint16 :: BytesPerType Uint16 where + byteWidth _ = 2 + +instance bytesPerTypeUint32 :: BytesPerType Uint32 where + byteWidth _ = 4 + +instance bytesPerTypeUint8Clamped :: BytesPerType Uint8Clamped where + byteWidth _ = 1 + +instance bytesPerTypeFloat32 :: BytesPerType Float32 where + byteWidth _ = 4 + +instance bytesPerTypeFloat64 :: BytesPerType Float64 where + byteWidth _ = 8 + +-- | Type-level map of `TypedArray`’s binary casted value to its +-- | representation in JavaScript. +class BinaryValue (a :: ArrayViewType) (t :: Type) | a -> t + +instance binaryValueUint8Clamped :: BinaryValue Uint8Clamped UInt +instance binaryValueUint32 :: BinaryValue Uint32 UInt +instance binaryValueUint16 :: BinaryValue Uint16 UInt +instance binaryValueUint8 :: BinaryValue Uint8 UInt +instance binaryValueInt32 :: BinaryValue Int32 Int +instance binaryValueInt16 :: BinaryValue Int16 Int +instance binaryValueInt8 :: BinaryValue Int8 Int +instance binaryValueFloat32 :: BinaryValue Float32 F.Float32 +instance binaryValueFloat64 :: BinaryValue Float64 Number + +-- | Type-level map of `TypedArray` to its element type name. +class ShowArrayViewType (a :: ArrayViewType) (name :: Symbol) | a -> name + +instance showArrayViewTypeUint8Clamped :: ShowArrayViewType Uint8Clamped "Uint8Clamped" +instance showArrayViewTypeViewUint32 :: ShowArrayViewType Uint32 "Uint32" +instance showArrayViewTypeViewUint16 :: ShowArrayViewType Uint16 "Uint16" +instance showArrayViewTypeViewUint8 :: ShowArrayViewType Uint8 "Uint8" +instance showArrayViewTypeViewInt32 :: ShowArrayViewType Int32 "Int32" +instance showArrayViewTypeViewInt16 :: ShowArrayViewType Int16 "Int16" +instance showArrayViewTypeViewInt8 :: ShowArrayViewType Int8 "Int8" +instance showArrayViewTypeViewFloat32 :: ShowArrayViewType Float32 "Float32" +instance showArrayViewTypeViewFloat64 :: ShowArrayViewType Float64 "Float64" diff --git a/test/Main.purs b/test/Main.purs index afa1ffd..4ad0759 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,101 +1,12 @@ module Test.Main where import Prelude -import Data.Maybe (Maybe(..)) -import Test.QuickCheck (QC, quickCheck') -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE) -import Control.Monad.Eff.Random (RANDOM) -import Control.Monad.Eff.Exception (EXCEPTION) -import Data.UInt (fromInt, pow) -import Data.ArrayBuffer.ArrayBuffer as AB -import Data.ArrayBuffer.DataView as DV -import Data.ArrayBuffer.Typed as TA -main :: forall e - . Eff ( console :: CONSOLE - , random :: RANDOM - , err :: EXCEPTION - , arraybuffer :: AB.ARRAYBUFFER - | e ) - Unit -main = do - ab4 <- AB.create 4 - assert $ AB.byteLength ab4 == 4 - assert =<< do - abs02 <- AB.slice 0 2 ab4 - pure $ AB.byteLength abs02 == 2 - assert =<< do - abs24 <- AB.slice 2 4 ab4 - pure $ AB.byteLength abs24 == 2 - assert =<< do - absm2m2 <- AB.slice (-2) (-2) ab4 - pure $ AB.byteLength absm2m2 == 0 - assert =<< do - absm2m1 <- AB.slice (-2) (-1) ab4 - pure $ AB.byteLength absm2m1 == 1 - assert =<< do - s02 <- DV.slice 0 2 ab4 - pure $ (DV.byteLength <$> s02) == Just 2 - assert =<< do - s22 <- DV.slice 2 2 ab4 - pure $ (DV.byteLength <$> s22) == Just 2 - aab <- AB.fromArray [1.0, 2.0, 3.0, 4.0] - assert $ AB.byteLength aab == 4 - sab <- AB.fromString "hola" - assert $ AB.byteLength sab == 8 - - nab <- AB.create 8 - dv <- DV.whole nab - assert $ AB.byteLength (DV.buffer dv) == 8 - - assert =<< do - dvi8 <- TA.asInt8Array dv - pure $ AB.byteLength (DV.buffer $ TA.dataView dvi8) == 8 - - assert =<< do - s04 <- DV.slice 0 4 nab - pure $ (DV.byteLength <$> s04) == Just 4 - assert =<< do - s040 <- DV.slice 0 40 nab - pure $ (DV.byteLength <$> s040) == Nothing - - assert =<< do - ab <- AB.fromArray [1.0,2.0,3.0,4.0] - dv <- DV.whole ab - i8 <- TA.asInt8Array dv - a1 <- i8 `TA.at` 1 - a4 <- i8 `TA.at` 4 - am1 <- i8 `TA.at` (-1) - pure $ ((Just 2.0) == a1) && (Nothing == a4) && (Nothing == am1) - - assert =<< do - ab3 <- AB.fromArray [1.0,2.0,3.0] - wab3 <- DV.whole ab3 - wab3i8 <- TA.asInt8Array wab3 - a3 <- TA.toArray wab3i8 - pure $ a3 == [1.0,2.0,3.0] - - ab2 <- AB.create 2 - assert =<< do - dv <- DV.whole ab2 - DV.setUint8 dv 123 0 - DV.setUint8 dv 0 1 - leVal <- DV.getUint16le dv 0 - beVal <- DV.getUint16be dv 0 - pure $ Just 123 == leVal && Just 31488 == beVal - - assert =<< do - ab <- AB.create 4 - dv <- DV.whole ab - DV.setUint8 dv 255 0 - DV.setUint8 dv 255 1 - DV.setUint8 dv 255 2 - DV.setUint8 dv 255 3 - val <- DV.getUint32be dv 0 - let expected = fromInt 2 `pow` fromInt 32 - fromInt 1 - pure $ Just expected == val - -assert :: forall e. Boolean -> QC e Unit -assert = quickCheck' 1 +import Effect (Effect) +import Effect.Console (log) +import Test.Properties (propertiesTests) +main :: Effect Unit +main = do + log "Starting tests..." + propertiesTests diff --git a/test/Properties.purs b/test/Properties.purs new file mode 100644 index 0000000..bb529fc --- /dev/null +++ b/test/Properties.purs @@ -0,0 +1,26 @@ +module Test.Properties where + +import Effect (Effect) +import Effect.Console (log) +import Effect.Ref (new, read) as Ref +import Prelude (Unit, bind, discard, ($), (<>), (*), show) +import Test.Properties.DataView (dataViewTests) +import Test.Properties.TypedArray (typedArrayTests) +import Test.Properties.Typed.Laws (typedArrayLaws) + +propertiesTests :: Effect Unit +propertiesTests = do + do + count <- Ref.new 0 + log " - TypedArray Tests:" + typedArrayTests count + typedArrayLaws count + c <- Ref.read count + log $ " - Verified " <> show c <> " properties, generating " <> show (c * 9 * 100) <> " test cases." + + do + count <- Ref.new 0 + log " - DataView Tests:" + dataViewTests count + c <- Ref.read count + log $ " - Verified " <> show c <> " properties, generating " <> show (c * 16 * 100) <> " test cases." diff --git a/test/Properties/ArrayBuffer.purs b/test/Properties/ArrayBuffer.purs new file mode 100644 index 0000000..8ab6fe4 --- /dev/null +++ b/test/Properties/ArrayBuffer.purs @@ -0,0 +1 @@ +module Test.Properties.ArrayBuffer where diff --git a/test/Properties/DataView.purs b/test/Properties/DataView.purs new file mode 100644 index 0000000..e7199bf --- /dev/null +++ b/test/Properties/DataView.purs @@ -0,0 +1,127 @@ +module Test.Properties.DataView where + +import Prelude + +import Data.Array.Partial (head) as Array +import Data.ArrayBuffer.DataView as DV +import Data.ArrayBuffer.DataView.Gen (genDataView, genWithOffsetAndValue, WithOffsetAndValue(..)) +import Data.ArrayBuffer.Typed.Gen (genFloat32, genFloat64, genInt16, genInt32, genInt8, genUint16, genUint32, genUint8) +import Data.ArrayBuffer.Types (Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8) +import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerType, class ShowArrayViewType) +import Data.Float32 (Float32) as F +import Data.Maybe (Maybe(..)) +import Data.Symbol (class IsSymbol) +import Data.UInt (UInt) +import Effect (Effect) +import Effect.Console (log) +import Effect.Ref (Ref) +import Effect.Ref as Ref +import Effect.Unsafe (unsafePerformEffect) +import Partial.Unsafe (unsafePartial) +import Test.QuickCheck (class Testable, quickCheckGen, Result, (===)) +import Type.Proxy (Proxy(..)) + +dataViewTests :: Ref Int -> Effect Unit +dataViewTests count = do + log " - setBE x o => getBE o === Just x" + placingAValueIsThereTests DV.BE count + log " - setLE x o => getLE o === Just x" + placingAValueIsThereTests DV.LE count + +type TestableViewF a name t q = + Show t + => Eq t + => Ord t + => Semiring t + => BytesPerType a + => BinaryValue a t + => ShowArrayViewType a name + => IsSymbol name + => WithOffsetAndValue a t + -> q + +overAll + :: forall q + . Testable q + => Ref Int + -> (forall a name t. TestableViewF a name t q) + -> Effect Unit +overAll count f = do + void (Ref.modify (_ + 1) count) + log " - Uint32" + quickCheckGen do + let + f' :: TestableViewF Uint32 "Uint32" UInt q + f' = f + + f' <$> genWithOffsetAndValue 4 genDataView genUint32 + + log " - Uint16" + quickCheckGen do + let + f' :: TestableViewF Uint16 "Uint16" UInt q + f' = f + + f' <$> genWithOffsetAndValue 2 genDataView genUint16 + + log " - Uint8" + quickCheckGen do + let + f' :: TestableViewF Uint8 "Uint8" UInt q + f' = f + + f' <$> genWithOffsetAndValue 1 genDataView genUint8 + + log " - Int32" + quickCheckGen do + let + f' :: TestableViewF Int32 "Int32" Int q + f' = f + + f' <$> genWithOffsetAndValue 4 genDataView genInt32 + + log " - Int16" + quickCheckGen do + let + f' :: TestableViewF Int16 "Int16" Int q + f' = f + + f' <$> genWithOffsetAndValue 2 genDataView genInt16 + + log " - Int8" + quickCheckGen do + let + f' :: TestableViewF Int8 "Int8" Int q + f' = f + + f' <$> genWithOffsetAndValue 1 genDataView genInt8 + + log " - Float32" + quickCheckGen do + let + f' :: TestableViewF Float32 "Float32" F.Float32 q + f' = f + + f' <$> genWithOffsetAndValue 4 genDataView genFloat32 + + log " - Float64" + quickCheckGen do + let + f' :: TestableViewF Float64 "Float64" Number q + f' = f + + f' <$> genWithOffsetAndValue 8 genDataView genFloat64 + +placingAValueIsThereTests :: DV.Endian -> Ref Int -> Effect Unit +placingAValueIsThereTests endian count = overAll count placingAValueIsThere + where + placingAValueIsThere :: forall a name t. TestableViewF a name t Result + placingAValueIsThere (WithOffsetAndValue os t xs) = do + let + o = unsafePartial $ Array.head os + prx = Proxy :: Proxy a + + unsafePerformEffect do + _ <- DV.set endian prx xs o t + my <- DV.get endian prx xs o + pure (my === Just t) diff --git a/test/Properties/Typed/Laws.purs b/test/Properties/Typed/Laws.purs new file mode 100644 index 0000000..21ac0dd --- /dev/null +++ b/test/Properties/Typed/Laws.purs @@ -0,0 +1,149 @@ +module Test.Properties.Typed.Laws where + +import Prelude +import Data.ArrayBuffer.Typed (class TypedArray, toString) +import Data.ArrayBuffer.Typed.Gen (genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8) +import Data.ArrayBuffer.Types (ArrayView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, Uint8Clamped, ArrayViewType) +import Data.Float32 as F +import Data.UInt (UInt) +import Effect (Effect) +import Effect.Ref (Ref) +import Effect.Ref as Ref +import Test.QuickCheck (class Arbitrary, arbitrary) +import Test.QuickCheck.Gen (Gen) +import Test.QuickCheck.Laws.Data (checkEq, checkMonoid, checkOrd, checkSemigroup) +import Type.Proxy (Proxy(..)) +import Data.ArrayBuffer.Typed as TA +import Data.Generic.Rep (class Generic) +import Data.Maybe (Maybe(..)) +import Effect.Unsafe (unsafePerformEffect) + +newtype A a = A a + +foreign import data ArrayElt :: ArrayViewType -> Type -> Type + +class ArrayEl (a :: ArrayViewType) (t :: Type) where + arb :: Proxy (ArrayView a) -> Gen t + +instance arrayElUint8Clamped :: ArrayEl Uint8Clamped UInt where + arb _ = genUint8 + +instance arrayElUint32 :: ArrayEl Uint32 UInt where + arb _ = genUint32 + +instance arrayElUint16 :: ArrayEl Uint16 UInt where + arb _ = genUint16 + +instance arrayElUint8 :: ArrayEl Uint8 UInt where + arb _ = genUint8 + +instance arrayElInt32 :: ArrayEl Int32 Int where + arb _ = genInt32 + +instance arrayElInt16 :: ArrayEl Int16 Int where + arb _ = genInt16 + +instance arrayElInt8 :: ArrayEl Int8 Int where + arb _ = genInt8 + +instance arrayElFloat32 :: ArrayEl Float32 F.Float32 where + arb _ = genFloat32 + +instance arrayElFloat64 :: ArrayEl Float64 Number where + arb _ = genFloat64 + +instance arbitraryAAV :: (TypedArray a t, ArrayEl a t) => Arbitrary (A (AV a t)) where + arbitrary = (A <<< AV) <$> genTypedArray (arb (Proxy :: Proxy (ArrayView a))) + +derive newtype instance eqA :: Eq t => Eq (A t) +derive newtype instance ordA :: Ord t => Ord (A t) +derive newtype instance semigroupA :: Semigroup t => Semigroup (A t) +derive newtype instance monoidA :: Monoid t => Monoid (A t) + +typedArrayLaws :: Ref Int -> Effect Unit +typedArrayLaws count = do + do + let f = checkEq + void $ Ref.modify (_ + 1) count + f (Proxy :: Proxy (A (AV Float32 F.Float32))) + f (Proxy :: Proxy (A (AV Float64 Number))) + f (Proxy :: Proxy (A (AV Int16 Int))) + f (Proxy :: Proxy (A (AV Int32 Int))) + f (Proxy :: Proxy (A (AV Int8 Int))) + f (Proxy :: Proxy (A (AV Uint16 UInt))) + f (Proxy :: Proxy (A (AV Uint32 UInt))) + f (Proxy :: Proxy (A (AV Uint8 UInt))) + f (Proxy :: Proxy (A (AV Uint8Clamped UInt))) + + do + let f = checkOrd + void $ Ref.modify (_ + 1) count + f (Proxy :: Proxy (A (AV Float32 F.Float32))) + f (Proxy :: Proxy (A (AV Float64 Number))) + f (Proxy :: Proxy (A (AV Int16 Int))) + f (Proxy :: Proxy (A (AV Int32 Int))) + f (Proxy :: Proxy (A (AV Int8 Int))) + f (Proxy :: Proxy (A (AV Uint16 UInt))) + f (Proxy :: Proxy (A (AV Uint32 UInt))) + f (Proxy :: Proxy (A (AV Uint8 UInt))) + f (Proxy :: Proxy (A (AV Uint8Clamped UInt))) + + do + let f = checkSemigroup + void $ Ref.modify (_ + 1) count + f (Proxy :: Proxy (A (AV Float32 F.Float32))) + f (Proxy :: Proxy (A (AV Float64 Number))) + f (Proxy :: Proxy (A (AV Int16 Int))) + f (Proxy :: Proxy (A (AV Int32 Int))) + f (Proxy :: Proxy (A (AV Int8 Int))) + f (Proxy :: Proxy (A (AV Uint16 UInt))) + f (Proxy :: Proxy (A (AV Uint32 UInt))) + f (Proxy :: Proxy (A (AV Uint8 UInt))) + f (Proxy :: Proxy (A (AV Uint8Clamped UInt))) + + do + let f = checkMonoid + void $ Ref.modify (_ + 1) count + f (Proxy :: Proxy (A (AV Float32 F.Float32))) + f (Proxy :: Proxy (A (AV Float64 Number))) + f (Proxy :: Proxy (A (AV Int16 Int))) + f (Proxy :: Proxy (A (AV Int32 Int))) + f (Proxy :: Proxy (A (AV Int8 Int))) + f (Proxy :: Proxy (A (AV Uint16 UInt))) + f (Proxy :: Proxy (A (AV Uint32 UInt))) + f (Proxy :: Proxy (A (AV Uint8 UInt))) + f (Proxy :: Proxy (A (AV Uint8Clamped UInt))) + +newtype AV :: forall k. ArrayViewType -> k -> Type +newtype AV a t = AV (ArrayView a) + +derive instance genericAV :: Generic (AV a t) _ + +instance ordArrayView :: (TypedArray a t, Ord t) => Ord (AV a t) where + compare (AV a) (AV b) = unsafePerformEffect $ TA.compare a b + +instance eqArrayView :: (TypedArray a t, Eq t) => Eq (AV a t) where + eq (AV a) (AV b) = unsafePerformEffect $ TA.eq a b + +instance showArrayView :: (TypedArray a t, Show t) => Show (AV a t) where + show (AV a) = "T[" <> s <> "]" + where + s = unsafePerformEffect $ toString a + +instance semigroupArrayView :: TypedArray a t => Semigroup (AV a t) where + append (AV a) (AV b) = unsafePerformEffect do + let + la = TA.length a + lb = TA.length b + r <- TA.empty $ la + lb + void $ TA.setTyped r (Just 0) a + void $ TA.setTyped r (Just la) b + pure $ AV r + +instance monoidArrayView :: TypedArray a t => Monoid (AV a t) where + mempty = AV $ unsafePerformEffect $ TA.empty 0 + +instance arbitraryArrayView :: (TypedArray a t, Arbitrary t) => Arbitrary (AV a t) where + arbitrary = do + xs <- arbitrary + pure $ unsafePerformEffect $ AV <$> TA.fromArray xs diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs new file mode 100644 index 0000000..36dfc8c --- /dev/null +++ b/test/Properties/TypedArray.purs @@ -0,0 +1,722 @@ +module Test.Properties.TypedArray where + +import Prelude + +import Control.Monad.Gen (suchThat) +import Data.Array (all, cons, drop, length, reverse, slice, snoc, sort, take, unsafeIndex) as Array +import Data.Array.Partial (head) as Array +import Data.ArrayBuffer.Typed (class TypedArray) +import Data.ArrayBuffer.Typed as TA +import Data.ArrayBuffer.Typed.Gen (WithIndices(..), genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8, genWithIndices) +import Data.ArrayBuffer.Types (ArrayView, Float32Array, Float64Array, Int16Array, Int32Array, Int8Array, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray) +import Data.ArrayBuffer.ValueMapping (class BytesPerType, byteWidth) +import Data.Maybe (Maybe(..), fromMaybe, isJust) +import Data.Traversable (traverse) +import Data.Tuple (Tuple(..)) +import Effect (Effect) +import Effect.Console (log) +import Effect.Ref (Ref) +import Effect.Ref as Ref +import Effect.Unsafe (unsafePerformEffect) +import Partial.Unsafe (unsafePartial) +import Test.QuickCheck (class Testable, Result(..), quickCheckGen, (/==), (), (===)) +import Test.QuickCheck.Gen (Gen) +import Type.Proxy (Proxy(..)) + +typedArrayTests :: Ref Int -> Effect Unit +typedArrayTests count = do + log " - subarrayBehavesLikeArraySlice" + subarrayBehavesLikeArraySliceTests count + log " - sliceBehavesLikeArraySlice" + sliceBehavesLikeArraySliceTests count + log " - partBehavesLikeTakeDrop" + partBehavesLikeTakeDropTests count + log " - byteLength x / bytesPerValue === length x" + byteLengthDivBytesPerValueTests count + log " - fromArray (toArray x) === x" + fromArrayToArrayIsoTests count + log " - fill y x => all (== y) x" + allAreFilledTests count + log " - set x [y] o => (at x o == Just y)" + setSingletonIsEqTests count + log " - all p x => any p x" + allImpliesAnyTests count + log " - all p (filter p x)" + filterImpliesAllTests count + log " - filter (not . p) (filter p x) == []" + filterIsTotalTests count + log " - filter p (filter p x) == filter p x" + filterIsIdempotentTests count + log " - forall os `in` xs. all (\\o -> hasIndex o xs)" + withIndicesHasIndexTests count + log " - forall os `in` xs. all (\\o -> elem (at o xs) xs)" + withIndicesElemTests count + log " - any p x => p (find p x)" + anyImpliesFindTests count + log " - p (at x (findIndex p x))" + findIndexImpliesAtTests count + log " - at x (indexOf y x) == y" + indexOfImpliesAtTests count + log " - at x (lastIndexOf y x) == y" + lastIndexOfImpliesAtTests count + log " - foldr cons [] x == toArray x" + foldrConsIsToArrayTests count + log " - foldl snoc [] x == toArray x" + foldlSnocIsToArrayTests count + log " - map identity x == x" + mapIdentityIsIdentityTests count + log " - traverse snoc x == toArray x" + traverseSnocIsToArrayTests count + log " - reverse (reverse x) == x" + doubleReverseIsIdentityTests count + log " - toArray (reverse x) == Array.reverse (toArray x)" + reverseIsArrayReverseTests count + log " - sort (sort x) == sort x" + sortIsIdempotentTests count + log " - toArray (sort x) == Array.sort (toArray x)" + sortIsArraySortTests count + log " - join \",\" x == toString x" + toStringIsJoinWithCommaTests count + log " - setTyped x (subArray x) == x" + setTypedOfSubArrayIsIdentityTests count + log " - let z' = subArray x; q = toArray z'; mutate x; pure q /= toArray z'" + modifyingOriginalMutatesSubArrayTests count + log " - let z' = subArray x; q = toArray x; mutate z'; pure q /= toArray x" + modifyingSubArrayMutatesOriginalTests count + log " - let z' = subArray 0 x; q = toArray z'; mutate x; pure q /= toArray z'" + modifyingOriginalMutatesSubArrayZeroTests count + log " - let z' = subArray 0 x; q = toArray x; mutate z'; pure q /= toArray x" + modifyingSubArrayMutatesOriginalZeroTests count + log " - let z' = subArray 0 (length x) x; q = toArray z'; mutate x; pure q /= toArray z'" + modifyingOriginalMutatesSubArrayAllTests count + log " - let z' = subArray 0 (length x) x; q = toArray x; mutate z'; pure q /= toArray x" + modifyingSubArrayMutatesOriginalAllTests count + log " - let z' = subArray o x; q = toArray z'; mutate x; pure q == toArray z'" + modifyingOriginalMutatesSubArrayPartTests count + log " - let z' = slice x; q = toArray z'; mutate x; pure q == toArray z'" + modifyingOriginalDoesntMutateSliceTests count + log " - let z' = slice o x; q = toArray z'; mutate x; pure q == toArray z'" + modifyingOriginalDoesntMutateSlicePartTests count + log " - let z' = slice 0 o x; q = toArray z'; mutate x; pure q == toArray z'" + modifyingOriginalDoesntMutateSlicePart2Tests count + log " - copyWithin x 0 0 (length x) == x" + copyWithinSelfIsIdentityTests count + log " - take (o + 1) (copyWithin o x) == slice o x" + copyWithinIsSliceTests count + log " - copyWithin o x == setTyped x (slice o x)" + copyWithinViaSetTypedTests count + +type TestableArrayF a t q = + Show t + => Eq t + => Ord t + => Semiring t + => TypedArray a t + => BytesPerType a + => WithIndices a + -> Effect q + +overAll' + :: forall q + . Testable q + => Int -- n + -> Int -- “minimum n”? + -> Ref Int + -> (forall a t. TestableArrayF a t q) + -> Effect Unit +overAll' n mn count f = do + void (Ref.modify (_ + 1) count) + + let + chk + :: forall a t + . Show t + => Eq t + => Ord t + => Semiring t + => BytesPerType a + => TypedArray a t + => String + -> Int + -> Proxy (ArrayView a) + -> Gen t + -> Effect Unit + chk s n' _ gen = do + log $ " - " <> s + quickCheckGen $ unsafePerformEffect <<< f <$> genWithIndices n' arr + where + arr :: Gen (ArrayView a) + arr = genTypedArray gen `suchThat` \xs -> mn <= TA.length xs + + chk "Uint8ClampedArray" n (Proxy :: Proxy Uint8ClampedArray) genUint8 + chk "Uint32Array" n (Proxy :: Proxy Uint32Array) genUint32 + chk "Uint16Array" n (Proxy :: Proxy Uint16Array) genUint16 + chk "Uint8Array" n (Proxy :: Proxy Uint8Array) genUint8 + chk "Int32Array" n (Proxy :: Proxy Int32Array) genInt32 + chk "Int16Array" n (Proxy :: Proxy Int16Array) genInt16 + chk "Int8Array" n (Proxy :: Proxy Int8Array) genInt8 + chk "Float32Array" n (Proxy :: Proxy Float32Array) genFloat32 + chk "Float64Array" n (Proxy :: Proxy Float64Array) genFloat64 + +overAll + :: forall q + . Testable q + => Int + -> Ref Int + -> (forall a t. TestableArrayF a t q) + -> Effect Unit +overAll n count f = overAll' n 0 count f + +overAll1 + :: forall q + . Testable q + => Int + -> Ref Int + -> (forall a t. TestableArrayF a t q) + -> Effect Unit +overAll1 n count f = overAll' n 1 count f + +subarrayBehavesLikeArraySliceTests :: Ref Int -> Effect Unit +subarrayBehavesLikeArraySliceTests count = overAll 2 count f + where + f :: forall a t. TestableArrayF a t Result + f (WithIndices os xs) = do + let + s = unsafePartial $ os `Array.unsafeIndex` 0 + e = unsafePartial $ os `Array.unsafeIndex` 1 + axs <- TA.toArray xs + let sxs = TA.subArray s e xs + a <- TA.toArray sxs + pure $ Array.slice s e axs === a + +sliceBehavesLikeArraySliceTests :: Ref Int -> Effect Unit +sliceBehavesLikeArraySliceTests count = overAll 2 count f + where + f :: forall a t. TestableArrayF a t Result + f (WithIndices os xs) = do + let + s = unsafePartial $ os `Array.unsafeIndex` 0 + e = unsafePartial $ os `Array.unsafeIndex` 1 + axs <- TA.toArray xs + sxs <- TA.slice s e xs + a <- TA.toArray sxs + pure $ Array.slice s e axs === a + +partBehavesLikeTakeDropTests :: Ref Int -> Effect Unit +partBehavesLikeTakeDropTests count = overAll 0 count f + where + f :: forall a t. TestableArrayF a t Result + f (WithIndices _ xs) = do + let n = 2 + axs <- TA.toArray xs + pxs <- TA.part (TA.buffer xs) n n :: Effect (ArrayView a) + aps <- TA.toArray pxs + pure $ Array.take n (Array.drop n axs) === aps + +byteLengthDivBytesPerValueTests :: Ref Int -> Effect Unit +byteLengthDivBytesPerValueTests count = overAll 0 count byteLengthDivBytesPerValueEqLength + where + byteLengthDivBytesPerValueEqLength :: forall a t. TestableArrayF a t Result + byteLengthDivBytesPerValueEqLength (WithIndices _ xs) = do + let b = byteWidth (Proxy :: Proxy a) + pure $ TA.length xs === (TA.byteLength xs `div` b) + +fromArrayToArrayIsoTests :: Ref Int -> Effect Unit +fromArrayToArrayIsoTests count = overAll 0 count fromArrayToArrayIso + where + fromArrayToArrayIso :: forall a t. TestableArrayF a t Result + fromArrayToArrayIso (WithIndices _ xs) = do + axs <- TA.toArray xs + xs' <- TA.fromArray axs :: Effect (ArrayView a) + axs' <- TA.toArray xs' + pure $ axs' === axs + +allAreFilledTests :: Ref Int -> Effect Unit +allAreFilledTests count = overAll 0 count allAreFilled + where + allAreFilled :: forall a t. TestableArrayF a t Result + allAreFilled (WithIndices _ xs) = do + e <- TA.at xs 0 + let + x = fromMaybe zero e + l = TA.length xs + TA.fill x 0 l xs + b <- TA.all (_ == x) xs + pure (b "All aren't the filled value") + +setSingletonIsEqTests :: Ref Int -> Effect Unit +setSingletonIsEqTests count = overAll 1 count setSingletonIsEq + where + setSingletonIsEq :: forall a t. TestableArrayF a t Result + setSingletonIsEq (WithIndices os xs) = do + e <- TA.at xs 0 + case e of + Nothing -> pure Success + Just x -> do + let o = unsafePartial $ Array.head os + _ <- TA.set xs (Just o) [ x ] + e' <- TA.at xs o + pure $ e' === Just x + +-- | Should work with any arbitrary predicate, but we can't generate them +allImpliesAnyTests :: Ref Int -> Effect Unit +allImpliesAnyTests count = overAll 0 count allImpliesAny + where + allImpliesAny :: forall a t. TestableArrayF a t Result + allImpliesAny (WithIndices _ xs) = do + let pred x = x /= zero + all'' <- TA.all pred xs + let all' = all'' "All don't satisfy the predicate" + any'' <- TA.any pred xs + let any' = any'' "None satisfy the predicate" + pure $ (TA.length xs === zero) `xor` all' `implies` any' + +-- | Should work with any arbitrary predicate, but we can't generate them +filterImpliesAllTests :: Ref Int -> Effect Unit +filterImpliesAllTests count = overAll 0 count filterImpliesAll + where + filterImpliesAll :: forall a t. TestableArrayF a t Result + filterImpliesAll (WithIndices _ xs) = do + let pred x = x /= zero + ys <- TA.filter pred xs + all' <- TA.all pred ys + pure $ all' "Filter doesn't imply all" + +-- | Should work with any arbitrary predicate, but we can't generate them +filterIsTotalTests :: Ref Int -> Effect Unit +filterIsTotalTests count = overAll 0 count filterIsTotal + where + filterIsTotal :: forall a t. TestableArrayF a t Result + filterIsTotal (WithIndices _ xs) = do + let pred x = x /= zero + ys <- TA.filter pred xs + zs <- TA.filter (not pred) ys + azs <- TA.toArray zs + pure $ azs === [] + +-- | Should work with any arbitrary predicate, but we can't generate them +filterIsIdempotentTests :: Ref Int -> Effect Unit +filterIsIdempotentTests count = overAll 0 count filterIsIdempotent + where + filterIsIdempotent :: forall a t. TestableArrayF a t Result + filterIsIdempotent (WithIndices _ xs) = do + let pred x = x /= zero + ys <- TA.filter pred xs + zs <- TA.filter pred ys + azs <- TA.toArray zs + ays <- TA.toArray ys + pure $ azs === ays + +withIndicesHasIndexTests :: Ref Int -> Effect Unit +withIndicesHasIndexTests count = overAll1 5 count withIndicesHasIndex + where + withIndicesHasIndex :: forall a t. TestableArrayF a t Result + withIndicesHasIndex (WithIndices os xs) = pure $ + Array.all (TA.hasIndex xs) os "All doesn't have index of itself" + +withIndicesElemTests :: Ref Int -> Effect Unit +withIndicesElemTests count = overAll1 5 count withIndicesElem + where + withIndicesElem :: forall a t. TestableArrayF a t Result + withIndicesElem (WithIndices os xs) = do + let fetch o = TA.at xs o + exs <- traverse fetch os + pure $ Array.all isJust exs "All doesn't have an elem of itself" + +-- | Should work with any arbitrary predicate, but we can't generate them +anyImpliesFindTests :: Ref Int -> Effect Unit +anyImpliesFindTests count = overAll 0 count anyImpliesFind + where + anyImpliesFind :: forall a t. TestableArrayF a t Result + anyImpliesFind (WithIndices _ xs) = do + let pred x = x /= zero + a <- TA.any pred xs + let p = a "All don't satisfy the predicate" + idx <- TA.find pred xs + let + q = case idx of + Nothing -> Failed "Doesn't have a value satisfying the predicate" + Just z -> + if pred z then Success + else Failed "Found value doesn't satisfy the predicate" + pure $ p `implies` q + +-- | Should work with any arbitrary predicate, but we can't generate them +findIndexImpliesAtTests :: Ref Int -> Effect Unit +findIndexImpliesAtTests count = overAll 0 count findIndexImpliesAt + where + findIndexImpliesAt :: forall a t. TestableArrayF a t Result + findIndexImpliesAt (WithIndices _ xs) = do + let pred x _ = x /= zero + mo <- TA.findIndex pred xs + case mo of + Nothing -> pure Success + Just o -> do + e <- TA.at xs o + case e of + Nothing -> pure $ Failed "No value at found index" + Just x -> pure $ pred x o "Find index implies at" + +indexOfImpliesAtTests :: Ref Int -> Effect Unit +indexOfImpliesAtTests count = overAll 1 count indexOfImpliesAt + where + indexOfImpliesAt :: forall a t. TestableArrayF a t Result + indexOfImpliesAt (WithIndices _ xs) = do + e <- TA.at xs 0 + case e of + Nothing -> pure Success + Just y -> do + idx <- TA.indexOf y Nothing xs + case idx of + Nothing -> pure $ Failed "no index of" + Just o -> do + e' <- TA.at xs o + pure $ e' === Just y + +lastIndexOfImpliesAtTests :: Ref Int -> Effect Unit +lastIndexOfImpliesAtTests count = overAll 0 count lastIndexOfImpliesAt + where + lastIndexOfImpliesAt :: forall a t. TestableArrayF a t Result + lastIndexOfImpliesAt (WithIndices _ xs) = do + e <- TA.at xs 0 + case e of + Nothing -> pure Success + Just y -> do + idx <- TA.lastIndexOf y Nothing xs + case idx of + Nothing -> pure $ Failed "no lastIndex of" + Just o -> do + e' <- TA.at xs o + pure $ e' === Just y + +foldrConsIsToArrayTests :: Ref Int -> Effect Unit +foldrConsIsToArrayTests count = overAll 0 count foldrConsIsToArray + where + foldrConsIsToArray :: forall a t. TestableArrayF a t Result + foldrConsIsToArray (WithIndices _ xs) = do + axs <- TA.toArray xs + rxs <- TA.foldr Array.cons [] xs + pure $ rxs === axs + +foldlSnocIsToArrayTests :: Ref Int -> Effect Unit +foldlSnocIsToArrayTests count = overAll 0 count foldlSnocIsToArray + where + foldlSnocIsToArray :: forall a t. TestableArrayF a t Result + foldlSnocIsToArray (WithIndices _ xs) = do + axs <- TA.toArray xs + rxs <- TA.foldl Array.snoc [] xs + pure $ rxs === axs + +mapIdentityIsIdentityTests :: Ref Int -> Effect Unit +mapIdentityIsIdentityTests count = overAll 0 count mapIdentityIsIdentity + where + mapIdentityIsIdentity :: forall a t. TestableArrayF a t Result + mapIdentityIsIdentity (WithIndices _ xs) = do + axs <- TA.toArray xs + mxs <- TA.toArray (TA.map identity xs) + pure $ axs === mxs + +traverseSnocIsToArrayTests :: Ref Int -> Effect Unit +traverseSnocIsToArrayTests count = overAll 0 count traverseSnocIsToArray + where + traverseSnocIsToArray :: forall a t. TestableArrayF a t Result + traverseSnocIsToArray (WithIndices _ xs) = do + ref <- Ref.new [] + TA.traverse_ (\x -> void (Ref.modify (\xs' -> Array.snoc xs' x) ref)) xs + ys <- Ref.read ref + axs <- TA.toArray xs + pure $ axs === ys + +doubleReverseIsIdentityTests :: Ref Int -> Effect Unit +doubleReverseIsIdentityTests count = overAll 0 count doubleReverseIsIdentity + where + doubleReverseIsIdentity :: forall a t. TestableArrayF a t Result + doubleReverseIsIdentity (WithIndices _ xs) = do + axs <- TA.toArray xs + TA.reverse xs + TA.reverse xs + axs' <- TA.toArray xs + pure $ axs === axs' + +reverseIsArrayReverseTests :: Ref Int -> Effect Unit +reverseIsArrayReverseTests count = overAll 0 count reverseIsArrayReverse + where + reverseIsArrayReverse :: forall a t. TestableArrayF a t Result + reverseIsArrayReverse (WithIndices _ xs) = do + axs <- TA.toArray xs + TA.reverse xs + rxs <- TA.toArray xs + pure $ Array.reverse axs === rxs + +sortIsIdempotentTests :: Ref Int -> Effect Unit +sortIsIdempotentTests count = overAll 0 count sortIsIdempotent + where + sortIsIdempotent :: forall a t. TestableArrayF a t Result + sortIsIdempotent (WithIndices _ xs) = do + TA.sort xs + ys <- TA.toArray xs + TA.sort xs + zs <- TA.toArray xs + pure $ zs === ys + +sortIsArraySortTests :: Ref Int -> Effect Unit +sortIsArraySortTests count = overAll 0 count sortIsArraySort + where + sortIsArraySort :: forall a t. TestableArrayF a t Result + sortIsArraySort (WithIndices _ xs) = do + axs <- TA.toArray xs + let ys = Array.sort axs + TA.sort xs + sxs <- TA.toArray xs + pure $ sxs === ys + +toStringIsJoinWithCommaTests :: Ref Int -> Effect Unit +toStringIsJoinWithCommaTests count = overAll 0 count toStringIsJoinWithComma + where + toStringIsJoinWithComma :: forall a t. TestableArrayF a t Result + toStringIsJoinWithComma (WithIndices _ xs) = do + s1 <- TA.join "," xs + s2 <- TA.toString xs + pure $ s1 === s2 + +setTypedOfSubArrayIsIdentityTests :: Ref Int -> Effect Unit +setTypedOfSubArrayIsIdentityTests count = overAll 0 count setTypedOfSubArrayIsIdentity + where + setTypedOfSubArrayIsIdentity :: forall a t. TestableArrayF a t Result + setTypedOfSubArrayIsIdentity (WithIndices _ xs) = do + ys <- TA.toArray xs + let + l = TA.length xs + zsSub = TA.subArray 0 l xs + _ <- TA.setTyped xs Nothing zsSub + zs <- TA.toArray xs + pure $ zs === ys + +modifyingOriginalMutatesSubArrayTests :: Ref Int -> Effect Unit +modifyingOriginalMutatesSubArrayTests count = overAll 0 count modifyingOriginalMutatesSubArray + where + modifyingOriginalMutatesSubArray :: forall a t. TestableArrayF a t Result + modifyingOriginalMutatesSubArray (WithIndices _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs then pure Success + else do + let + l = TA.length xs + zsSub = TA.subArray 0 l xs + zs <- TA.toArray zsSub + TA.fill zero 0 l xs + ys <- TA.toArray zsSub + pure $ zs /== ys + +modifyingSubArrayMutatesOriginalTests :: Ref Int -> Effect Unit +modifyingSubArrayMutatesOriginalTests count = overAll 0 count modifyingOriginalMutatesSubArray + where + modifyingOriginalMutatesSubArray :: forall a t. TestableArrayF a t Result + modifyingOriginalMutatesSubArray (WithIndices _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs then pure Success + else do + let + l = TA.length xs + zsSub = TA.subArray 0 l xs + zs <- TA.toArray xs + TA.fill zero 0 l zsSub + ys <- TA.toArray xs + pure $ zs /== ys + +modifyingOriginalMutatesSubArrayZeroTests :: Ref Int -> Effect Unit +modifyingOriginalMutatesSubArrayZeroTests count = overAll 0 count modifyingOriginalMutatesSubArrayZero + where + modifyingOriginalMutatesSubArrayZero :: forall a t. TestableArrayF a t Result + modifyingOriginalMutatesSubArrayZero (WithIndices _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs then pure Success + else do + let + l = TA.length xs + zsSub = TA.subArray 0 l xs + zs <- TA.toArray zsSub + TA.fill zero 0 l xs + ys <- TA.toArray zsSub + pure $ zs /== ys + +modifyingSubArrayMutatesOriginalZeroTests :: Ref Int -> Effect Unit +modifyingSubArrayMutatesOriginalZeroTests count = overAll 0 count modifyingSubArrayMutatesOriginalZero + where + modifyingSubArrayMutatesOriginalZero :: forall a t. TestableArrayF a t Result + modifyingSubArrayMutatesOriginalZero (WithIndices _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs then pure Success + else do + let + l = TA.length xs + zsSub = TA.subArray 0 l xs + zs <- TA.toArray xs + TA.fill zero 0 l zsSub + ys <- TA.toArray xs + pure $ zs /== ys + +modifyingOriginalMutatesSubArrayAllTests :: Ref Int -> Effect Unit +modifyingOriginalMutatesSubArrayAllTests count = overAll 0 count modifyingOriginalMutatesSubArrayAll + where + modifyingOriginalMutatesSubArrayAll :: forall a t. TestableArrayF a t Result + modifyingOriginalMutatesSubArrayAll (WithIndices _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs then pure Success + else do + let + l = TA.length xs + zsSub = TA.subArray 0 l xs + zs <- TA.toArray zsSub + TA.fill zero 0 l xs + ys <- TA.toArray zsSub + pure $ zs /== ys + +modifyingSubArrayMutatesOriginalAllTests :: Ref Int -> Effect Unit +modifyingSubArrayMutatesOriginalAllTests count = overAll 0 count modifyingSubArrayMutatesOriginalAll + where + modifyingSubArrayMutatesOriginalAll :: forall a t. TestableArrayF a t Result + modifyingSubArrayMutatesOriginalAll (WithIndices _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs then pure Success + else do + let + l = TA.length xs + zsSub = TA.subArray 0 l xs + zs <- TA.toArray xs + TA.fill zero 0 l zsSub + ys <- TA.toArray xs + pure $ zs /== ys + +modifyingOriginalMutatesSubArrayPartTests :: Ref Int -> Effect Unit +modifyingOriginalMutatesSubArrayPartTests count = overAll 1 count modifyingOriginalMutatesSubArrayPart + where + modifyingOriginalMutatesSubArrayPart :: forall a t. TestableArrayF a t Result + modifyingOriginalMutatesSubArrayPart (WithIndices os xs) = do + let + o = unsafePartial $ Array.head os + l = TA.length xs + zsSub = TA.subArray 0 l xs + zs <- TA.toArray zsSub + if o == 0 || Array.all (eq zero) zs then pure Success + else do + TA.fill zero 0 l xs + ys <- TA.toArray zsSub + pure $ zs /== ys + +modifyingOriginalDoesntMutateSliceTests :: Ref Int -> Effect Unit +modifyingOriginalDoesntMutateSliceTests count = overAll 0 count modifyingOriginalDoesntMutateSlice + where + modifyingOriginalDoesntMutateSlice :: forall a t. TestableArrayF a t Result + modifyingOriginalDoesntMutateSlice (WithIndices _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs then pure Success + else do + let l = TA.length xs + zsSub <- TA.slice 0 l xs + zs <- TA.toArray zsSub + TA.fill zero 0 l xs + ys <- TA.toArray zsSub + pure $ zs === ys + +modifyingOriginalDoesntMutateSlicePartTests :: Ref Int -> Effect Unit +modifyingOriginalDoesntMutateSlicePartTests count = overAll 1 count modifyingOriginalDoesntMutateSlicePart + where + modifyingOriginalDoesntMutateSlicePart :: forall a t. TestableArrayF a t Result + modifyingOriginalDoesntMutateSlicePart (WithIndices os xs) = do + let l = TA.length xs + axs <- TA.toArray =<< TA.slice 0 l xs + let o = unsafePartial $ Array.head os + e <- TA.at xs o + if Array.all (eq zero) axs || e == Just zero then pure Success + else do + zsSub <- TA.slice o l xs + zs <- TA.toArray zsSub + TA.fill zero 0 l xs + ys <- TA.toArray zsSub + pure $ zs === ys + +modifyingOriginalDoesntMutateSlicePart2Tests :: Ref Int -> Effect Unit +modifyingOriginalDoesntMutateSlicePart2Tests count = overAll 1 count modifyingOriginalDoesntMutateSlicePart2 + where + modifyingOriginalDoesntMutateSlicePart2 :: forall a t. TestableArrayF a t Result + modifyingOriginalDoesntMutateSlicePart2 (WithIndices os xs) = do + let + o = unsafePartial $ Array.head os + l = TA.length xs + axs <- TA.toArray =<< TA.slice o l xs + e <- TA.at xs o + if Array.all (eq zero) axs || e == Just zero then pure Success + else do + zsSub <- TA.slice o l xs + zs <- TA.toArray zsSub + TA.fill zero 0 l xs + ys <- TA.toArray zsSub + pure $ zs === ys + +copyWithinSelfIsIdentityTests :: Ref Int -> Effect Unit +copyWithinSelfIsIdentityTests count = overAll 0 count copyWithinSelfIsIdentity + where + copyWithinSelfIsIdentity :: forall a t. TestableArrayF a t Result + copyWithinSelfIsIdentity (WithIndices _ xs) = do + ys <- TA.toArray xs + TA.copyWithin xs 0 0 (Just (TA.length xs)) + zs <- TA.toArray xs + pure $ zs === ys + +copyWithinIsSliceTests :: Ref Int -> Effect Unit +copyWithinIsSliceTests count = overAll 1 count copyWithinIsSlice + where + copyWithinIsSlice :: forall a t. TestableArrayF a t Result + copyWithinIsSlice (WithIndices os xs) = do + let + o = unsafePartial $ Array.head os + l = TA.length xs + ys <- TA.toArray =<< TA.slice o l xs + TA.copyWithin xs 0 o Nothing + axs <- TA.toArray xs + zs <- pure $ Array.drop (Array.length ys) axs + pure $ axs === ys <> zs + +copyWithinViaSetTypedTests :: Ref Int -> Effect Unit +copyWithinViaSetTypedTests count = overAll 1 count copyWithinViaSetTyped + where + copyWithinViaSetTyped :: forall a t. TestableArrayF a t Result + copyWithinViaSetTyped (WithIndices os xs) = do + let o = unsafePartial $ Array.head os + txs <- TA.toArray xs + xs' <- TA.fromArray txs :: Effect (ArrayView a) + let l = TA.length xs' + ys <- TA.slice o l xs' + _ <- TA.setTyped xs' Nothing ys + TA.copyWithin xs 0 o Nothing + axs <- TA.toArray xs + axs' <- TA.toArray xs' + pure $ axs === axs' + +-- | Uses the second failure message as the result failure message +-- | https://github.com/athanclark/purescript-quickcheck-combinators/blob/293e5af07ae47b61d4eae5defef4c0f472bfa9ca/src/Test/QuickCheck/Combinators.purs#L62 +implies :: Result -> Result -> Result +implies x y = case y of + Failed y' -> case x of + Success -> Failed ("Implied failure: " <> y') + _ -> Success + _ -> Success + +-- | Combine two results with "Exclusive Or" logic, and with `", xor "` as the failure message separator, and "XOR" as the failure message if they are both `Success` +-- | https://github.com/athanclark/purescript-quickcheck-combinators/blob/293e5af07ae47b61d4eae5defef4c0f472bfa9ca/src/Test/QuickCheck/Combinators.purs#L44 +xor :: Result -> Result -> Result +xor = xor' ", xor " "XOR" + where + -- Combine two results with "Exclusive Or" logic, and with a failure message separator and failure message if they are both `Success` + xor' + :: String -- ^ Separator + -> String -- ^ Success failure message + -> Result + -> Result + -> Result + xor' m s x y = case Tuple x y of + Tuple (Failed x') (Failed y') -> Failed (x' <> m <> y') + Tuple Success Success -> Failed s + Tuple Success y' -> y' + Tuple x' Success -> x'