From 0a80132331463bd32c11443dcb9cc4c5b32d5bf1 Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 21 Jun 2021 12:46:33 +0900 Subject: [PATCH 01/34] Transfer repository to purescript-contrib To transfer the repository, refactor to remove the dependencies on __typelevel__ and __quickcheck-combinators__. Prep for v11. Repair some purs v0.14 warnings. --- .gitignore | 1 + CHANGELOG.md | 22 ++ README.md | 8 +- package.json | 2 +- packages.dhall | 2 +- spago.dhall | 3 +- src/Data/ArrayBuffer/ArrayBuffer.purs | 1 - src/Data/ArrayBuffer/DataView.purs | 126 ++++++------ src/Data/ArrayBuffer/DataView/Gen.purs | 26 +-- src/Data/ArrayBuffer/Typed.purs | 17 +- src/Data/ArrayBuffer/Typed/Gen.purs | 22 +- src/Data/ArrayBuffer/Typed/Unsafe.purs | 5 +- src/Data/ArrayBuffer/ValueMapping.purs | 52 ++--- test/Properties/DataView.purs | 59 +++--- test/Properties/Typed/Laws.purs | 2 +- test/Properties/TypedArray.purs | 266 ++++++++++++++----------- 16 files changed, 328 insertions(+), 286 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.gitignore b/.gitignore index 9cb72c2..f71c254 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ yarn-error.log yarn.lock generated-docs/ .spago/ +.psc-ide-port diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ec49320 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,22 @@ +# v11 2021-06-21 + +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 + +To upgrade to v11, you might need to do a few simple 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`. + +In v11 of this package, we have also upgraded to PureScript v0.14. + diff --git a/README.md b/README.md index e318957..e9efeb9 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,18 @@ # purescript-arraybuffer +[![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: natefaubion](https://img.shields.io/badge/maintainer-jamesdbrock-teal.svg)](https://github.com/jamesdbrock) ArrayBuffer bindings for PureScript. + ## Installation +Install `arraybuffer` with [Spago](https://github.com/purescript/spago): ``` - bower install purescript-arraybuffer +spago install purescript-arraybuffer ``` ## Documentation diff --git a/package.json b/package.json index 110d9f1..a792c5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "purescript-arraybuffer", - "version": "9.0.0", + "version": "11.0.0", "main": "index.js", "repository": "git@github.com:jacereda/purescript-arraybuffer.git", "author": "https://github.com/jacereda", diff --git a/packages.dhall b/packages.dhall index cf30481..446440b 100644 --- a/packages.dhall +++ b/packages.dhall @@ -25,7 +25,7 @@ let additions = , "quickcheck" , "quickcheck-laws" ] - , repo = "https://github.com/zaquest/purescript-uint.git" + , repo = "https://github.com/purescript-contrib/purescript-uint.git" , version = "v5.1.4" } } diff --git a/spago.dhall b/spago.dhall index ef25406..41922dc 100644 --- a/spago.dhall +++ b/spago.dhall @@ -13,14 +13,13 @@ , "partial" , "prelude" , "quickcheck" - , "quickcheck-combinators" , "quickcheck-laws" , "refs" , "tailrec" - , "typelevel" , "typelevel-prelude" , "uint" , "unfoldable" + , "tuples" ] , packages = ./packages.dhall , sources = [ "src/**/*.purs", "test/**/*.purs" ] diff --git a/src/Data/ArrayBuffer/ArrayBuffer.purs b/src/Data/ArrayBuffer/ArrayBuffer.purs index 1206040..9bedd45 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.purs +++ b/src/Data/ArrayBuffer/ArrayBuffer.purs @@ -1,6 +1,5 @@ -- | 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 diff --git a/src/Data/ArrayBuffer/DataView.purs b/src/Data/ArrayBuffer/DataView.purs index b88f344..4daca87 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -1,9 +1,7 @@ -- | 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 - ( AProxy (..) - , Endian (..) + ( Endian(..) , buffer , byteLength , byteOffset @@ -46,20 +44,25 @@ module Data.ArrayBuffer.DataView , whole ) where -import Data.ArrayBuffer.Types (ArrayBuffer, ByteLength, ByteOffset, DataView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, kind ArrayViewType) -import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerValue, class ShowArrayViewType) +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 (SProxy(..), class IsSymbol, reflectSymbol) -import Data.Typelevel.Num (toInt', class Nat) import Data.UInt (UInt) import Effect (Effect) import Effect.Uncurried (EffectFn2, EffectFn3, EffectFn4, runEffectFn2, runEffectFn3, runEffectFn4) import Prelude (class Eq, (<$>), (<>), (==)) import Type.Proxy (Proxy(..)) +-- | Endianness of a multi-byte type. Little-Endian or Big-Endian. +data Endian = LE | BE +instance eqEndian :: Eq Endian where + eq LE LE = true + eq BE BE = true + eq _ _ = false -- | View mapping the whole `ArrayBuffer`. foreign import whole :: ArrayBuffer -> DataView @@ -85,15 +88,6 @@ foreign import byteOffset :: DataView -> ByteOffset foreign import byteLength :: DataView -> ByteLength -data AProxy (a :: ArrayViewType) = AProxy - -data Endian = LE | BE - -instance eqEndian :: Eq Endian where - eq LE LE = true - eq BE BE = true - eq _ _ = false - getter :: forall t. { functionName :: String @@ -115,38 +109,35 @@ foreign import getterImpl :: forall t -get :: forall a name t b +get :: forall a name t . BinaryValue a t - => BytesPerValue a b + => BytesPerType a => ShowArrayViewType a name => IsSymbol name - => Nat b - => Endian -> AProxy a -> DataView -> ByteOffset -> Effect (Maybe t) + => Endian -> Proxy a -> DataView -> ByteOffset -> Effect (Maybe t) get endian prx = let le = endian == LE pnm = "get" <> reflectSymbol (SProxy :: SProxy name) - bpv = toInt' (Proxy :: Proxy b) + bpv = byteWidth prx in getter { functionName: pnm , bytesPerValue: bpv , littleEndian: le } -getBE :: forall a name t b +getBE :: forall a name t . BinaryValue a t - => BytesPerValue a b + => BytesPerType a => ShowArrayViewType a name => IsSymbol name - => Nat b - => AProxy a -> DataView -> ByteOffset -> Effect (Maybe t) + => Proxy a -> DataView -> ByteOffset -> Effect (Maybe t) getBE = get BE -getLE :: forall a name t b +getLE :: forall a name t . BinaryValue a t - => BytesPerValue a b + => BytesPerType a => ShowArrayViewType a name => IsSymbol name - => Nat b - => AProxy a -> DataView -> ByteOffset -> Effect (Maybe t) + => Proxy a -> DataView -> ByteOffset -> Effect (Maybe t) getLE = get LE setter :: forall t. @@ -162,17 +153,16 @@ foreign import setterImpl :: forall t } DataView ByteOffset t Boolean -set :: forall a name t b +set :: forall a name t . BinaryValue a t - => BytesPerValue a b + => BytesPerType a => ShowArrayViewType a name => IsSymbol name - => Nat b - => Endian -> AProxy a -> DataView -> ByteOffset -> t -> Effect Boolean + => Endian -> Proxy a -> DataView -> ByteOffset -> t -> Effect Boolean set endian prx = let le = endian == LE pnm = "set" <> reflectSymbol (SProxy :: SProxy name) - bpv = toInt' (Proxy :: Proxy b) + bpv = byteWidth prx in setter { functionName: pnm , bytesPerValue: bpv , littleEndian: le @@ -180,134 +170,132 @@ set endian prx = -- | Fetch int8 value at a certain index in a `DataView`. getInt8 :: DataView -> ByteOffset -> Effect (Maybe Int) -getInt8 = getLE (AProxy :: AProxy Int8) +getInt8 = getLE (Proxy :: Proxy Int8) -- | Fetch big-endian int16 value at a certain index in a `DataView`. getInt16be :: DataView -> ByteOffset -> Effect (Maybe Int) -getInt16be = getBE (AProxy :: AProxy Int16) +getInt16be = getBE (Proxy :: Proxy Int16) -- | Fetch little-endian int16 value at a certain index in a `DataView`. getInt16le :: DataView -> ByteOffset -> Effect (Maybe Int) -getInt16le = getLE (AProxy :: AProxy Int16) +getInt16le = getLE (Proxy :: Proxy Int16) -- | Fetch big-endian int32 value at a certain index in a `DataView`. getInt32be :: DataView -> ByteOffset -> Effect (Maybe Int) -getInt32be = getBE (AProxy :: AProxy Int32) +getInt32be = getBE (Proxy :: Proxy Int32) -- | Fetch little-endian int32 value at a certain index in a `DataView`. getInt32le :: DataView -> ByteOffset -> Effect (Maybe Int) -getInt32le = getLE (AProxy :: AProxy Int32) +getInt32le = getLE (Proxy :: Proxy Int32) -- | Fetch uint8 value at a certain index in a `DataView`. getUint8 :: DataView -> ByteOffset -> Effect (Maybe UInt) -getUint8 = getLE (AProxy :: AProxy Uint8) +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 (AProxy :: AProxy Uint16) +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 (AProxy :: AProxy Uint16) +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 (AProxy :: AProxy Uint32) +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 (AProxy :: AProxy Uint32) +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 (AProxy :: AProxy 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 (AProxy :: AProxy 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 (AProxy :: AProxy Float64) +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 (AProxy :: AProxy Float64) +getFloat64le = getLE (Proxy :: Proxy Float64) -- | Store big-endian value at a certain index in a `DataView`. -setBE :: forall a name t b +setBE :: forall a name t . BinaryValue a t - => BytesPerValue a b + => BytesPerType a => ShowArrayViewType a name => IsSymbol name - => Nat b - => AProxy a -> DataView -> ByteOffset -> t -> Effect Boolean + => 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 b +setLE :: forall a name t . BinaryValue a t - => BytesPerValue a b + => BytesPerType a => ShowArrayViewType a name => IsSymbol name - => Nat b - => AProxy a -> DataView -> ByteOffset -> t -> Effect Boolean + => Proxy a -> DataView -> ByteOffset -> t -> Effect Boolean setLE = set LE -- | Store int8 value at a certain index in a `DataView`. setInt8 :: DataView -> ByteOffset -> Int -> Effect Boolean -setInt8 = setLE (AProxy :: AProxy Int8) +setInt8 = setLE (Proxy :: Proxy Int8) -- | Store big-endian int16 value at a certain index in a `DataView`. setInt16be :: DataView -> ByteOffset -> Int -> Effect Boolean -setInt16be = setBE (AProxy :: AProxy Int16) +setInt16be = setBE (Proxy :: Proxy Int16) -- | Store little-endian int16 value at a certain index in a `DataView`. setInt16le :: DataView -> ByteOffset -> Int -> Effect Boolean -setInt16le = setLE (AProxy :: AProxy Int16) +setInt16le = setLE (Proxy :: Proxy Int16) -- | Store big-endian int32 value at a certain index in a `DataView`. setInt32be :: DataView -> ByteOffset -> Int -> Effect Boolean -setInt32be = setBE (AProxy :: AProxy Int32) +setInt32be = setBE (Proxy :: Proxy Int32) -- | Store little-endian int32 value at a certain index in a `DataView`. setInt32le :: DataView -> ByteOffset -> Int -> Effect Boolean -setInt32le = setLE (AProxy :: AProxy Int32) +setInt32le = setLE (Proxy :: Proxy Int32) -- | Store uint8 value at a certain index in a `DataView`. setUint8 :: DataView -> ByteOffset -> UInt -> Effect Boolean -setUint8 = setLE (AProxy :: AProxy Uint8) +setUint8 = setLE (Proxy :: Proxy Uint8) -- | Store big-endian uint16 value at a certain index in a `DataView`. setUint16be :: DataView -> ByteOffset -> UInt -> Effect Boolean -setUint16be = setBE (AProxy :: AProxy Uint16) +setUint16be = setBE (Proxy :: Proxy Uint16) -- | Store little-endian uint16 value at a certain index in a `DataView`. setUint16le :: DataView -> ByteOffset -> UInt -> Effect Boolean -setUint16le = setLE (AProxy :: AProxy Uint16) +setUint16le = setLE (Proxy :: Proxy Uint16) -- | Store big-endian uint32 value at a certain index in a `DataView`. setUint32be :: DataView -> ByteOffset -> UInt -> Effect Boolean -setUint32be = setBE (AProxy :: AProxy Uint32) +setUint32be = setBE (Proxy :: Proxy Uint32) -- | Store little-endian uint32 value at a certain index in a `DataView`. setUint32le :: DataView -> ByteOffset -> UInt -> Effect Boolean -setUint32le = setLE (AProxy :: AProxy Uint32) +setUint32le = setLE (Proxy :: Proxy Uint32) -- | Store big-endian float32 value at a certain index in a `DataView`. setFloat32be :: DataView -> ByteOffset -> F.Float32 -> Effect Boolean -setFloat32be = setBE (AProxy :: AProxy Float32) +setFloat32be = setBE (Proxy :: Proxy Float32) -- | Store little-endian float32 value at a certain index in a `DataView`. setFloat32le :: DataView -> ByteOffset -> F.Float32 -> Effect Boolean -setFloat32le = setLE (AProxy :: AProxy Float32) +setFloat32le = setLE (Proxy :: Proxy Float32) -- | Store big-endian float64 value at a certain index in a `DataView`. setFloat64be :: DataView -> ByteOffset -> Number -> Effect Boolean -setFloat64be = setBE (AProxy :: AProxy Float64) +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 (AProxy :: AProxy Float64) +setFloat64le = setLE (Proxy :: Proxy Float64) diff --git a/src/Data/ArrayBuffer/DataView/Gen.purs b/src/Data/ArrayBuffer/DataView/Gen.purs index 441851a..f7e55ca 100644 --- a/src/Data/ArrayBuffer/DataView/Gen.purs +++ b/src/Data/ArrayBuffer/DataView/Gen.purs @@ -1,16 +1,14 @@ module Data.ArrayBuffer.DataView.Gen where -import Prelude ((<$>), bind, (<=), (-), pure) - 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, kind ArrayViewType) -import Data.ArrayBuffer.ValueMapping (class BytesPerValue, class BinaryValue) -import Data.Typelevel.Num (class Nat, toInt') +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(..)) @@ -22,22 +20,20 @@ genDataView = whole <$> genArrayBuffer -- | For generating some set of offsets residing inside the generated array, with some computable value -data WithOffsetAndValue n (a :: ArrayViewType) t = +data WithOffsetAndValue (a :: ArrayViewType) t = WithOffsetAndValue (Array ByteOffset) t DataView -genWithOffsetAndValue :: forall m n a b t +genWithOffsetAndValue :: forall m a t . MonadGen m => MonadRec m - => Nat n - => BytesPerValue a b + => BytesPerType a => BinaryValue a t - => Nat b - => m DataView -- ^ Assumes generated length is at least the minimum length of one value + => Int -- generated length + -> m DataView -- ^ Assumes generated length is at least the minimum length of one value -> m t - -> m (WithOffsetAndValue n a t) -genWithOffsetAndValue gen genT = do - let n = toInt' (Proxy :: Proxy n) - b = toInt' (Proxy :: Proxy b) + -> 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)) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 6d17ee1..472a959 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -43,20 +43,19 @@ module Data.ArrayBuffer.Typed , all, any , allWithIndex, anyWithIndex , unsafeAt, hasIndex, at, (!) - , reduce, reduce1, foldl, foldl1, reduceRight, reduceRight1, foldr, foldr1 - , find, findIndex, indexOf, lastIndexOf + , reduce, reduce1, foldl, foldl1, reduceRight, reduceRight1, foldr, foldr1, foldlWithIndex, foldrWithIndex + , find, findIndex, findWithIndex, indexOf, lastIndexOf , slice, subArray , toString, join, toArray ) where import Data.Array (length) as A -import Data.ArrayBuffer.Types (ArrayView, kind 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 BytesPerValue) +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.Typelevel.Num (class Nat, toInt') import Data.UInt (UInt) import Effect (Effect) import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4, mkEffectFn2, mkEffectFn3, runEffectFn1, runEffectFn2, runEffectFn3, runEffectFn4) @@ -126,17 +125,17 @@ 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 => Nat b => BytesPerValue a b => ArrayBuffer -> Index -> Effect (ArrayView a) +remainder :: forall a b t. TypedArray a t => BytesPerType b => ArrayBuffer -> Index -> Effect (ArrayView a) remainder a x = remainder' a o - where o = x * toInt' (Proxy :: Proxy b) + 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 b t. TypedArray a t => Nat b => BytesPerValue a b => ArrayBuffer -> Index -> Length -> Effect (ArrayView a) +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 * toInt' (Proxy :: Proxy b) + where o = x * byteWidth (Proxy :: Proxy a) part' :: forall a t. TypedArray a t => ArrayBuffer -> ByteOffset -> Length -> Effect (ArrayView a) part' a x y = runEffectFn3 create a (notNull x) (notNull y) diff --git a/src/Data/ArrayBuffer/Typed/Gen.purs b/src/Data/ArrayBuffer/Typed/Gen.purs index 380e28b..678c14d 100644 --- a/src/Data/ArrayBuffer/Typed/Gen.purs +++ b/src/Data/ArrayBuffer/Typed/Gen.purs @@ -1,21 +1,18 @@ -- | Functions for generating typed arrays and values. - module Data.ArrayBuffer.Typed.Gen where -import Prelude ((<$>), bind, (/), (-), negate, ($), bottom, pure, top) 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.Generic.Rep (class Generic) -import Data.Typelevel.Num (class Nat, toInt') 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 Type.Proxy (Proxy(..)) +import Prelude (bind, bottom, negate, pure, top, ($), (-), (/), (<$>)) genTypedArray :: forall m a t @@ -54,16 +51,15 @@ genFloat64 = chooseFloat ((-1.7976931348623157e+308)/div) (1.7976931348623157e+3 where div = 4.0 -- | For generating some set of offsets residing inside the generated array -data WithIndices n a = WithIndices (Array TA.Index) (ArrayView a) -derive instance genericWithIndices :: Generic (ArrayView a) a' => Generic (WithIndices n a) _ +data WithIndices a = WithIndices (Array TA.Index) (ArrayView a) -genWithIndices :: forall m n a +genWithIndices :: forall m a . MonadGen m - => Nat n - => m (ArrayView a) - -> m (WithIndices n a) -genWithIndices gen = do - let n = toInt' (Proxy :: Proxy n) + => 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)) diff --git a/src/Data/ArrayBuffer/Typed/Unsafe.purs b/src/Data/ArrayBuffer/Typed/Unsafe.purs index a536eee..facd419 100644 --- a/src/Data/ArrayBuffer/Typed/Unsafe.purs +++ b/src/Data/ArrayBuffer/Typed/Unsafe.purs @@ -2,13 +2,14 @@ module Data.ArrayBuffer.Typed.Unsafe where import Data.ArrayBuffer.Typed (class TypedArray, toString) import Data.ArrayBuffer.Typed as TA -import Data.ArrayBuffer.Types (ArrayView) -import Data.Maybe (Maybe(..)) +import Data.ArrayBuffer.Types (ArrayView, ArrayViewType) import Data.Generic.Rep (class Generic) +import Data.Maybe (Maybe(..)) import Effect.Unsafe (unsafePerformEffect) import Prelude (class Eq, class Monoid, class Ord, class Semigroup, class Show, bind, discard, pure, void, ($), (+), (<>), (<$>)) import Test.QuickCheck (class Arbitrary, arbitrary) +newtype AV :: forall k. ArrayViewType -> k -> Type newtype AV a t = AV (ArrayView a) derive instance genericAV :: Generic (AV a t) _ diff --git a/src/Data/ArrayBuffer/ValueMapping.purs b/src/Data/ArrayBuffer/ValueMapping.purs index 87bc256..e262b2c 100644 --- a/src/Data/ArrayBuffer/ValueMapping.purs +++ b/src/Data/ArrayBuffer/ValueMapping.purs @@ -1,29 +1,33 @@ -- | This module represents type-level mappings between `ArrayViewType`s -- | and meaningful data. - -module Data.ArrayBuffer.ValueMapping where - -import Data.ArrayBuffer.Types (kind ArrayViewType, Float64, Float32, Uint8Clamped, Uint32, Uint16, Uint8, Int32, Int16, Int8) -import Data.Typelevel.Num (D1, D2, D4, D8) -import Data.UInt (UInt) +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 - - --- | Maps a `TypedArray`'s binary casted value, to the space occupied by that value, in bytes. -class BytesPerValue (a :: ArrayViewType) (b :: Type) | a -> b - -instance bytesPerValueUint8Clamped :: BytesPerValue Uint8Clamped D1 -instance bytesPerValueUint32 :: BytesPerValue Uint32 D4 -instance bytesPerValueUint16 :: BytesPerValue Uint16 D2 -instance bytesPerValueUint8 :: BytesPerValue Uint8 D1 -instance bytesPerValueInt32 :: BytesPerValue Int32 D4 -instance bytesPerValueInt16 :: BytesPerValue Int16 D2 -instance bytesPerValueInt8 :: BytesPerValue Int8 D1 -instance bytesPerValueFloat32 :: BytesPerValue Float32 D4 -instance bytesPerValueFloat64 :: BytesPerValue Float64 D8 - - --- | Maps a `TypedArray`'s binary casted value, to its computable representation in JavaScript. +import Data.UInt (UInt) +import Type.Proxy (Proxy) + +-- | 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 + +-- | Maps a `TypedArray`’s binary casted value to its computable representation in JavaScript. class BinaryValue (a :: ArrayViewType) (t :: Type) | a -> t instance binaryValueUint8Clamped :: BinaryValue Uint8Clamped UInt @@ -36,8 +40,6 @@ instance binaryValueInt8 :: BinaryValue Int8 Int instance binaryValueFloat32 :: BinaryValue Float32 F.Float32 instance binaryValueFloat64 :: BinaryValue Float64 Number - - class ShowArrayViewType (a :: ArrayViewType) (name :: Symbol) | a -> name instance showArrayViewTypeUint8Clamped :: ShowArrayViewType Uint8Clamped "Uint8Clamped" instance showArrayViewTypeViewUint32 :: ShowArrayViewType Uint32 "Uint32" diff --git a/test/Properties/DataView.purs b/test/Properties/DataView.purs index 58cde67..a981bf7 100644 --- a/test/Properties/DataView.purs +++ b/test/Properties/DataView.purs @@ -1,6 +1,5 @@ module Test.Properties.DataView where - import Prelude import Data.Array.Partial (head) as Array @@ -8,21 +7,19 @@ 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 BytesPerValue, class ShowArrayViewType, class BinaryValue) -import Data.Maybe (Maybe(..)) -import Data.Typelevel.Num (class Nat, D1, D2, D4, D8) -import Data.UInt (UInt) +import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerType, class ShowArrayViewType) import Data.Float32 (Float32) as F --- import Data.Vec (head) as Vec +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 Test.QuickCheck (class Testable, quickCheckGen, Result, (===)) import Partial.Unsafe (unsafePartial) - +import Test.QuickCheck (class Testable, quickCheckGen, Result, (===)) +import Type.Proxy (Proxy(..)) dataViewTests :: Ref Int -> Effect Unit @@ -33,79 +30,79 @@ dataViewTests count = do placingAValueIsThereTests DV.LE count -type TestableViewF a name b n t q = +type TestableViewF a name t q = Show t => Eq t => Ord t => Semiring t - => BytesPerValue a b + => BytesPerType a => BinaryValue a t => ShowArrayViewType a name => IsSymbol name - => Nat b - => WithOffsetAndValue n a t + => WithOffsetAndValue a t -> q -overAll :: forall q n. Testable q => Nat n => Ref Int -> (forall a name b t. TestableViewF a name b n t q) -> Effect Unit +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 $ - let f' :: TestableViewF Uint32 "Uint32" D4 n UInt q + let f' :: TestableViewF Uint32 "Uint32" UInt q f' = f - in f' <$> genWithOffsetAndValue genDataView genUint32 + in f' <$> genWithOffsetAndValue 4 genDataView genUint32 log " - Uint16" quickCheckGen $ - let f' :: TestableViewF Uint16 "Uint16" D2 n UInt q + let f' :: TestableViewF Uint16 "Uint16" UInt q f' = f - in f' <$> genWithOffsetAndValue genDataView genUint16 + in f' <$> genWithOffsetAndValue 2 genDataView genUint16 log " - Uint8" quickCheckGen $ - let f' :: TestableViewF Uint8 "Uint8" D1 n UInt q + let f' :: TestableViewF Uint8 "Uint8" UInt q f' = f - in f' <$> genWithOffsetAndValue genDataView genUint8 + in f' <$> genWithOffsetAndValue 1 genDataView genUint8 log " - Int32" quickCheckGen $ - let f' :: TestableViewF Int32 "Int32" D4 n Int q + let f' :: TestableViewF Int32 "Int32" Int q f' = f - in f' <$> genWithOffsetAndValue genDataView genInt32 + in f' <$> genWithOffsetAndValue 4 genDataView genInt32 log " - Int16" quickCheckGen $ - let f' :: TestableViewF Int16 "Int16" D2 n Int q + let f' :: TestableViewF Int16 "Int16" Int q f' = f - in f' <$> genWithOffsetAndValue genDataView genInt16 + in f' <$> genWithOffsetAndValue 2 genDataView genInt16 log " - Int8" quickCheckGen $ - let f' :: TestableViewF Int8 "Int8" D1 n Int q + let f' :: TestableViewF Int8 "Int8" Int q f' = f - in f' <$> genWithOffsetAndValue genDataView genInt8 + in f' <$> genWithOffsetAndValue 1 genDataView genInt8 log " - Float32" quickCheckGen $ - let f' :: TestableViewF Float32 "Float32" D4 n F.Float32 q + let f' :: TestableViewF Float32 "Float32" F.Float32 q f' = f - in f' <$> genWithOffsetAndValue genDataView genFloat32 + in f' <$> genWithOffsetAndValue 4 genDataView genFloat32 log " - Float64" quickCheckGen $ - let f' :: TestableViewF Float64 "Float64" D8 n Number q + let f' :: TestableViewF Float64 "Float64" Number q f' = f - in f' <$> genWithOffsetAndValue genDataView genFloat64 + in f' <$> genWithOffsetAndValue 8 genDataView genFloat64 placingAValueIsThereTests :: DV.Endian -> Ref Int -> Effect Unit placingAValueIsThereTests endian count = overAll count placingAValueIsThere where - placingAValueIsThere :: forall a name b t. TestableViewF a name b D1 t Result + placingAValueIsThere :: forall a name t. TestableViewF a name t Result placingAValueIsThere (WithOffsetAndValue os t xs) = let o = unsafePartial $ Array.head os - prx = DV.AProxy :: DV.AProxy a + prx = Proxy :: Proxy a in unsafePerformEffect do _ <- DV.set endian prx xs o t my <- DV.get endian prx xs o diff --git a/test/Properties/Typed/Laws.purs b/test/Properties/Typed/Laws.purs index 8a6f02b..5f7d5c5 100644 --- a/test/Properties/Typed/Laws.purs +++ b/test/Properties/Typed/Laws.purs @@ -3,7 +3,7 @@ module Test.Properties.Typed.Laws where import Data.ArrayBuffer.Typed (class TypedArray) import Data.ArrayBuffer.Typed.Gen (genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8) import Data.ArrayBuffer.Typed.Unsafe (AV(..)) -import Data.ArrayBuffer.Types (ArrayView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, Uint8Clamped, kind ArrayViewType) +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) diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index 449f1a1..9b054c0 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -9,12 +9,11 @@ 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, Uint8Array, Uint8ClampedArray, Uint32Array) -import Data.ArrayBuffer.ValueMapping (class BytesPerValue) +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.Typelevel.Num (class Nat, D0, D1, D2, D5, toInt') --- import Data.Vec (head, index) as Vec +import Data.Tuple (Tuple(..)) import Effect (Effect) import Effect.Console (log) import Effect.Ref (Ref) @@ -22,11 +21,9 @@ import Effect.Ref as Ref import Effect.Unsafe (unsafePerformEffect) import Partial.Unsafe (unsafePartial) import Test.QuickCheck (class Testable, Result(..), quickCheckGen, (/==), (), (===)) -import Test.QuickCheck.Combinators ((==>), (|=|)) import Test.QuickCheck.Gen (Gen) import Type.Proxy (Proxy(..)) - typedArrayTests :: Ref Int -> Effect Unit typedArrayTests count = do log " - subarrayBehavesLikeArraySlice" @@ -111,51 +108,66 @@ typedArrayTests count = do copyWithinViaSetTypedTests count - -type TestableArrayF a b n t q = +type TestableArrayF a t q = Show t => Eq t => Ord t => Semiring t => TypedArray a t - => BytesPerValue a b - => Nat b - => WithIndices n a + => BytesPerType a + => WithIndices a -> Effect q - -overAll' :: forall q n. Testable q => Nat n => Int -> Ref Int -> (forall a b t. TestableArrayF a b n t q) -> Effect Unit -overAll' mn count f = do +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 b t. Show t => Eq t => Ord t => Semiring t => Nat b => BytesPerValue a b => TypedArray a t => String -> Proxy (ArrayView a) -> Gen t -> Effect Unit - chk s _ gen = do + 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 arr + quickCheckGen $ unsafePerformEffect <<< f <$> genWithIndices n' arr where arr :: Gen (ArrayView a) arr = genTypedArray gen `suchThat` \xs -> mn <= TA.length xs - chk "Uint8ClampedArray" (Proxy :: Proxy Uint8ClampedArray) genUint8 - chk "Uint32Array" (Proxy :: Proxy Uint32Array) genUint32 - chk "Uint16Array" (Proxy :: Proxy Uint16Array) genUint16 - chk "Uint8Array" (Proxy :: Proxy Uint8Array) genUint8 - chk "Int32Array" (Proxy :: Proxy Int32Array) genInt32 - chk "Int16Array" (Proxy :: Proxy Int16Array) genInt16 - chk "Int8Array" (Proxy :: Proxy Int8Array) genInt8 - chk "Float32Array" (Proxy :: Proxy Float32Array) genFloat32 - chk "Float64Array" (Proxy :: Proxy Float64Array) genFloat64 + 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 n. Testable q => Nat n => Ref Int -> (forall a b t. TestableArrayF a b n t q) -> Effect Unit -overAll count f = overAll' 0 count f +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 n. Testable q => Nat n => Ref Int -> (forall a b t. TestableArrayF a b n t q) -> Effect Unit -overAll1 count f = overAll' 1 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 count f +subarrayBehavesLikeArraySliceTests count = overAll 2 count f where - f :: forall a b t. TestableArrayF a b D2 t Result + 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 @@ -165,9 +177,9 @@ subarrayBehavesLikeArraySliceTests count = overAll count f pure $ Array.slice s e axs === a sliceBehavesLikeArraySliceTests :: Ref Int -> Effect Unit -sliceBehavesLikeArraySliceTests count = overAll count f +sliceBehavesLikeArraySliceTests count = overAll 2 count f where - f :: forall a b t. TestableArrayF a b D2 t Result + 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 @@ -177,9 +189,9 @@ sliceBehavesLikeArraySliceTests count = overAll count f pure $ Array.slice s e axs === a partBehavesLikeTakeDropTests :: Ref Int -> Effect Unit -partBehavesLikeTakeDropTests count = overAll count f +partBehavesLikeTakeDropTests count = overAll 0 count f where - f :: forall a b t. TestableArrayF a b D0 t Result + f :: forall a t. TestableArrayF a t Result f (WithIndices _ xs) = do let n = 2 axs <- TA.toArray xs @@ -188,17 +200,17 @@ partBehavesLikeTakeDropTests count = overAll count f pure $ Array.take n (Array.drop n axs) === aps byteLengthDivBytesPerValueTests :: Ref Int -> Effect Unit -byteLengthDivBytesPerValueTests count = overAll count byteLengthDivBytesPerValueEqLength +byteLengthDivBytesPerValueTests count = overAll 0 count byteLengthDivBytesPerValueEqLength where - byteLengthDivBytesPerValueEqLength :: forall a b t. TestableArrayF a b D0 t Result - byteLengthDivBytesPerValueEqLength (WithIndices _ a) = - let b = toInt' (Proxy :: Proxy b) - in pure $ TA.length a === (TA.byteLength a `div` b) + byteLengthDivBytesPerValueEqLength :: forall a t. TestableArrayF a t Result + byteLengthDivBytesPerValueEqLength (WithIndices _ xs) = + let b = byteWidth (Proxy :: Proxy a) + in pure $ TA.length xs === (TA.byteLength xs `div` b) fromArrayToArrayIsoTests :: Ref Int -> Effect Unit -fromArrayToArrayIsoTests count = overAll count fromArrayToArrayIso +fromArrayToArrayIsoTests count = overAll 0 count fromArrayToArrayIso where - fromArrayToArrayIso :: forall a b t. TestableArrayF a b D0 t Result + fromArrayToArrayIso :: forall a t. TestableArrayF a t Result fromArrayToArrayIso (WithIndices _ xs) = do axs <- TA.toArray xs xs' <- TA.fromArray axs :: Effect (ArrayView a) @@ -207,9 +219,9 @@ fromArrayToArrayIsoTests count = overAll count fromArrayToArrayIso allAreFilledTests :: Ref Int -> Effect Unit -allAreFilledTests count = overAll count allAreFilled +allAreFilledTests count = overAll 0 count allAreFilled where - allAreFilled :: forall a b t. TestableArrayF a b D0 t Result + allAreFilled :: forall a t. TestableArrayF a t Result allAreFilled (WithIndices _ xs) = do e <- TA.at xs 0 let x = fromMaybe zero e @@ -220,9 +232,9 @@ allAreFilledTests count = overAll count allAreFilled setSingletonIsEqTests :: Ref Int -> Effect Unit -setSingletonIsEqTests count = overAll count setSingletonIsEq +setSingletonIsEqTests count = overAll 1 count setSingletonIsEq where - setSingletonIsEq :: forall a b t. TestableArrayF a b D1 t Result + setSingletonIsEq :: forall a t. TestableArrayF a t Result setSingletonIsEq (WithIndices os xs) = do e <- TA.at xs 0 case e of @@ -236,23 +248,23 @@ setSingletonIsEqTests count = overAll count setSingletonIsEq -- | Should work with any arbitrary predicate, but we can't generate them allImpliesAnyTests :: Ref Int -> Effect Unit -allImpliesAnyTests count = overAll count allImpliesAny +allImpliesAnyTests count = overAll 0 count allImpliesAny where - allImpliesAny :: forall a b t. TestableArrayF a b D0 t Result + 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) |=| all' ==> any' + 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 count filterImpliesAll +filterImpliesAllTests count = overAll 0 count filterImpliesAll where - filterImpliesAll :: forall a b t. TestableArrayF a b D0 t Result + filterImpliesAll :: forall a t. TestableArrayF a t Result filterImpliesAll (WithIndices _ xs) = do let pred x = x /= zero ys <- TA.filter pred xs @@ -262,9 +274,9 @@ filterImpliesAllTests count = overAll count filterImpliesAll -- | Should work with any arbitrary predicate, but we can't generate them filterIsTotalTests :: Ref Int -> Effect Unit -filterIsTotalTests count = overAll count filterIsTotal +filterIsTotalTests count = overAll 0 count filterIsTotal where - filterIsTotal :: forall a b t. TestableArrayF a b D0 t Result + filterIsTotal :: forall a t. TestableArrayF a t Result filterIsTotal (WithIndices _ xs) = do let pred x = x /= zero ys <- TA.filter pred xs @@ -275,9 +287,9 @@ filterIsTotalTests count = overAll count filterIsTotal -- | Should work with any arbitrary predicate, but we can't generate them filterIsIdempotentTests :: Ref Int -> Effect Unit -filterIsIdempotentTests count = overAll count filterIsIdempotent +filterIsIdempotentTests count = overAll 0 count filterIsIdempotent where - filterIsIdempotent :: forall a b t. TestableArrayF a b D0 t Result + filterIsIdempotent :: forall a t. TestableArrayF a t Result filterIsIdempotent (WithIndices _ xs) = do let pred x = x /= zero ys <- TA.filter pred xs @@ -288,17 +300,17 @@ filterIsIdempotentTests count = overAll count filterIsIdempotent withIndicesHasIndexTests :: Ref Int -> Effect Unit -withIndicesHasIndexTests count = overAll1 count withIndicesHasIndex +withIndicesHasIndexTests count = overAll1 5 count withIndicesHasIndex where - withIndicesHasIndex :: forall a b t. TestableArrayF a b D5 t Result + 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 count withIndicesElem +withIndicesElemTests count = overAll1 5 count withIndicesElem where - withIndicesElem :: forall a b t. TestableArrayF a b D5 t Result + withIndicesElem :: forall a t. TestableArrayF a t Result withIndicesElem (WithIndices os xs) = do let fetch o = TA.at xs o exs <- traverse fetch os @@ -307,9 +319,9 @@ withIndicesElemTests count = overAll1 count withIndicesElem -- | Should work with any arbitrary predicate, but we can't generate them anyImpliesFindTests :: Ref Int -> Effect Unit -anyImpliesFindTests count = overAll count anyImpliesFind +anyImpliesFindTests count = overAll 0 count anyImpliesFind where - anyImpliesFind :: forall a b t. TestableArrayF a b D0 t Result + anyImpliesFind :: forall a t. TestableArrayF a t Result anyImpliesFind (WithIndices _ xs) = do let pred x = x /= zero a <- TA.any pred xs @@ -320,14 +332,14 @@ anyImpliesFindTests count = overAll count anyImpliesFind Just z -> if pred z then Success else Failed "Found value doesn't satisfy the predicate" - pure $ p ==> q + pure $ p `implies` q -- | Should work with any arbitrary predicate, but we can't generate them findIndexImpliesAtTests :: Ref Int -> Effect Unit -findIndexImpliesAtTests count = overAll count findIndexImpliesAt +findIndexImpliesAtTests count = overAll 0 count findIndexImpliesAt where - findIndexImpliesAt :: forall a b t. TestableArrayF a b D0 t Result + findIndexImpliesAt :: forall a t. TestableArrayF a t Result findIndexImpliesAt (WithIndices _ xs) = do let pred x _ = x /= zero mo <- TA.findIndex pred xs @@ -342,9 +354,9 @@ findIndexImpliesAtTests count = overAll count findIndexImpliesAt indexOfImpliesAtTests :: Ref Int -> Effect Unit -indexOfImpliesAtTests count = overAll count indexOfImpliesAt +indexOfImpliesAtTests count = overAll 1 count indexOfImpliesAt where - indexOfImpliesAt :: forall a b t. TestableArrayF a b D1 t Result + indexOfImpliesAt :: forall a t. TestableArrayF a t Result indexOfImpliesAt (WithIndices _ xs) = do e <- TA.at xs 0 case e of @@ -359,9 +371,9 @@ indexOfImpliesAtTests count = overAll count indexOfImpliesAt lastIndexOfImpliesAtTests :: Ref Int -> Effect Unit -lastIndexOfImpliesAtTests count = overAll count lastIndexOfImpliesAt +lastIndexOfImpliesAtTests count = overAll 0 count lastIndexOfImpliesAt where - lastIndexOfImpliesAt :: forall a b t. TestableArrayF a b D0 t Result + lastIndexOfImpliesAt :: forall a t. TestableArrayF a t Result lastIndexOfImpliesAt (WithIndices _ xs) = do e <- TA.at xs 0 case e of @@ -376,9 +388,9 @@ lastIndexOfImpliesAtTests count = overAll count lastIndexOfImpliesAt foldrConsIsToArrayTests :: Ref Int -> Effect Unit -foldrConsIsToArrayTests count = overAll count foldrConsIsToArray +foldrConsIsToArrayTests count = overAll 0 count foldrConsIsToArray where - foldrConsIsToArray :: forall a b t. TestableArrayF a b D0 t Result + foldrConsIsToArray :: forall a t. TestableArrayF a t Result foldrConsIsToArray (WithIndices _ xs) = do axs <- TA.toArray xs rxs <- TA.foldr Array.cons [] xs @@ -386,9 +398,9 @@ foldrConsIsToArrayTests count = overAll count foldrConsIsToArray foldlSnocIsToArrayTests :: Ref Int -> Effect Unit -foldlSnocIsToArrayTests count = overAll count foldlSnocIsToArray +foldlSnocIsToArrayTests count = overAll 0 count foldlSnocIsToArray where - foldlSnocIsToArray :: forall a b t. TestableArrayF a b D0 t Result + foldlSnocIsToArray :: forall a t. TestableArrayF a t Result foldlSnocIsToArray (WithIndices _ xs) = do axs <- TA.toArray xs rxs <- TA.foldl Array.snoc [] xs @@ -396,9 +408,9 @@ foldlSnocIsToArrayTests count = overAll count foldlSnocIsToArray mapIdentityIsIdentityTests :: Ref Int -> Effect Unit -mapIdentityIsIdentityTests count = overAll count mapIdentityIsIdentity +mapIdentityIsIdentityTests count = overAll 0 count mapIdentityIsIdentity where - mapIdentityIsIdentity :: forall a b t. TestableArrayF a b D0 t Result + mapIdentityIsIdentity :: forall a t. TestableArrayF a t Result mapIdentityIsIdentity (WithIndices _ xs) = do axs <- TA.toArray xs mxs <- TA.toArray (TA.map identity xs) @@ -406,9 +418,9 @@ mapIdentityIsIdentityTests count = overAll count mapIdentityIsIdentity traverseSnocIsToArrayTests :: Ref Int -> Effect Unit -traverseSnocIsToArrayTests count = overAll count traverseSnocIsToArray +traverseSnocIsToArrayTests count = overAll 0 count traverseSnocIsToArray where - traverseSnocIsToArray :: forall a b t. TestableArrayF a b D0 t Result + 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 @@ -418,9 +430,9 @@ traverseSnocIsToArrayTests count = overAll count traverseSnocIsToArray doubleReverseIsIdentityTests :: Ref Int -> Effect Unit -doubleReverseIsIdentityTests count = overAll count doubleReverseIsIdentity +doubleReverseIsIdentityTests count = overAll 0 count doubleReverseIsIdentity where - doubleReverseIsIdentity :: forall a b t. TestableArrayF a b D0 t Result + doubleReverseIsIdentity :: forall a t. TestableArrayF a t Result doubleReverseIsIdentity (WithIndices _ xs) = do axs <- TA.toArray xs TA.reverse xs @@ -430,9 +442,9 @@ doubleReverseIsIdentityTests count = overAll count doubleReverseIsIdentity reverseIsArrayReverseTests :: Ref Int -> Effect Unit -reverseIsArrayReverseTests count = overAll count reverseIsArrayReverse +reverseIsArrayReverseTests count = overAll 0 count reverseIsArrayReverse where - reverseIsArrayReverse :: forall a b t. TestableArrayF a b D0 t Result + reverseIsArrayReverse :: forall a t. TestableArrayF a t Result reverseIsArrayReverse (WithIndices _ xs) = do axs <- TA.toArray xs TA.reverse xs @@ -441,9 +453,9 @@ reverseIsArrayReverseTests count = overAll count reverseIsArrayReverse sortIsIdempotentTests :: Ref Int -> Effect Unit -sortIsIdempotentTests count = overAll count sortIsIdempotent +sortIsIdempotentTests count = overAll 0 count sortIsIdempotent where - sortIsIdempotent :: forall a b t. TestableArrayF a b D0 t Result + sortIsIdempotent :: forall a t. TestableArrayF a t Result sortIsIdempotent (WithIndices _ xs) = do TA.sort xs ys <- TA.toArray xs @@ -453,9 +465,9 @@ sortIsIdempotentTests count = overAll count sortIsIdempotent sortIsArraySortTests :: Ref Int -> Effect Unit -sortIsArraySortTests count = overAll count sortIsArraySort +sortIsArraySortTests count = overAll 0 count sortIsArraySort where - sortIsArraySort :: forall a b t. TestableArrayF a b D0 t Result + sortIsArraySort :: forall a t. TestableArrayF a t Result sortIsArraySort (WithIndices _ xs) = do axs <- TA.toArray xs let ys = Array.sort axs @@ -465,9 +477,9 @@ sortIsArraySortTests count = overAll count sortIsArraySort toStringIsJoinWithCommaTests :: Ref Int -> Effect Unit -toStringIsJoinWithCommaTests count = overAll count toStringIsJoinWithComma +toStringIsJoinWithCommaTests count = overAll 0 count toStringIsJoinWithComma where - toStringIsJoinWithComma :: forall a b t. TestableArrayF a b D0 t Result + toStringIsJoinWithComma :: forall a t. TestableArrayF a t Result toStringIsJoinWithComma (WithIndices _ xs) = do s1 <- TA.join "," xs s2 <- TA.toString xs @@ -475,9 +487,9 @@ toStringIsJoinWithCommaTests count = overAll count toStringIsJoinWithComma setTypedOfSubArrayIsIdentityTests :: Ref Int -> Effect Unit -setTypedOfSubArrayIsIdentityTests count = overAll count setTypedOfSubArrayIsIdentity +setTypedOfSubArrayIsIdentityTests count = overAll 0 count setTypedOfSubArrayIsIdentity where - setTypedOfSubArrayIsIdentity :: forall a b t. TestableArrayF a b D0 t Result + setTypedOfSubArrayIsIdentity :: forall a t. TestableArrayF a t Result setTypedOfSubArrayIsIdentity (WithIndices _ xs) = do ys <- TA.toArray xs let l = TA.length xs @@ -488,9 +500,9 @@ setTypedOfSubArrayIsIdentityTests count = overAll count setTypedOfSubArrayIsIden modifyingOriginalMutatesSubArrayTests :: Ref Int -> Effect Unit -modifyingOriginalMutatesSubArrayTests count = overAll count modifyingOriginalMutatesSubArray +modifyingOriginalMutatesSubArrayTests count = overAll 0 count modifyingOriginalMutatesSubArray where - modifyingOriginalMutatesSubArray :: forall a b t. TestableArrayF a b D0 t Result + modifyingOriginalMutatesSubArray :: forall a t. TestableArrayF a t Result modifyingOriginalMutatesSubArray (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs @@ -505,9 +517,9 @@ modifyingOriginalMutatesSubArrayTests count = overAll count modifyingOriginalMut modifyingSubArrayMutatesOriginalTests :: Ref Int -> Effect Unit -modifyingSubArrayMutatesOriginalTests count = overAll count modifyingOriginalMutatesSubArray +modifyingSubArrayMutatesOriginalTests count = overAll 0 count modifyingOriginalMutatesSubArray where - modifyingOriginalMutatesSubArray :: forall a b t. TestableArrayF a b D0 t Result + modifyingOriginalMutatesSubArray :: forall a t. TestableArrayF a t Result modifyingOriginalMutatesSubArray (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs @@ -522,9 +534,9 @@ modifyingSubArrayMutatesOriginalTests count = overAll count modifyingOriginalMut modifyingOriginalMutatesSubArrayZeroTests :: Ref Int -> Effect Unit -modifyingOriginalMutatesSubArrayZeroTests count = overAll count modifyingOriginalMutatesSubArrayZero +modifyingOriginalMutatesSubArrayZeroTests count = overAll 0 count modifyingOriginalMutatesSubArrayZero where - modifyingOriginalMutatesSubArrayZero :: forall a b t. TestableArrayF a b D0 t Result + modifyingOriginalMutatesSubArrayZero :: forall a t. TestableArrayF a t Result modifyingOriginalMutatesSubArrayZero (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs @@ -539,9 +551,9 @@ modifyingOriginalMutatesSubArrayZeroTests count = overAll count modifyingOrigina modifyingSubArrayMutatesOriginalZeroTests :: Ref Int -> Effect Unit -modifyingSubArrayMutatesOriginalZeroTests count = overAll count modifyingSubArrayMutatesOriginalZero +modifyingSubArrayMutatesOriginalZeroTests count = overAll 0 count modifyingSubArrayMutatesOriginalZero where - modifyingSubArrayMutatesOriginalZero :: forall a b t. TestableArrayF a b D0 t Result + modifyingSubArrayMutatesOriginalZero :: forall a t. TestableArrayF a t Result modifyingSubArrayMutatesOriginalZero (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs @@ -556,9 +568,9 @@ modifyingSubArrayMutatesOriginalZeroTests count = overAll count modifyingSubArra modifyingOriginalMutatesSubArrayAllTests :: Ref Int -> Effect Unit -modifyingOriginalMutatesSubArrayAllTests count = overAll count modifyingOriginalMutatesSubArrayAll +modifyingOriginalMutatesSubArrayAllTests count = overAll 0 count modifyingOriginalMutatesSubArrayAll where - modifyingOriginalMutatesSubArrayAll :: forall a b t. TestableArrayF a b D0 t Result + modifyingOriginalMutatesSubArrayAll :: forall a t. TestableArrayF a t Result modifyingOriginalMutatesSubArrayAll (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs @@ -573,9 +585,9 @@ modifyingOriginalMutatesSubArrayAllTests count = overAll count modifyingOriginal modifyingSubArrayMutatesOriginalAllTests :: Ref Int -> Effect Unit -modifyingSubArrayMutatesOriginalAllTests count = overAll count modifyingSubArrayMutatesOriginalAll +modifyingSubArrayMutatesOriginalAllTests count = overAll 0 count modifyingSubArrayMutatesOriginalAll where - modifyingSubArrayMutatesOriginalAll :: forall a b t. TestableArrayF a b D0 t Result + modifyingSubArrayMutatesOriginalAll :: forall a t. TestableArrayF a t Result modifyingSubArrayMutatesOriginalAll (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs @@ -590,9 +602,9 @@ modifyingSubArrayMutatesOriginalAllTests count = overAll count modifyingSubArray modifyingOriginalMutatesSubArrayPartTests :: Ref Int -> Effect Unit -modifyingOriginalMutatesSubArrayPartTests count = overAll count modifyingOriginalMutatesSubArrayPart +modifyingOriginalMutatesSubArrayPartTests count = overAll 1 count modifyingOriginalMutatesSubArrayPart where - modifyingOriginalMutatesSubArrayPart :: forall a b t. TestableArrayF a b D1 t Result + modifyingOriginalMutatesSubArrayPart :: forall a t. TestableArrayF a t Result modifyingOriginalMutatesSubArrayPart (WithIndices os xs) = do let o = unsafePartial $ Array.head os l = TA.length xs @@ -607,9 +619,9 @@ modifyingOriginalMutatesSubArrayPartTests count = overAll count modifyingOrigina modifyingOriginalDoesntMutateSliceTests :: Ref Int -> Effect Unit -modifyingOriginalDoesntMutateSliceTests count = overAll count modifyingOriginalDoesntMutateSlice +modifyingOriginalDoesntMutateSliceTests count = overAll 0 count modifyingOriginalDoesntMutateSlice where - modifyingOriginalDoesntMutateSlice :: forall a b t. TestableArrayF a b D0 t Result + modifyingOriginalDoesntMutateSlice :: forall a t. TestableArrayF a t Result modifyingOriginalDoesntMutateSlice (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs @@ -624,9 +636,9 @@ modifyingOriginalDoesntMutateSliceTests count = overAll count modifyingOriginalD modifyingOriginalDoesntMutateSlicePartTests :: Ref Int -> Effect Unit -modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOriginalDoesntMutateSlicePart +modifyingOriginalDoesntMutateSlicePartTests count = overAll 1 count modifyingOriginalDoesntMutateSlicePart where - modifyingOriginalDoesntMutateSlicePart :: forall a b t. TestableArrayF a b D1 t Result + 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 @@ -643,9 +655,9 @@ modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOrigi modifyingOriginalDoesntMutateSlicePart2Tests :: Ref Int -> Effect Unit -modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOriginalDoesntMutateSlicePart2 +modifyingOriginalDoesntMutateSlicePart2Tests count = overAll 1 count modifyingOriginalDoesntMutateSlicePart2 where - modifyingOriginalDoesntMutateSlicePart2 :: forall a b t. TestableArrayF a b D1 t Result + modifyingOriginalDoesntMutateSlicePart2 :: forall a t. TestableArrayF a t Result modifyingOriginalDoesntMutateSlicePart2 (WithIndices os xs) = do let o = unsafePartial $ Array.head os l = TA.length xs @@ -662,9 +674,9 @@ modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOrig copyWithinSelfIsIdentityTests :: Ref Int -> Effect Unit -copyWithinSelfIsIdentityTests count = overAll count copyWithinSelfIsIdentity +copyWithinSelfIsIdentityTests count = overAll 0 count copyWithinSelfIsIdentity where - copyWithinSelfIsIdentity :: forall a b t. TestableArrayF a b D0 t Result + 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)) @@ -673,9 +685,9 @@ copyWithinSelfIsIdentityTests count = overAll count copyWithinSelfIsIdentity copyWithinIsSliceTests :: Ref Int -> Effect Unit -copyWithinIsSliceTests count = overAll count copyWithinIsSlice +copyWithinIsSliceTests count = overAll 1 count copyWithinIsSlice where - copyWithinIsSlice :: forall a b t. TestableArrayF a b D1 t Result + copyWithinIsSlice :: forall a t. TestableArrayF a t Result copyWithinIsSlice (WithIndices os xs) = do let o = unsafePartial $ Array.head os l = TA.length xs @@ -687,9 +699,9 @@ copyWithinIsSliceTests count = overAll count copyWithinIsSlice copyWithinViaSetTypedTests :: Ref Int -> Effect Unit -copyWithinViaSetTypedTests count = overAll count copyWithinViaSetTyped +copyWithinViaSetTypedTests count = overAll 1 count copyWithinViaSetTyped where - copyWithinViaSetTyped :: forall a b t. TestableArrayF a b D1 t Result + copyWithinViaSetTyped :: forall a t. TestableArrayF a t Result copyWithinViaSetTyped (WithIndices os xs) = do let o = unsafePartial $ Array.head os txs <- TA.toArray xs @@ -701,3 +713,27 @@ copyWithinViaSetTypedTests count = overAll count copyWithinViaSetTyped 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' From 051d43b6c2476a22f91097f6fb2bb9f7da0417e8 Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 21 Jun 2021 20:12:20 +0900 Subject: [PATCH 02/34] Run contrib-updater --- .editorconfig | 13 +++++ .github/ISSUE_TEMPLATE/bug-report.md | 19 +++++++ .github/ISSUE_TEMPLATE/change-request.md | 21 ++++++++ .github/ISSUE_TEMPLATE/config.yml | 8 +++ .github/PULL_REQUEST_TEMPLATE.md | 11 ++++ .github/workflows/ci.yml | 34 ++++++++++++ .gitignore | 19 +++---- CHANGELOG.md | 15 ++++-- CONTRIBUTING.md | 5 ++ README.md | 69 +++++++++++++++++++++--- docs/README.md | 3 ++ 11 files changed, 194 insertions(+), 23 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/change-request.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/ci.yml create mode 100644 CONTRIBUTING.md create mode 100644 docs/README.md 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..c47a263 --- /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 here. + - name: Functional Programming Slack + url: https://functionalprogramming.slack.com + about: For casual chat and questions (use https://fpchat-invite.herokuapp.com to join). 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..6b0550f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up a PureScript toolchain + uses: purescript-contrib/setup-purescript@main + + - name: Cache PureScript dependencies + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }} + path: | + .spago + output + + - name: Install dependencies + run: spago install + + - name: Build source + run: spago build --no-install --purs-args '--censor-lib --strict' + + - name: Run tests + run: spago test --no-install diff --git a/.gitignore b/.gitignore index f71c254..7bca306 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,8 @@ -*~ -output/ -bower_components/ -node_modules/ -.psci -.psci_modules/ -yarn-error.log -yarn.lock -generated-docs/ -.spago/ -.psc-ide-port +.* +!.gitignore +!.github +!.editorconfig + +output +generated-docs +bower_components diff --git a/CHANGELOG.md b/CHANGELOG.md index ec49320..d7eea4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -# v11 2021-06-21 +# 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). + +## v11.0.0 [Unreleased] Jorge Acereda has graciously donated this package to __purescript-contrib__. For version 11, we have refactored this library so that it depends only on @@ -11,12 +15,13 @@ 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 -To upgrade to v11, you might need to do a few simple substitutions +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`. - -In v11 of this package, we have also upgraded to PureScript v0.14. - 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/README.md b/README.md index e9efeb9..8f2e831 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,77 @@ -# purescript-arraybuffer +# arraybuffer + [![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: natefaubion](https://img.shields.io/badge/maintainer-jamesdbrock-teal.svg)](https://github.com/jamesdbrock) +[![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. -ArrayBuffer bindings for PureScript. +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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) +* [ECMA-262](https://tc39.es/ecma262/multipage/structured-data.html#sec-arraybuffer-objects) ## Installation Install `arraybuffer` with [Spago](https://github.com/purescript/spago): -``` -spago install purescript-arraybuffer + +```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. +- [Search or start a thread on the PureScript Discourse](https://discourse.purescript.org) if you have general questions. You can also ask questions in the `#purescript` and `#purescript-beginners` channels on the [Functional Programming Slack](https://functionalprogramming.slack.com) ([invite link](https://fpchat-invite.herokuapp.com/)). + +## 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. + +## Other 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 + +* [__text-encoding__](https://pursuit.purescript.org/packages/purescript-text-encoding) + +### Base64 -See https://github.com/AlexaDeWit/purescript-arraybuffer-codecs if you need text/base64 encoding/decoding functions. +* [__base64-codec__](https://pursuit.purescript.org/packages/purescript-base64-codec) 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. From ff799d07584e32cde5ce4492080e9119bb828783 Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 5 Jul 2021 09:23:39 +0900 Subject: [PATCH 03/34] Don't export Typed.part' --- CHANGELOG.md | 5 ++++- src/Data/ArrayBuffer/Typed.purs | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7eea4b..1df7523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ 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). -## v11.0.0 [Unreleased] +## 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__. @@ -25,3 +26,5 @@ 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/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 472a959..b7828a6 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -34,7 +34,7 @@ module Data.ArrayBuffer.Typed , buffer, byteOffset, byteLength, length , compare, eq , class TypedArray - , create, whole, remainder, part, part', empty, fromArray + , create, whole, remainder, part, empty, fromArray , fill, set, setTyped, copyWithin , map, traverse, traverse_, filter , mapWithIndex, traverseWithIndex, traverseWithIndex_, filterWithIndex @@ -137,6 +137,8 @@ part :: forall a t. TypedArray a t => BytesPerType a => ArrayBuffer -> Index -> 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) From 146469d8b90edddda05d6c488177550686dd54a4 Mon Sep 17 00:00:00 2001 From: James Brock Date: Sun, 11 Jul 2021 21:39:21 +0900 Subject: [PATCH 04/34] Split test dependencies out into spago-test.dhall --- .github/workflows/ci.yml | 8 ++++- README.md | 8 +++++ spago-test.dhall | 14 ++++++++ spago.dhall | 10 +----- src/Data/ArrayBuffer/Typed/Unsafe.purs | 42 ------------------------ test/Properties/Typed/Laws.purs | 45 +++++++++++++++++++++++--- 6 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 spago-test.dhall delete mode 100644 src/Data/ArrayBuffer/Typed/Unsafe.purs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b0550f..805034b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,5 +30,11 @@ jobs: - name: Build source run: spago build --no-install --purs-args '--censor-lib --strict' + - name: Install test dependencies + run: spago -x spago-test.dhall install + + - name: Build tests + run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --strict' + - name: Run tests - run: spago test --no-install + run: spago -x spago-test.dhall test --no-install diff --git a/README.md b/README.md index 8f2e831..67ddab0 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,11 @@ These are some other packages which provide more `ArrayBuffer` features. ### Base64 * [__base64-codec__](https://pursuit.purescript.org/packages/purescript-base64-codec) + +## Development + +Run the tests with + +```sh +spago -x spago-test.dhall test +``` diff --git a/spago-test.dhall b/spago-test.dhall new file mode 100644 index 0000000..ab1a012 --- /dev/null +++ b/spago-test.dhall @@ -0,0 +1,14 @@ +let conf = ./spago.dhall +in conf // { +, dependencies = conf.dependencies # + [ "console" + , "foldable-traversable" + , "partial" + , "refs" + , "typelevel-prelude" + , "tuples" + , "quickcheck" + , "quickcheck-laws" + ] +, sources = conf.sources # [ "test/**/*.purs" ] +} diff --git a/spago.dhall b/spago.dhall index 41922dc..c7d8717 100644 --- a/spago.dhall +++ b/spago.dhall @@ -2,25 +2,17 @@ , dependencies = [ "arraybuffer-types" , "arrays" - , "console" , "effect" , "float32" - , "foldable-traversable" , "functions" , "gen" , "maybe" , "nullable" - , "partial" , "prelude" - , "quickcheck" - , "quickcheck-laws" - , "refs" , "tailrec" - , "typelevel-prelude" , "uint" , "unfoldable" - , "tuples" ] , packages = ./packages.dhall -, sources = [ "src/**/*.purs", "test/**/*.purs" ] +, sources = [ "src/**/*.purs" ] } diff --git a/src/Data/ArrayBuffer/Typed/Unsafe.purs b/src/Data/ArrayBuffer/Typed/Unsafe.purs deleted file mode 100644 index facd419..0000000 --- a/src/Data/ArrayBuffer/Typed/Unsafe.purs +++ /dev/null @@ -1,42 +0,0 @@ -module Data.ArrayBuffer.Typed.Unsafe where - -import Data.ArrayBuffer.Typed (class TypedArray, toString) -import Data.ArrayBuffer.Typed as TA -import Data.ArrayBuffer.Types (ArrayView, ArrayViewType) -import Data.Generic.Rep (class Generic) -import Data.Maybe (Maybe(..)) -import Effect.Unsafe (unsafePerformEffect) -import Prelude (class Eq, class Monoid, class Ord, class Semigroup, class Show, bind, discard, pure, void, ($), (+), (<>), (<$>)) -import Test.QuickCheck (class Arbitrary, arbitrary) - -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/Typed/Laws.purs b/test/Properties/Typed/Laws.purs index 5f7d5c5..8cf2f5c 100644 --- a/test/Properties/Typed/Laws.purs +++ b/test/Properties/Typed/Laws.purs @@ -1,19 +1,24 @@ module Test.Properties.Typed.Laws where -import Data.ArrayBuffer.Typed (class TypedArray) +import Prelude +-- import Prelude (class Eq, class Monoid, class Ord, class Semigroup, class Show, bind, discard, pure, void, ($), (+), (<>), (<$>)) +-- import Prelude (class Eq, class Monoid, class Ord, class Semigroup, Unit, discard, void, ($), (+), (<$>), (<<<)) +import Data.ArrayBuffer.Typed (class TypedArray, toString) import Data.ArrayBuffer.Typed.Gen (genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8) -import Data.ArrayBuffer.Typed.Unsafe (AV(..)) 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 Prelude (class Eq, class Monoid, class Ord, class Semigroup, Unit, discard, void, ($), (+), (<$>), (<<<)) -import Test.QuickCheck (class Arbitrary) +import Test.QuickCheck (class Arbitrary, arbitrary) import Test.QuickCheck.Gen (Gen) import Test.QuickCheck.Laws.Data (checkEq, checkMonoid, checkOrd, checkSemigroup) import Type.Prelude (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 @@ -102,3 +107,35 @@ typedArrayLaws count = do 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 \ No newline at end of file From 97baec38b93d202ef6feaa8cd6abcebc0a73410c Mon Sep 17 00:00:00 2001 From: James Brock Date: Sun, 11 Jul 2021 21:42:57 +0900 Subject: [PATCH 05/34] 'bower install' resolutions --- bower.json | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/bower.json b/bower.json index 9f5755a..0157b1d 100644 --- a/bower.json +++ b/bower.json @@ -28,5 +28,45 @@ "purescript-quickcheck": "^7.0.0", "purescript-quickcheck-combinators": "~0.1.3", "purescript-quickcheck-laws": "^6.0.0" + }, + "resolutions": { + "purescript-effect": "^3.0.0", + "purescript-functions": "^5.0.0", + "purescript-partial": "^3.0.0", + "purescript-prelude": "^5.0.0", + "purescript-maybe": "^5.0.0", + "purescript-quickcheck": "^7.0.0", + "purescript-control": "^5.0.0", + "purescript-invariant": "^5.0.0", + "purescript-newtype": "^4.0.0", + "purescript-quickcheck-laws": "^6.0.0", + "purescript-arrays": "^6.0.0", + "purescript-enums": "^5.0.0", + "purescript-foldable-traversable": "^5.0.0", + "purescript-console": "^5.0.0", + "purescript-exceptions": "^5.0.0", + "purescript-gen": "^3.0.0", + "purescript-either": "^5.0.0", + "purescript-integers": "^5.0.0", + "purescript-lazy": "^5.0.0", + "purescript-lcg": "^3.0.0", + "purescript-lists": "^6.0.0", + "purescript-identity": "^5.0.0", + "purescript-math": "^3.0.0", + "purescript-nonempty": "^6.0.0", + "purescript-record": "^3.0.0", + "purescript-st": "^5.0.0", + "purescript-strings": "^5.0.0", + "purescript-transformers": "^5.0.0", + "purescript-tuples": "^6.0.0", + "purescript-unfoldable": "^5.0.0", + "purescript-tailrec": "^5.0.0", + "purescript-unsafe-coerce": "^5.0.0", + "purescript-orders": "^5.0.0", + "purescript-bifunctors": "^5.0.0", + "purescript-random": "^5.0.0", + "purescript-distributive": "^5.0.0", + "purescript-refs": "^5.0.0", + "purescript-type-equality": "^4.0.0" } } From 9ec68e53f073e4f9b377c89de9d664bf7511492a Mon Sep 17 00:00:00 2001 From: James Brock Date: Sun, 11 Jul 2021 21:30:05 +0900 Subject: [PATCH 06/34] float32 and uint are back in package-sets --- packages.dhall | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/packages.dhall b/packages.dhall index 446440b..87f92e8 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,34 +1,10 @@ let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.14.1-20210419/packages.dhall sha256:d9a082ffb5c0fabf689574f0680e901ca6f924e01acdbece5eeedd951731375a + https://github.com/purescript/package-sets/releases/download/psc-0.14.2-20210713/packages.dhall sha256:654c3148cb995f642c73b4508d987d9896e2ad3ea1d325a1e826c034c0d3cd7b let overrides = {=} -let additions = - { float32 = - { dependencies = - [ "effect" - , "gen" - , "maybe" - , "prelude" - ] - , repo = - "https://github.com/athanclark/purescript-float32.git" - , version = - "v0.2.0" - } - , uint = - { dependencies = - [ "effect" - , "math" - , "maybe" - , "quickcheck" - , "quickcheck-laws" - ] - , repo = "https://github.com/purescript-contrib/purescript-uint.git" - , version = "v5.1.4" - } - } +let additions = {=} in upstream // overrides // additions From 76b8eb03fd24759044db038c50cf79f471255d03 Mon Sep 17 00:00:00 2001 From: James Brock Date: Fri, 16 Jul 2021 19:05:55 +0900 Subject: [PATCH 07/34] README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 67ddab0..7113484 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ access of aligned local-machine-endian types, for in-process flat memory operati The `DataView` module provides a view into an `ArrayBuffer` for inter-process flat memory operations. -* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) -* [ECMA-262](https://tc39.es/ecma262/multipage/structured-data.html#sec-arraybuffer-objects) +* [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 @@ -53,7 +53,7 @@ You can contribute to `arraybuffer` in several ways: 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. -## Other packages +## Related packages These are some other packages which provide more `ArrayBuffer` features. From e9c896d369b02e5096d6d125f8a66d4b0f347405 Mon Sep 17 00:00:00 2001 From: James Brock Date: Fri, 16 Jul 2021 19:13:16 +0900 Subject: [PATCH 08/34] v11.0.0 From 26a3bc5900d38960de3f7232e2ba6dd2fdc7bd2e Mon Sep 17 00:00:00 2001 From: James Brock Date: Fri, 16 Jul 2021 19:19:52 +0900 Subject: [PATCH 09/34] spago bump-version --no-dry-run patch --- LICENSE.txt | 21 ++++++++++++ bower.json | 98 +++++++++++++++-------------------------------------- spago.dhall | 2 ++ 3 files changed, 51 insertions(+), 70 deletions(-) create mode 100644 LICENSE.txt 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/bower.json b/bower.json index 0157b1d..e11d42e 100644 --- a/bower.json +++ b/bower.json @@ -1,72 +1,30 @@ { - "name": "purescript-arraybuffer", - "license": "MIT", - "repository": { - "type": "git", - "url": "git://github.com/jacereda/purescript-arraybuffer.git" - }, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "dependencies": { - "purescript-prelude": "^5.0.0", - "purescript-functions": "^5.0.0", - "purescript-arraybuffer-types": "^2.0.0", - "purescript-maybe": "^5.0.0", - "purescript-effect": "^3.0.0", - "purescript-nullable": "^5.0.0", - "purescript-typelevel": "^6.0.0", - "purescript-uint": "^5.1.4", - "purescript-partial": "^3.0.0", - "purescript-float32": "~0.2.0" - }, - "devDependencies": { - "purescript-debug": "^5.0.0", - "purescript-quickcheck": "^7.0.0", - "purescript-quickcheck-combinators": "~0.1.3", - "purescript-quickcheck-laws": "^6.0.0" - }, - "resolutions": { - "purescript-effect": "^3.0.0", - "purescript-functions": "^5.0.0", - "purescript-partial": "^3.0.0", - "purescript-prelude": "^5.0.0", - "purescript-maybe": "^5.0.0", - "purescript-quickcheck": "^7.0.0", - "purescript-control": "^5.0.0", - "purescript-invariant": "^5.0.0", - "purescript-newtype": "^4.0.0", - "purescript-quickcheck-laws": "^6.0.0", - "purescript-arrays": "^6.0.0", - "purescript-enums": "^5.0.0", - "purescript-foldable-traversable": "^5.0.0", - "purescript-console": "^5.0.0", - "purescript-exceptions": "^5.0.0", - "purescript-gen": "^3.0.0", - "purescript-either": "^5.0.0", - "purescript-integers": "^5.0.0", - "purescript-lazy": "^5.0.0", - "purescript-lcg": "^3.0.0", - "purescript-lists": "^6.0.0", - "purescript-identity": "^5.0.0", - "purescript-math": "^3.0.0", - "purescript-nonempty": "^6.0.0", - "purescript-record": "^3.0.0", - "purescript-st": "^5.0.0", - "purescript-strings": "^5.0.0", - "purescript-transformers": "^5.0.0", - "purescript-tuples": "^6.0.0", - "purescript-unfoldable": "^5.0.0", - "purescript-tailrec": "^5.0.0", - "purescript-unsafe-coerce": "^5.0.0", - "purescript-orders": "^5.0.0", - "purescript-bifunctors": "^5.0.0", - "purescript-random": "^5.0.0", - "purescript-distributive": "^5.0.0", - "purescript-refs": "^5.0.0", - "purescript-type-equality": "^4.0.0" - } + "name": "purescript-arraybuffer", + "license": [ + "MIT" + ], + "repository": { + "type": "git", + "url": "https://github.com/purescript-contrib/purescript-arraybuffer" + }, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-arraybuffer-types": "^v3.0.0", + "purescript-arrays": "^v6.0.1", + "purescript-effect": "^v3.0.0", + "purescript-float32": "^v1.0.0", + "purescript-functions": "^v5.0.0", + "purescript-gen": "^v3.0.0", + "purescript-maybe": "^v5.0.0", + "purescript-nullable": "^v5.0.0", + "purescript-prelude": "^v5.0.1", + "purescript-tailrec": "^v5.0.1", + "purescript-uint": "^v6.0.3", + "purescript-unfoldable": "^v5.0.0" + } } diff --git a/spago.dhall b/spago.dhall index c7d8717..48fc095 100644 --- a/spago.dhall +++ b/spago.dhall @@ -15,4 +15,6 @@ ] , packages = ./packages.dhall , sources = [ "src/**/*.purs" ] +, license = "MIT" +, repository = "https://github.com/purescript-contrib/purescript-arraybuffer" } From 23eaac80d0f20f6de35b25374daf52b4ec75cc2c Mon Sep 17 00:00:00 2001 From: James Brock Date: Fri, 16 Jul 2021 19:42:13 +0900 Subject: [PATCH 10/34] =?UTF-8?q?v11.0.0=20=E2=86=92=20v11.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From d1115c754e8d02840c3dc1b7135fc96ea071c745 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Sun, 25 Jul 2021 12:34:35 -0400 Subject: [PATCH 11/34] Replace Slack links with Discord (#33) --- .github/ISSUE_TEMPLATE/config.yml | 8 ++++---- README.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index c47a263..d63c9d7 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,7 +2,7 @@ blank_issues_enabled: false contact_links: - name: PureScript Discourse url: https://discourse.purescript.org/ - about: Ask and answer questions here. - - name: Functional Programming Slack - url: https://functionalprogramming.slack.com - about: For casual chat and questions (use https://fpchat-invite.herokuapp.com to join). + about: Ask and answer questions on the PureScript discussion forum. + - name: PureScript Discord + url: https://discord.com/invite/sMqwYUbvz6/ + about: Ask and answer questions on the PureScript chat. diff --git a/README.md b/README.md index 7113484..fc6d01c 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ spago install arraybuffer 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. -- [Search or start a thread on the PureScript Discourse](https://discourse.purescript.org) if you have general questions. You can also ask questions in the `#purescript` and `#purescript-beginners` channels on the [Functional Programming Slack](https://functionalprogramming.slack.com) ([invite link](https://fpchat-invite.herokuapp.com/)). +- Ask general questions on the [PureScript Discourse](https://discourse.purescript.org) forum or the [PureScript Discord](https://discord.com/invite/sMqwYUbvz6) chat. ## Contributing From edccb06d7c5bc4b98b2d73eca60e40f49b03e106 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Wed, 28 Jul 2021 11:32:08 -0400 Subject: [PATCH 12/34] Update to the latest package set --- .travis.yml | 9 --------- package.json | 9 --------- packages.dhall | 4 +--- 3 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 .travis.yml delete mode 100644 package.json diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1f93807..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: node_js -sudo: required -dist: trusty -node_js: 8 -install: - - npm install -g purescript pulp bower -script: - - bower install - - pulp test diff --git a/package.json b/package.json deleted file mode 100644 index a792c5d..0000000 --- a/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "purescript-arraybuffer", - "version": "11.0.0", - "main": "index.js", - "repository": "git@github.com:jacereda/purescript-arraybuffer.git", - "author": "https://github.com/jacereda", - "license": "MIT", - "devDependencies": {} -} \ No newline at end of file diff --git a/packages.dhall b/packages.dhall index 87f92e8..bea1ce8 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,10 +1,8 @@ - let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.14.2-20210713/packages.dhall sha256:654c3148cb995f642c73b4508d987d9896e2ad3ea1d325a1e826c034c0d3cd7b + https://github.com/purescript/package-sets/releases/download/psc-0.14.3-20210722/packages.dhall sha256:1ceb43aa59436bf5601bac45f6f3781c4e1f0e4c2b8458105b018e5ed8c30f8c let overrides = {=} let additions = {=} in upstream // overrides // additions - From 20f4de11f92ebb7fa78cd4ca67b2d4b707721637 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Wed, 4 Aug 2021 13:02:21 -0400 Subject: [PATCH 13/34] Replace Discord links with PS chat --- .github/ISSUE_TEMPLATE/config.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index d63c9d7..8d7661e 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -4,5 +4,5 @@ contact_links: url: https://discourse.purescript.org/ about: Ask and answer questions on the PureScript discussion forum. - name: PureScript Discord - url: https://discord.com/invite/sMqwYUbvz6/ + url: https://purescript.org/chat about: Ask and answer questions on the PureScript chat. diff --git a/README.md b/README.md index fc6d01c..72d7c55 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ spago install arraybuffer 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://discord.com/invite/sMqwYUbvz6) chat. +- Ask general questions on the [PureScript Discourse](https://discourse.purescript.org) forum or the [PureScript Discord](https://purescript.org/chat) chat. ## Contributing From 3e8cb28b8372adf74bca220451fdad6008cabe9a Mon Sep 17 00:00:00 2001 From: James Brock Date: Tue, 21 Sep 2021 14:20:22 +0900 Subject: [PATCH 14/34] Delete the TypedArray polyfill The `polyFill()` for TypedArray was causing problems with `purs bundle` v0.14.4. https://github.com/purescript-contrib/purescript-arraybuffer/issues/34 The reference link which the `polyFill()` function comments referred to is dead. Add a section on polyfills to the README, with new reference links. --- CHANGELOG.md | 6 ++++++ README.md | 17 +++++++++++++++++ src/Data/ArrayBuffer/Typed.js | 19 ------------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1df7523..b4a8950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ 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 + +@jamesdbrock 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.0 Jorge Acereda has graciously donated this package to __purescript-contrib__. diff --git a/README.md b/README.md index 72d7c55..749faf0 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,23 @@ You can contribute to `arraybuffer` in several ways: 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 implemtations 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. diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index cf2d733..2ab0cb6 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -1,24 +1,5 @@ "use strict"; - - -// Lightweight polyfill for ie - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill -function polyFill () { - var typedArrayTypes = - [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array - , Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array - ]; - - for (var k in typedArrayTypes) { - for (var v in Array.prototype) { - if (Array.prototype.hasOwnProperty(v) && !typedArrayTypes[k].prototype.hasOwnProperty(v)) - typedArrayTypes[k].prototype[v] = Array.prototype[v]; - } - } -}; - -polyFill(); - // module Data.ArrayBuffer.Typed exports.buffer = function buffer (v) { From 674d443b3cb187b201282a519a2c8a3835ea6f38 Mon Sep 17 00:00:00 2001 From: James Brock Date: Wed, 22 Sep 2021 01:09:54 +0900 Subject: [PATCH 15/34] README fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 749faf0..c89142a 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ 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 implemtations are available in your target +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). From d29c01f0421c41cfa5e873e40fbac1a8ecdac5c2 Mon Sep 17 00:00:00 2001 From: James Brock Date: Wed, 22 Sep 2021 01:12:02 +0900 Subject: [PATCH 16/34] prep for v11.0.2 --- CHANGELOG.md | 5 +++-- bower.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4a8950..1830534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,9 @@ 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 +## v11.0.2 -@jamesdbrock Delete the `TypedArray` polyfill which was preventing this +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 @@ -34,3 +34,4 @@ to the type declarations in your own dependent code: * 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/bower.json b/bower.json index e11d42e..4d6947c 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,7 @@ "output" ], "dependencies": { - "purescript-arraybuffer-types": "^v3.0.0", + "purescript-arraybuffer-types": "^v3.0.1", "purescript-arrays": "^v6.0.1", "purescript-effect": "^v3.0.0", "purescript-float32": "^v1.0.0", From ff9e181c20b2a5f0b0cd6d7448818d366e50c232 Mon Sep 17 00:00:00 2001 From: James Brock Date: Wed, 22 Sep 2021 01:14:15 +0900 Subject: [PATCH 17/34] =?UTF-8?q?v11.0.1=20=E2=86=92=20v11.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 341d123426c0be6e41c1992d4419c2495fbd9350 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 23 Sep 2021 20:34:23 +0900 Subject: [PATCH 18/34] Revert to v11.0.1 for issue #37 --- .github/ISSUE_TEMPLATE/config.yml | 8 ++++---- .travis.yml | 9 +++++++++ CHANGELOG.md | 7 ------- README.md | 19 +------------------ bower.json | 2 +- package.json | 9 +++++++++ packages.dhall | 4 +++- src/Data/ArrayBuffer/Typed.js | 19 +++++++++++++++++++ 8 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 .travis.yml create mode 100644 package.json diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 8d7661e..c47a263 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,7 +2,7 @@ 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. + about: Ask and answer questions here. + - name: Functional Programming Slack + url: https://functionalprogramming.slack.com + about: For casual chat and questions (use https://fpchat-invite.herokuapp.com to join). diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1f93807 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +sudo: required +dist: trusty +node_js: 8 +install: + - npm install -g purescript pulp bower +script: + - bower install + - pulp test diff --git a/CHANGELOG.md b/CHANGELOG.md index 1830534..1df7523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,6 @@ 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). -## 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.0 Jorge Acereda has graciously donated this package to __purescript-contrib__. @@ -34,4 +28,3 @@ to the type declarations in your own dependent code: * 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/README.md b/README.md index c89142a..7113484 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ spago install arraybuffer 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. +- [Search or start a thread on the PureScript Discourse](https://discourse.purescript.org) if you have general questions. You can also ask questions in the `#purescript` and `#purescript-beginners` channels on the [Functional Programming Slack](https://functionalprogramming.slack.com) ([invite link](https://fpchat-invite.herokuapp.com/)). ## Contributing @@ -53,23 +53,6 @@ You can contribute to `arraybuffer` in several ways: 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. diff --git a/bower.json b/bower.json index 4d6947c..e11d42e 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,7 @@ "output" ], "dependencies": { - "purescript-arraybuffer-types": "^v3.0.1", + "purescript-arraybuffer-types": "^v3.0.0", "purescript-arrays": "^v6.0.1", "purescript-effect": "^v3.0.0", "purescript-float32": "^v1.0.0", diff --git a/package.json b/package.json new file mode 100644 index 0000000..a792c5d --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "purescript-arraybuffer", + "version": "11.0.0", + "main": "index.js", + "repository": "git@github.com:jacereda/purescript-arraybuffer.git", + "author": "https://github.com/jacereda", + "license": "MIT", + "devDependencies": {} +} \ No newline at end of file diff --git a/packages.dhall b/packages.dhall index bea1ce8..87f92e8 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,8 +1,10 @@ + let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.14.3-20210722/packages.dhall sha256:1ceb43aa59436bf5601bac45f6f3781c4e1f0e4c2b8458105b018e5ed8c30f8c + https://github.com/purescript/package-sets/releases/download/psc-0.14.2-20210713/packages.dhall sha256:654c3148cb995f642c73b4508d987d9896e2ad3ea1d325a1e826c034c0d3cd7b let overrides = {=} let additions = {=} in upstream // overrides // additions + diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index 2ab0cb6..cf2d733 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -1,5 +1,24 @@ "use strict"; + + +// Lightweight polyfill for ie - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill +function polyFill () { + var typedArrayTypes = + [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array + , Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array + ]; + + for (var k in typedArrayTypes) { + for (var v in Array.prototype) { + if (Array.prototype.hasOwnProperty(v) && !typedArrayTypes[k].prototype.hasOwnProperty(v)) + typedArrayTypes[k].prototype[v] = Array.prototype[v]; + } + } +}; + +polyFill(); + // module Data.ArrayBuffer.Typed exports.buffer = function buffer (v) { From 5c8fc86f9ae3d548d8a6e998209824175be7615d Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 23 Sep 2021 21:58:36 +0900 Subject: [PATCH 19/34] =?UTF-8?q?v11.0.2=20=E2=86=92=20v11.0.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 36aa9e2f689dc549f753988ee6510219ef99bbc8 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 23 Sep 2021 22:03:53 +0900 Subject: [PATCH 20/34] Revert back to v11.0.2 for issue #37 --- .github/ISSUE_TEMPLATE/config.yml | 8 ++++---- .travis.yml | 9 --------- CHANGELOG.md | 7 +++++++ README.md | 19 ++++++++++++++++++- bower.json | 2 +- package.json | 9 --------- packages.dhall | 4 +--- src/Data/ArrayBuffer/Typed.js | 19 ------------------- 8 files changed, 31 insertions(+), 46 deletions(-) delete mode 100644 .travis.yml delete mode 100644 package.json diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index c47a263..8d7661e 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,7 +2,7 @@ blank_issues_enabled: false contact_links: - name: PureScript Discourse url: https://discourse.purescript.org/ - about: Ask and answer questions here. - - name: Functional Programming Slack - url: https://functionalprogramming.slack.com - about: For casual chat and questions (use https://fpchat-invite.herokuapp.com to join). + 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/.travis.yml b/.travis.yml deleted file mode 100644 index 1f93807..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: node_js -sudo: required -dist: trusty -node_js: 8 -install: - - npm install -g purescript pulp bower -script: - - bower install - - pulp test diff --git a/CHANGELOG.md b/CHANGELOG.md index 1df7523..1830534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ 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). +## 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.0 Jorge Acereda has graciously donated this package to __purescript-contrib__. @@ -28,3 +34,4 @@ to the type declarations in your own dependent code: * 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/README.md b/README.md index 7113484..c89142a 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ spago install arraybuffer 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. -- [Search or start a thread on the PureScript Discourse](https://discourse.purescript.org) if you have general questions. You can also ask questions in the `#purescript` and `#purescript-beginners` channels on the [Functional Programming Slack](https://functionalprogramming.slack.com) ([invite link](https://fpchat-invite.herokuapp.com/)). +- Ask general questions on the [PureScript Discourse](https://discourse.purescript.org) forum or the [PureScript Discord](https://purescript.org/chat) chat. ## Contributing @@ -53,6 +53,23 @@ You can contribute to `arraybuffer` in several ways: 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. diff --git a/bower.json b/bower.json index e11d42e..4d6947c 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,7 @@ "output" ], "dependencies": { - "purescript-arraybuffer-types": "^v3.0.0", + "purescript-arraybuffer-types": "^v3.0.1", "purescript-arrays": "^v6.0.1", "purescript-effect": "^v3.0.0", "purescript-float32": "^v1.0.0", diff --git a/package.json b/package.json deleted file mode 100644 index a792c5d..0000000 --- a/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "purescript-arraybuffer", - "version": "11.0.0", - "main": "index.js", - "repository": "git@github.com:jacereda/purescript-arraybuffer.git", - "author": "https://github.com/jacereda", - "license": "MIT", - "devDependencies": {} -} \ No newline at end of file diff --git a/packages.dhall b/packages.dhall index 87f92e8..bea1ce8 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,10 +1,8 @@ - let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.14.2-20210713/packages.dhall sha256:654c3148cb995f642c73b4508d987d9896e2ad3ea1d325a1e826c034c0d3cd7b + https://github.com/purescript/package-sets/releases/download/psc-0.14.3-20210722/packages.dhall sha256:1ceb43aa59436bf5601bac45f6f3781c4e1f0e4c2b8458105b018e5ed8c30f8c let overrides = {=} let additions = {=} in upstream // overrides // additions - diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index cf2d733..2ab0cb6 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -1,24 +1,5 @@ "use strict"; - - -// Lightweight polyfill for ie - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill -function polyFill () { - var typedArrayTypes = - [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array - , Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array - ]; - - for (var k in typedArrayTypes) { - for (var v in Array.prototype) { - if (Array.prototype.hasOwnProperty(v) && !typedArrayTypes[k].prototype.hasOwnProperty(v)) - typedArrayTypes[k].prototype[v] = Array.prototype[v]; - } - } -}; - -polyFill(); - // module Data.ArrayBuffer.Typed exports.buffer = function buffer (v) { From c77bd25981653fae35ee82ef4cb44b1149f1862b Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 23 Sep 2021 22:24:26 +0900 Subject: [PATCH 21/34] Prep for v12.0.0 --- CHANGELOG.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1830534..16ed4a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,33 @@ 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). +## 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__. From 383d746fc355a3c12494c9b1f7686b519183dbc4 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 23 Sep 2021 22:33:13 +0900 Subject: [PATCH 22/34] =?UTF-8?q?v11.0.3=20=E2=86=92=20v12.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 51271ec72102f4dcb7064f4d9220700ebf5bd8f2 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Fri, 19 Nov 2021 23:10:04 -0500 Subject: [PATCH 23/34] Introduce purs-tidy formatter (#38) * Add purs-tidy formatter * Run purs-tidy * review --- .github/workflows/ci.yml | 5 + .gitignore | 1 + .tidyrc.json | 10 + src/Data/ArrayBuffer/ArrayBuffer.purs | 2 + src/Data/ArrayBuffer/ArrayBuffer/Gen.purs | 5 +- src/Data/ArrayBuffer/DataView.purs | 312 +++++---- src/Data/ArrayBuffer/DataView/Gen.purs | 26 +- src/Data/ArrayBuffer/Typed.purs | 129 +++- src/Data/ArrayBuffer/Typed/Gen.purs | 30 +- src/Data/ArrayBuffer/ValueMapping.purs | 47 +- test/Main.purs | 1 - test/Properties.purs | 1 - test/Properties/ArrayBuffer.purs | 1 - test/Properties/DataView.purs | 110 +-- test/Properties/Typed/Laws.purs | 20 +- test/Properties/TypedArray.purs | 813 +++++++++++----------- 16 files changed, 836 insertions(+), 677 deletions(-) create mode 100644 .tidyrc.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 805034b..4aaad3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,8 @@ jobs: - name: Set up a PureScript toolchain uses: purescript-contrib/setup-purescript@main + with: + purs-tidy: "latest" - name: Cache PureScript dependencies uses: actions/cache@v2 @@ -38,3 +40,6 @@ jobs: - name: Run tests run: spago -x spago-test.dhall test --no-install + + - name: Check formatting + run: purs-tidy check src test diff --git a/.gitignore b/.gitignore index 7bca306..7e82b68 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ !.gitignore !.github !.editorconfig +!.tidyrc.json output generated-docs 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/src/Data/ArrayBuffer/ArrayBuffer.purs b/src/Data/ArrayBuffer/ArrayBuffer.purs index 9bedd45..fecb62b 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.purs +++ b/src/Data/ArrayBuffer/ArrayBuffer.purs @@ -14,6 +14,7 @@ import Effect.Uncurried (EffectFn1, runEffectFn1) -- | Create an `ArrayBuffer` with the given capacity. empty :: ByteLength -> Effect ArrayBuffer empty l = runEffectFn1 emptyImpl l + foreign import emptyImpl :: EffectFn1 ByteLength ArrayBuffer -- | Represents the length of an `ArrayBuffer` in bytes. @@ -22,4 +23,5 @@ foreign import byteLength :: ArrayBuffer -> ByteLength -- | Returns a new `ArrayBuffer` whose contents are a copy of this ArrayBuffer's bytes from begin, inclusive, up to end, exclusive. 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 index dbe909a..381931c 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer/Gen.purs +++ b/src/Data/ArrayBuffer/ArrayBuffer/Gen.purs @@ -6,8 +6,5 @@ import Data.ArrayBuffer.Typed.Gen (genTypedArray, genUint8) import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array) import Prelude ((<$>)) - -genArrayBuffer :: forall m - . MonadGen m - => m ArrayBuffer +genArrayBuffer :: forall m. MonadGen m => m ArrayBuffer genArrayBuffer = buffer <$> (genTypedArray genUint8 :: m Uint8Array) diff --git a/src/Data/ArrayBuffer/DataView.purs b/src/Data/ArrayBuffer/DataView.purs index 4daca87..610090e 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -1,48 +1,48 @@ -- | 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 + ( 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) @@ -67,15 +67,16 @@ instance eqEndian :: Eq Endian where -- | View mapping the whole `ArrayBuffer`. foreign import whole :: ArrayBuffer -> 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`. 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. @@ -87,86 +88,129 @@ foreign import byteOffset :: DataView -> ByteOffset -- | Represents the length of this view. foreign import byteLength :: DataView -> ByteLength - - -getter :: forall t. - { functionName :: String - , bytesPerValue :: ByteLength - , littleEndian :: Boolean - } - -> DataView -> ByteOffset -> Effect (Maybe t) -getter data' d o = toMaybe <$> - runEffectFn3 getterImpl +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 - } d o -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 = - let le = endian == LE - pnm = "get" <> reflectSymbol (SProxy :: SProxy name) - bpv = byteWidth prx - in 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) + } + 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 (SProxy :: SProxy 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 + :: 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 d o t = runEffectFn4 setterImpl d o 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 = - let le = endian == LE - pnm = "set" <> reflectSymbol (SProxy :: SProxy name) - bpv = byteWidth prx - in setter { functionName: pnm - , bytesPerValue: bpv - , littleEndian: 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 (SProxy :: SProxy name) + bpv = byteWidth prx + + setter + { functionName: pnm + , bytesPerValue: bpv + , littleEndian: le + } -- | Fetch int8 value at a certain index in a `DataView`. getInt8 :: DataView -> ByteOffset -> Effect (Maybe Int) @@ -224,23 +268,32 @@ getFloat64be = getBE (Proxy :: Proxy Float64) 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 + :: 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 + :: 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`. @@ -267,7 +320,6 @@ setInt32le = setLE (Proxy :: Proxy Int32) setUint8 :: DataView -> ByteOffset -> UInt -> Effect Boolean setUint8 = setLE (Proxy :: Proxy Uint8) - -- | Store big-endian uint16 value at a certain index in a `DataView`. setUint16be :: DataView -> ByteOffset -> UInt -> Effect Boolean setUint16be = setBE (Proxy :: Proxy Uint16) diff --git a/src/Data/ArrayBuffer/DataView/Gen.purs b/src/Data/ArrayBuffer/DataView/Gen.purs index f7e55ca..cd1c974 100644 --- a/src/Data/ArrayBuffer/DataView/Gen.purs +++ b/src/Data/ArrayBuffer/DataView/Gen.purs @@ -11,27 +11,23 @@ import Data.Unfoldable (replicateA) import Prelude ((<$>), bind, (<=), (-), pure) import Type.Proxy (Proxy(..)) - -genDataView :: forall m - . MonadGen m - => m DataView +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 + :: 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 diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index b7828a6..b8d593b 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -28,25 +28,65 @@ -- | - `toString` prints to a CSV, `join` allows you to supply the delimiter -- | - `toArray` returns an array of numeric values - module Data.ArrayBuffer.Typed - ( Index, Length - , buffer, byteOffset, byteLength, length - , compare, eq + ( 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 + , 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 + , 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 import Data.Array (length) as A @@ -64,7 +104,6 @@ import Prelude (class Eq, class Ord, Ordering, Unit, flip, pure, ($), (&&), (*), import Prelude as Prelude import Type.Proxy (Proxy(..)) - -- | `ArrayBuffer` being mapped by the typed array. foreign import buffer :: forall a. ArrayView a -> ArrayBuffer @@ -77,6 +116,7 @@ foreign import byteLength :: forall a. ArrayView a -> ByteLength -- | Represents the number of elements in this typed array. length :: forall a. ArrayView a -> Length length = lengthImpl + foreign import lengthImpl :: forall a. ArrayView a -> Length -- object creator implementations for each typed array @@ -91,32 +131,38 @@ foreign import newInt8Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Null foreign import newFloat32Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Float32Array foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Float64Array - -- | Value-oriented array index. type Index = Int -- | Value-oriented array length. type Length = Int - class BinaryValue a t <= TypedArray (a :: ArrayViewType) (t :: Type) | a -> t where create :: forall x. EffectFn3 x (Nullable ByteOffset) (Nullable ByteLength) (ArrayView a) instance typedArrayUint8Clamped :: TypedArray Uint8Clamped UInt where create = newUint8ClampedArray + instance typedArrayUint32 :: TypedArray Uint32 UInt where create = newUint32Array + 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 @@ -127,7 +173,8 @@ 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) + 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 @@ -135,7 +182,8 @@ 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) + 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 @@ -153,6 +201,7 @@ 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. @@ -162,7 +211,6 @@ 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 buffer and -- | typed array as well. map :: forall a t. TypedArray a t => (t -> t) -> ArrayView a -> ArrayView a @@ -176,6 +224,7 @@ 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. @@ -199,6 +248,7 @@ 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. @@ -212,6 +262,7 @@ 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. @@ -224,6 +275,7 @@ 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. @@ -238,11 +290,13 @@ 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. @@ -252,21 +306,25 @@ 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 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. @@ -280,21 +338,25 @@ 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 @@ -330,23 +392,24 @@ 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 +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 = +setInternal lenfn a mo b = do let o = fromMaybe 0 mo - in 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 - + 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 @@ -355,36 +418,43 @@ setTyped = setInternal length -- | Copy part of the contents of a typed array into a new buffer, between some 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 buffer, 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 -> 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 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 ! @@ -392,6 +462,7 @@ infixl 3 at as ! -- | Turn typed array into an array. 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) -- | Compare 2 typed arrays. diff --git a/src/Data/ArrayBuffer/Typed/Gen.purs b/src/Data/ArrayBuffer/Typed/Gen.purs index 678c14d..b2091ff 100644 --- a/src/Data/ArrayBuffer/Typed/Gen.purs +++ b/src/Data/ArrayBuffer/Typed/Gen.purs @@ -14,12 +14,12 @@ 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 + :: 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 @@ -47,18 +47,20 @@ 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 +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 + :: 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 diff --git a/src/Data/ArrayBuffer/ValueMapping.purs b/src/Data/ArrayBuffer/ValueMapping.purs index e262b2c..70ac4f7 100644 --- a/src/Data/ArrayBuffer/ValueMapping.purs +++ b/src/Data/ArrayBuffer/ValueMapping.purs @@ -1,12 +1,11 @@ -- | This module represents type-level mappings between `ArrayViewType`s -- | and meaningful data. module Data.ArrayBuffer.ValueMapping - ( class BytesPerType - , byteWidth - , class BinaryValue - , class ShowArrayViewType - ) -where + ( 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 @@ -17,15 +16,32 @@ import Type.Proxy (Proxy) 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 +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 -- | Maps a `TypedArray`’s binary casted value to its computable representation in JavaScript. class BinaryValue (a :: ArrayViewType) (t :: Type) | a -> t @@ -41,6 +57,7 @@ instance binaryValueFloat32 :: BinaryValue Float32 F.Float32 instance binaryValueFloat64 :: BinaryValue Float64 Number class ShowArrayViewType (a :: ArrayViewType) (name :: Symbol) | a -> name + instance showArrayViewTypeUint8Clamped :: ShowArrayViewType Uint8Clamped "Uint8Clamped" instance showArrayViewTypeViewUint32 :: ShowArrayViewType Uint32 "Uint32" instance showArrayViewTypeViewUint16 :: ShowArrayViewType Uint16 "Uint16" diff --git a/test/Main.purs b/test/Main.purs index 40066b3..4ad0759 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -8,6 +8,5 @@ import Test.Properties (propertiesTests) main :: Effect Unit main = do - log "Starting tests..." propertiesTests diff --git a/test/Properties.purs b/test/Properties.purs index 6bf5407..bb529fc 100644 --- a/test/Properties.purs +++ b/test/Properties.purs @@ -8,7 +8,6 @@ import Test.Properties.DataView (dataViewTests) import Test.Properties.TypedArray (typedArrayTests) import Test.Properties.Typed.Laws (typedArrayLaws) - propertiesTests :: Effect Unit propertiesTests = do do diff --git a/test/Properties/ArrayBuffer.purs b/test/Properties/ArrayBuffer.purs index 3be4160..8ab6fe4 100644 --- a/test/Properties/ArrayBuffer.purs +++ b/test/Properties/ArrayBuffer.purs @@ -1,2 +1 @@ module Test.Properties.ArrayBuffer where - diff --git a/test/Properties/DataView.purs b/test/Properties/DataView.purs index a981bf7..e7199bf 100644 --- a/test/Properties/DataView.purs +++ b/test/Properties/DataView.purs @@ -21,7 +21,6 @@ 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" @@ -29,9 +28,8 @@ dataViewTests count = do log " - setLE x o => getLE o === Just x" placingAValueIsThereTests DV.LE count - type TestableViewF a name t q = - Show t + Show t => Eq t => Ord t => Semiring t @@ -42,68 +40,88 @@ type TestableViewF a name t q = => WithOffsetAndValue a t -> q - -overAll :: forall q . Testable q - => Ref Int -> (forall a name t. TestableViewF a name t q) -> Effect Unit +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 $ - let f' :: TestableViewF Uint32 "Uint32" UInt q - f' = f - in f' <$> genWithOffsetAndValue 4 genDataView genUint32 + quickCheckGen do + let + f' :: TestableViewF Uint32 "Uint32" UInt q + f' = f + + f' <$> genWithOffsetAndValue 4 genDataView genUint32 log " - Uint16" - quickCheckGen $ - let f' :: TestableViewF Uint16 "Uint16" UInt q - f' = f - in f' <$> genWithOffsetAndValue 2 genDataView genUint16 + quickCheckGen do + let + f' :: TestableViewF Uint16 "Uint16" UInt q + f' = f + + f' <$> genWithOffsetAndValue 2 genDataView genUint16 log " - Uint8" - quickCheckGen $ - let f' :: TestableViewF Uint8 "Uint8" UInt q - f' = f - in f' <$> genWithOffsetAndValue 1 genDataView genUint8 + quickCheckGen do + let + f' :: TestableViewF Uint8 "Uint8" UInt q + f' = f + + f' <$> genWithOffsetAndValue 1 genDataView genUint8 log " - Int32" - quickCheckGen $ - let f' :: TestableViewF Int32 "Int32" Int q - f' = f - in f' <$> genWithOffsetAndValue 4 genDataView genInt32 + quickCheckGen do + let + f' :: TestableViewF Int32 "Int32" Int q + f' = f + + f' <$> genWithOffsetAndValue 4 genDataView genInt32 log " - Int16" - quickCheckGen $ - let f' :: TestableViewF Int16 "Int16" Int q - f' = f - in f' <$> genWithOffsetAndValue 2 genDataView genInt16 + quickCheckGen do + let + f' :: TestableViewF Int16 "Int16" Int q + f' = f + + f' <$> genWithOffsetAndValue 2 genDataView genInt16 log " - Int8" - quickCheckGen $ - let f' :: TestableViewF Int8 "Int8" Int q - f' = f - in f' <$> genWithOffsetAndValue 1 genDataView genInt8 + quickCheckGen do + let + f' :: TestableViewF Int8 "Int8" Int q + f' = f + + f' <$> genWithOffsetAndValue 1 genDataView genInt8 log " - Float32" - quickCheckGen $ - let f' :: TestableViewF Float32 "Float32" F.Float32 q - f' = f - in f' <$> genWithOffsetAndValue 4 genDataView genFloat32 + quickCheckGen do + let + f' :: TestableViewF Float32 "Float32" F.Float32 q + f' = f + + f' <$> genWithOffsetAndValue 4 genDataView genFloat32 log " - Float64" - quickCheckGen $ - let f' :: TestableViewF Float64 "Float64" Number q - f' = f - in f' <$> genWithOffsetAndValue 8 genDataView genFloat64 + 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) = - let o = unsafePartial $ Array.head os - prx = Proxy :: Proxy a - in unsafePerformEffect do - _ <- DV.set endian prx xs o t - my <- DV.get endian prx xs o - pure (my === Just t) + 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 index 8cf2f5c..b58f08c 100644 --- a/test/Properties/Typed/Laws.purs +++ b/test/Properties/Typed/Laws.purs @@ -1,8 +1,6 @@ module Test.Properties.Typed.Laws where import Prelude --- import Prelude (class Eq, class Monoid, class Ord, class Semigroup, class Show, bind, discard, pure, void, ($), (+), (<>), (<$>)) --- import Prelude (class Eq, class Monoid, class Ord, class Semigroup, Unit, discard, void, ($), (+), (<$>), (<<<)) 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) @@ -29,20 +27,28 @@ class ArrayEl (a :: ArrayViewType) (t :: Type) where 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 @@ -121,12 +127,14 @@ instance eqArrayView :: (TypedArray a t, Eq t) => Eq (AV a t) where instance showArrayView :: (TypedArray a t, Show t) => Show (AV a t) where show (AV a) = "T[" <> s <> "]" - where s = unsafePerformEffect $ toString a + 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 + 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 @@ -138,4 +146,4 @@ instance monoidArrayView :: TypedArray a t => Monoid (AV a t) where instance arbitraryArrayView :: (TypedArray a t, Arbitrary t) => Arbitrary (AV a t) where arbitrary = do xs <- arbitrary - pure $ unsafePerformEffect $ AV <$> TA.fromArray xs \ No newline at end of file + pure $ unsafePerformEffect $ AV <$> TA.fromArray xs diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index 9b054c0..36dfc8c 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -1,6 +1,5 @@ module Test.Properties.TypedArray where - import Prelude import Control.Monad.Gen (suchThat) @@ -107,9 +106,8 @@ typedArrayTests count = do log " - copyWithin o x == setTyped x (slice o x)" copyWithinViaSetTypedTests count - type TestableArrayF a t q = - Show t + Show t => Eq t => Ord t => Semiring t @@ -119,31 +117,36 @@ type TestableArrayF a t q = -> Effect q overAll' - :: forall q. Testable q + :: forall q + . Testable q => Int -- n -> Int -- “minimum n”? - -> Ref Int -> (forall a t. TestableArrayF a t q) -> Effect Unit + -> 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 + 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 @@ -155,564 +158,541 @@ overAll' n mn count f = do 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 + :: 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 + :: 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 + 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 + 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 + 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) = - let b = byteWidth (Proxy :: Proxy a) - in pure $ TA.length xs === (TA.byteLength xs `div` b) + 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 - + 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") - + 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 - + 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' - + 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" - + 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 === [] - + 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 - + 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" - + 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" - + 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 - + 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" - - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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' - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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 - + 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' + 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 @@ -729,9 +709,12 @@ 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' + :: 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 From a5033499ee92a6cff0b7307f62ae14b067cc6de2 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Tue, 22 Mar 2022 14:40:25 -0500 Subject: [PATCH 24/34] Update to PureScript v0.15.0 (#41) * Migrated FFI to ES modules via 'lebab' * Replaced 'export var' with 'export const' * Removed '"use strict";' in FFI files * Update to CI to use 'unstable' purescript * Add CI test: verify 'bower.json' file works via pulp * Ignore spago-based tests (temporarily) * Update Bower dependencies to master or main * Update packages.dhall to 'prepare-0.15' package set * Fix FFI exports * Update SProxy to use Proxy * Installed bower dev dependency: purescript-quickcheck-laws@main * Fix Proxy import * Add changelog entry * Update .github/workflows/ci.yml Co-authored-by: Thomas Honeyman Co-authored-by: Thomas Honeyman --- .github/workflows/ci.yml | 14 ++- CHANGELOG.md | 6 ++ bower.json | 59 +++++------ packages.dhall | 8 +- src/Data/ArrayBuffer/ArrayBuffer.js | 12 +-- src/Data/ArrayBuffer/DataView.js | 34 +++---- src/Data/ArrayBuffer/DataView.purs | 6 +- src/Data/ArrayBuffer/Typed.js | 148 +++++++++++++--------------- test/Properties/Typed/Laws.purs | 2 +- 9 files changed, 147 insertions(+), 142 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4aaad3f..f5d37bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: - name: Set up a PureScript toolchain uses: purescript-contrib/setup-purescript@main with: + purescript: "unstable" purs-tidy: "latest" - name: Cache PureScript dependencies @@ -38,8 +39,17 @@ jobs: - name: Build tests run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --strict' - - name: Run tests - run: spago -x spago-test.dhall test --no-install +# - name: Run tests +# run: spago -x spago-test.dhall test --no-install - name: Check formatting run: purs-tidy check src test + + - name: Verify Bower & Pulp + run: | + npm install bower pulp@16.0.0-0 + npx bower install + npx pulp build -- --censor-lib --strict + if [ -d "test" ]; then + npx pulp test + fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 16ed4a7..982d560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ 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: +- 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 diff --git a/bower.json b/bower.json index 4d6947c..85fd87c 100644 --- a/bower.json +++ b/bower.json @@ -1,30 +1,33 @@ { - "name": "purescript-arraybuffer", - "license": [ - "MIT" - ], - "repository": { - "type": "git", - "url": "https://github.com/purescript-contrib/purescript-arraybuffer" - }, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "dependencies": { - "purescript-arraybuffer-types": "^v3.0.1", - "purescript-arrays": "^v6.0.1", - "purescript-effect": "^v3.0.0", - "purescript-float32": "^v1.0.0", - "purescript-functions": "^v5.0.0", - "purescript-gen": "^v3.0.0", - "purescript-maybe": "^v5.0.0", - "purescript-nullable": "^v5.0.0", - "purescript-prelude": "^v5.0.1", - "purescript-tailrec": "^v5.0.1", - "purescript-uint": "^v6.0.3", - "purescript-unfoldable": "^v5.0.0" - } + "name": "purescript-arraybuffer", + "license": [ + "MIT" + ], + "repository": { + "type": "git", + "url": "https://github.com/purescript-contrib/purescript-arraybuffer" + }, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-arraybuffer-types": "main", + "purescript-arrays": "master", + "purescript-effect": "master", + "purescript-float32": "main", + "purescript-functions": "master", + "purescript-gen": "master", + "purescript-maybe": "master", + "purescript-nullable": "main", + "purescript-prelude": "master", + "purescript-tailrec": "master", + "purescript-uint": "main", + "purescript-unfoldable": "master" + }, + "devDependencies": { + "purescript-quickcheck-laws": "main" + } } diff --git a/packages.dhall b/packages.dhall index bea1ce8..582d6d3 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,8 +1,4 @@ let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.14.3-20210722/packages.dhall sha256:1ceb43aa59436bf5601bac45f6f3781c4e1f0e4c2b8458105b018e5ed8c30f8c + https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall -let overrides = {=} - -let additions = {=} - -in upstream // overrides // additions +in upstream diff --git a/src/Data/ArrayBuffer/ArrayBuffer.js b/src/Data/ArrayBuffer/ArrayBuffer.js index b341921..9bb2fc1 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.js +++ b/src/Data/ArrayBuffer/ArrayBuffer.js @@ -1,15 +1,13 @@ -"use strict"; - // module Data.ArrayBuffer.ArrayBuffer -exports.emptyImpl = function empty (s) { +export function emptyImpl(s) { return new ArrayBuffer(s); }; -exports.byteLength = function byteLength (a) { +export function byteLength(a) { return a.byteLength; -}; +} -exports.sliceImpl = function sliceImpl (a, s, e) { +export function sliceImpl(a, s, e) { return a.slice(s, e); -}; +} diff --git a/src/Data/ArrayBuffer/DataView.js b/src/Data/ArrayBuffer/DataView.js index 6bfee81..1eeb060 100644 --- a/src/Data/ArrayBuffer/DataView.js +++ b/src/Data/ArrayBuffer/DataView.js @@ -1,43 +1,41 @@ -"use strict"; - // module Data.ArrayBuffer.DataView -exports.whole = function whole (b) { +export function whole(b) { return new DataView(b); -}; +} -exports.remainderImpl = function remainderImpl (b,i) { +export function remainderImpl(b, i) { return new DataView(b,i); -}; +} -exports.partImpl = function partImpl (b,i,j) { +export function partImpl(b, i, j) { return new DataView(b,i,j); -}; +} -exports.buffer = function buffer (v) { +export function buffer(v) { return v.buffer; -}; +} -exports.byteOffset = function byteOffset (v) { +export function byteOffset(v) { return v.byteOffset; -}; +} -exports.byteLength = function byteLength (v) { +export function byteLength(v) { return v.byteLength; -}; +} -exports.getterImpl = function getterImpl (data, v, o) { +export function getterImpl(data, v, o) { return ((o + data.bytesPerValue) >>> 0) <= v.byteLength ? v[data.functionName].call(v,o,data.littleEndian) : null; -}; +} -exports.setterImpl = function setterImpl (data, v, o, n) { +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 610090e..badab60 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -49,7 +49,7 @@ import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerType, cla import Data.Float32 (Float32) as F import Data.Maybe (Maybe) import Data.Nullable (Nullable, toMaybe) -import Data.Symbol (SProxy(..), class IsSymbol, reflectSymbol) +import Data.Symbol (class IsSymbol, reflectSymbol) import Data.UInt (UInt) import Effect (Effect) import Effect.Uncurried (EffectFn2, EffectFn3, EffectFn4, runEffectFn2, runEffectFn3, runEffectFn4) @@ -131,7 +131,7 @@ get get endian prx = do let le = endian == LE - pnm = "get" <> reflectSymbol (SProxy :: SProxy name) + pnm = "get" <> reflectSymbol (Proxy :: Proxy name) bpv = byteWidth prx getter @@ -203,7 +203,7 @@ set set endian prx = do let le = endian == LE - pnm = "set" <> reflectSymbol (SProxy :: SProxy name) + pnm = "set" <> reflectSymbol (Proxy :: Proxy name) bpv = byteWidth prx setter diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index 2ab0cb6..fc19771 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -1,20 +1,18 @@ -"use strict"; - // module Data.ArrayBuffer.Typed -exports.buffer = function buffer (v) { +export function buffer(v) { return v.buffer; -}; +} -exports.byteOffset = function byteOffset (v) { +export function byteOffset(v) { return v.byteOffset; -}; +} -exports.byteLength = function byteLength (v) { +export function byteLength(v) { return v.byteLength; -}; +} -exports.lengthImpl = function lemgthImpl (v) { +export function lengthImpl(v) { return v.length; }; @@ -36,130 +34,126 @@ function newArray (f) { }; } -exports.newUint8ClampedArray = newArray(Uint8ClampedArray); -exports.newUint32Array = newArray(Uint32Array); -exports.newUint16Array = newArray(Uint16Array); -exports.newUint8Array = newArray(Uint8Array); -exports.newInt32Array = newArray(Int32Array); -exports.newInt16Array = newArray(Int16Array); -exports.newInt8Array = newArray(Int8Array); -exports.newFloat32Array = newArray(Float32Array); -exports.newFloat64Array = newArray(Float64Array); - +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); // ------ -exports.everyImpl = function everyImpl (a,p) { +export function everyImpl(a, p) { return a.every(p); -}; -exports.someImpl = function someImpl (a,p) { - return a.some(p); -}; +} +export function someImpl(a, p) { + return a.some(p); +} -exports.fillImpl = function fillImpl (x, s, e, a) { +export function fillImpl(x, s, e, a) { return a.fill(x,s,e); -}; - +} -exports.mapImpl = function mapImpl (a,f) { +export function mapImpl(a, f) { return a.map(f); -}; +} -exports.forEachImpl = function forEachImpl (a,f) { +export function forEachImpl(a, f) { a.forEach(f); -}; +} -exports.filterImpl = function filterImpl (a,p) { +export function filterImpl(a, p) { return a.filter(p); -}; +} -exports.includesImpl = function includesImpl (a,x,mo) { +export function includesImpl(a, x, mo) { return mo === null ? a.includes(x) : a.includes(x,mo); -}; +} -exports.reduceImpl = function reduceImpl (a,f,i) { +export function reduceImpl(a, f, i) { return a.reduce(f,i); -}; -exports.reduce1Impl = function reduce1Impl (a,f) { +} + +export function reduce1Impl(a, f) { return a.reduce(f); -}; -exports.reduceRightImpl = function reduceRightImpl (a,f,i) { +} + +export function reduceRightImpl(a, f, i) { return a.reduceRight(f,i); -}; -exports.reduceRight1Impl = function reduceRight1Impl (a,f) { +} + +export function reduceRight1Impl(a, f) { return a.reduceRight(f); -}; +} -exports.findImpl = function findImpl (a,f) { +export function findImpl(a, f) { return a.find(f); -}; +} -exports.findIndexImpl = function findIndexImpl (a,f) { +export function findIndexImpl(a, f) { var r = a.findIndex(f); return r === -1 ? null : r; -}; -exports.indexOfImpl = function indexOfImpl (a,x,mo) { +} + +export function indexOfImpl(a, x, mo) { var r = mo === null ? a.indexOf(x) : a.indexOf(x,mo); return r === -1 ? null : r; -}; -exports.lastIndexOfImpl = function lastIndexOfImpl (a,x,mo) { +} + +export function lastIndexOfImpl(a, x, mo) { var r = mo === null ? a.lastIndexOf(x) : a.lastIndexOf(x,mo); return r === -1 ? null : r; -}; - - +} -exports.copyWithinImpl = function copyWithinImpl (a,t,s,me) { +export function copyWithinImpl(a, t, s, me) { if (me === null) { a.copyWithin(t,s); } else { a.copyWithin(t,s,me); } -}; - +} -exports.reverseImpl = function reverseImpl (a) { +export function reverseImpl(a) { a.reverse(); -}; - +} -exports.setImpl = function setImpl (a, off, b) { +export function setImpl(a, off, b) { a.set(b,off); -}; - +} -exports.sliceImpl = function sliceImpl (a, s, e) { +export function sliceImpl(a, s, e) { return a.slice(s,e); -}; +} -exports.sortImpl = function sortImpl (a) { +export function sortImpl(a) { a.sort(); -}; - +} -exports.subArrayImpl = function subArrayImpl (a, s, e) { +export function subArrayImpl(a, s, e) { return a.subarray(s, e); -}; - +} -exports.toStringImpl = function toStringImpl (a) { +export function toStringImpl(a) { return a.toString(); -}; +} -exports.joinImpl = function joinImpl (a,s) { +export function joinImpl(a, s) { return a.join(s); -}; +} -exports.unsafeAtImpl = function(a, i) { +export function unsafeAtImpl(a, i) { return a[i]; } -exports.hasIndexImpl = function(a, i) { +export function hasIndexImpl(a, i) { return i in a; } -exports.toArrayImpl = function(a) { +export function toArrayImpl(a) { var l = a.length; var ret = new Array(l); for (var i = 0; i < l; i++) diff --git a/test/Properties/Typed/Laws.purs b/test/Properties/Typed/Laws.purs index b58f08c..21ac0dd 100644 --- a/test/Properties/Typed/Laws.purs +++ b/test/Properties/Typed/Laws.purs @@ -12,7 +12,7 @@ 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.Prelude (Proxy(..)) +import Type.Proxy (Proxy(..)) import Data.ArrayBuffer.Typed as TA import Data.Generic.Rep (class Generic) import Data.Maybe (Maybe(..)) From 3b5ba3040f060057e864805546a50f319853517d Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Wed, 27 Apr 2022 18:08:50 -0500 Subject: [PATCH 25/34] Prepare v13.0.0 release (1st PS 0.15.0-compatible release) (#44) * Update the bower dependencies * Uncomment spago tests * Update the changelog --- .github/workflows/ci.yml | 4 ++-- CHANGELOG.md | 10 ++++++++++ bower.json | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5d37bc..a9d110d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,8 +39,8 @@ jobs: - name: Build tests run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --strict' -# - name: Run tests -# run: spago -x spago-test.dhall test --no-install + - name: Run tests + run: spago -x spago-test.dhall test --no-install - name: Check formatting run: purs-tidy check src test diff --git a/CHANGELOG.md b/CHANGELOG.md index 982d560..ad44db1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ Notable changes to this project are documented in this file. The format is based ## Unreleased +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [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) diff --git a/bower.json b/bower.json index 85fd87c..74106e6 100644 --- a/bower.json +++ b/bower.json @@ -14,20 +14,20 @@ "output" ], "dependencies": { - "purescript-arraybuffer-types": "main", - "purescript-arrays": "master", - "purescript-effect": "master", - "purescript-float32": "main", - "purescript-functions": "master", - "purescript-gen": "master", - "purescript-maybe": "master", - "purescript-nullable": "main", - "purescript-prelude": "master", - "purescript-tailrec": "master", - "purescript-uint": "main", - "purescript-unfoldable": "master" + "purescript-arraybuffer-types": "^3.0.2", + "purescript-arrays": "^7.0.0", + "purescript-effect": "^4.0.0", + "purescript-float32": "^2.0.0", + "purescript-functions": "^6.0.0", + "purescript-gen": "^4.0.0", + "purescript-maybe": "^6.0.0", + "purescript-nullable": "^6.0.0", + "purescript-prelude": "^6.0.0", + "purescript-tailrec": "^6.0.0", + "purescript-uint": "^7.0.0", + "purescript-unfoldable": "^6.0.0" }, "devDependencies": { - "purescript-quickcheck-laws": "main" + "purescript-quickcheck-laws": "^7.0.0" } } From bae93c3368828195fe8bd44add0e1a665e793eb6 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 17:34:51 +0900 Subject: [PATCH 26/34] New module: Data.ArrayBuffer.Cast (#46) * Upgrade packages.dhall * New module: Data.ArrayBuffer.Cast --- CHANGELOG.md | 2 ++ packages.dhall | 3 +- spago-test.dhall | 1 - src/Data/ArrayBuffer/Cast.purs | 46 ++++++++++++++++++++++++++ src/Data/ArrayBuffer/ValueMapping.purs | 7 ++-- 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/Data/ArrayBuffer/Cast.purs diff --git a/CHANGELOG.md b/CHANGELOG.md index ad44db1..7d83901 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Breaking changes: New features: +- `Data.ArrayBuffer.Cast` (#46 by @jamesdbrock) + Bugfixes: Other improvements: diff --git a/packages.dhall b/packages.dhall index 582d6d3..2ffa9a7 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,4 +1,5 @@ let upstream = - https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall + https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221102/packages.dhall + sha256:8628e413718876ce26983db1d0ce9d9e1588129117fa3bb8ed9f618db6914127 in upstream diff --git a/spago-test.dhall b/spago-test.dhall index ab1a012..7037d90 100644 --- a/spago-test.dhall +++ b/spago-test.dhall @@ -5,7 +5,6 @@ in conf // { , "foldable-traversable" , "partial" , "refs" - , "typelevel-prelude" , "tuples" , "quickcheck" , "quickcheck-laws" 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/ValueMapping.purs b/src/Data/ArrayBuffer/ValueMapping.purs index 70ac4f7..8694a19 100644 --- a/src/Data/ArrayBuffer/ValueMapping.purs +++ b/src/Data/ArrayBuffer/ValueMapping.purs @@ -12,7 +12,8 @@ import Data.Float32 (Float32) as F import Data.UInt (UInt) import Type.Proxy (Proxy) --- | Map of each `ArrayViewType` to the number of bytes of storage it requires. +-- | Type-level map of each `ArrayViewType` to the number of bytes of storage +-- | it requires. class BytesPerType (a :: ArrayViewType) where byteWidth :: (Proxy a) -> Int @@ -43,7 +44,8 @@ instance bytesPerTypeFloat32 :: BytesPerType Float32 where instance bytesPerTypeFloat64 :: BytesPerType Float64 where byteWidth _ = 8 --- | Maps a `TypedArray`’s binary casted value to its computable representation in JavaScript. +-- | 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 @@ -56,6 +58,7 @@ 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" From 42073e2b36742a8f0f10ccfe8237853746501cba Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 17:38:15 +0900 Subject: [PATCH 27/34] Prep for v13.1.0 --- CHANGELOG.md | 8 +++++-- bower.json | 59 +++++++++++++++++++++++++--------------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d83901..7e1187c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,16 @@ Breaking changes: New features: -- `Data.ArrayBuffer.Cast` (#46 by @jamesdbrock) - Bugfixes: Other improvements: +## [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: diff --git a/bower.json b/bower.json index 74106e6..d7d9ae7 100644 --- a/bower.json +++ b/bower.json @@ -1,33 +1,30 @@ { - "name": "purescript-arraybuffer", - "license": [ - "MIT" - ], - "repository": { - "type": "git", - "url": "https://github.com/purescript-contrib/purescript-arraybuffer" - }, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "dependencies": { - "purescript-arraybuffer-types": "^3.0.2", - "purescript-arrays": "^7.0.0", - "purescript-effect": "^4.0.0", - "purescript-float32": "^2.0.0", - "purescript-functions": "^6.0.0", - "purescript-gen": "^4.0.0", - "purescript-maybe": "^6.0.0", - "purescript-nullable": "^6.0.0", - "purescript-prelude": "^6.0.0", - "purescript-tailrec": "^6.0.0", - "purescript-uint": "^7.0.0", - "purescript-unfoldable": "^6.0.0" - }, - "devDependencies": { - "purescript-quickcheck-laws": "^7.0.0" - } + "name": "purescript-arraybuffer", + "license": [ + "MIT" + ], + "repository": { + "type": "git", + "url": "https://github.com/purescript-contrib/purescript-arraybuffer" + }, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-arraybuffer-types": "^v3.0.2", + "purescript-arrays": "^v7.1.0", + "purescript-effect": "^v4.0.0", + "purescript-float32": "^v2.0.0", + "purescript-functions": "^v6.0.0", + "purescript-gen": "^v4.0.0", + "purescript-maybe": "^v6.0.0", + "purescript-nullable": "^v6.0.0", + "purescript-prelude": "^v6.0.1", + "purescript-tailrec": "^v6.1.0", + "purescript-uint": "^v7.0.0", + "purescript-unfoldable": "^v6.0.0" + } } From 374df82368b9b43cae6b71515c0a21de0e0c3592 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 17:48:03 +0900 Subject: [PATCH 28/34] =?UTF-8?q?v13.0.0=20=E2=86=92=20v13.1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 1b5d3fb046e97547c54e9ffe1d7081c7e7457620 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 17:57:45 +0900 Subject: [PATCH 29/34] Remove npx pulp test from CI (#47) --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9d110d..28243e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,3 @@ jobs: npm install bower pulp@16.0.0-0 npx bower install npx pulp build -- --censor-lib --strict - if [ -d "test" ]; then - npx pulp test - fi From 6cc31540ad2bd3ba717f084717e5210938308498 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 18:00:13 +0900 Subject: [PATCH 30/34] =?UTF-8?q?v13.1.0=20=E2=86=92=20v13.1.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From fe2b1d5c7c7be3995dd7e912ddd051e4b1867916 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 18:24:39 +0900 Subject: [PATCH 31/34] README web-encoding instead of text-encoding --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c89142a..ee4c15d 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ These are some other packages which provide more `ArrayBuffer` features. ### UTF -* [__text-encoding__](https://pursuit.purescript.org/packages/purescript-text-encoding) +* [__web-encoding__](https://pursuit.purescript.org/packages/purescript-web-encoding) ### Base64 From 464ddc8917252db0290da8d5851d9179346bd37b Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 13 Feb 2023 15:36:58 +0900 Subject: [PATCH 32/34] Correct `Typed` `slice` and `subArray` docs (#51) --- CHANGELOG.md | 2 ++ src/Data/ArrayBuffer/Typed.purs | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e1187c..6c00e6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ Bugfixes: 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: diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index b8d593b..e46132d 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -23,8 +23,8 @@ -- | - `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 on the same array buffer content as the input --- | - `subArray` returns a new typed array with a separate array buffer +-- | - `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 @@ -211,7 +211,7 @@ 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 buffer and +-- | 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 @@ -415,7 +415,8 @@ foreign import setImpl :: forall a b. EffectFn3 (ArrayView a) Index b Unit 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 buffer, between some start and end indices. +-- | 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 @@ -427,7 +428,8 @@ sort a = runEffectFn1 sortImpl a foreign import sortImpl :: forall a. EffectFn1 (ArrayView a) Unit --- | Returns a new typed array view of the same buffer, beginning at the index and ending at the second. +-- | 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 From e70974bffa51d622441d8ea47cec2b9fc715f3ee Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 13 Feb 2023 15:39:29 +0900 Subject: [PATCH 33/34] Prep for v13.2.0 purs 15.7 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- packages.dhall | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c00e6a..fb92693 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Bugfixes: Other improvements: +## [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 diff --git a/bower.json b/bower.json index d7d9ae7..e0cb70c 100644 --- a/bower.json +++ b/bower.json @@ -15,7 +15,7 @@ ], "dependencies": { "purescript-arraybuffer-types": "^v3.0.2", - "purescript-arrays": "^v7.1.0", + "purescript-arrays": "^v7.2.0", "purescript-effect": "^v4.0.0", "purescript-float32": "^v2.0.0", "purescript-functions": "^v6.0.0", diff --git a/packages.dhall b/packages.dhall index 2ffa9a7..8af7890 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,5 +1,5 @@ let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221102/packages.dhall - sha256:8628e413718876ce26983db1d0ce9d9e1588129117fa3bb8ed9f618db6914127 + https://github.com/purescript/package-sets/releases/download/psc-0.15.7-20230211/packages.dhall + sha256:c44fcd5b1b7a1adf85bbd4ed2eeb08865c44996bd0c8b1e1fdcd3dea8cfab914 in upstream From a1e62aa93360fcc363766024a3c737bb6b75d562 Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 13 Feb 2023 15:50:39 +0900 Subject: [PATCH 34/34] =?UTF-8?q?v13.1.1=20=E2=86=92=20v13.2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit