From 83370eb9f96aa1638f1c532d0d4c10bdad295d1c Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Thu, 17 Jan 2019 15:53:31 -0700 Subject: [PATCH 01/79] pure functions for filtering & querying --- src/Data/ArrayBuffer/Typed.purs | 112 ++++++++++++++++---------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 158134c..9ec54bb 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -39,7 +39,7 @@ import Data.Maybe (Maybe(..)) import Data.Nullable (Nullable, toNullable, toMaybe) import Data.UInt (UInt) import Data.UInt (fromNumber, toNumber) as UInt -import Data.Function.Uncurried (Fn2, Fn3, runFn2, runFn3) +import Data.Function.Uncurried (Fn2, Fn3, runFn2, runFn3, mkFn2) -- | Lightweight polyfill for ie - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill @@ -75,21 +75,21 @@ foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N -- ---- -foreign import everyImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Boolean) Boolean -foreign import someImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Boolean) Boolean +foreign import everyImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean +foreign import someImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean foreign import fillImpl :: forall a b. EffectFn4 (ArrayView a) b (Nullable Offset) (Nullable Offset) Unit foreign import mapImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset b) (ArrayView a) foreign import forEachImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Unit) Unit -foreign import filterImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Boolean) (ArrayView a) +foreign import filterImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) (ArrayView a) foreign import includesImpl :: forall a b. Fn3 (ArrayView a) b (Nullable Offset) Boolean foreign import reduceImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Offset c) c c foreign import reduce1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Offset b) b foreign import reduceRightImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Offset c) c c foreign import reduceRight1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Offset b) b -foreign import findImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Boolean) (Nullable b) -foreign import findIndexImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Boolean) (Nullable Offset) +foreign import findImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) (Nullable b) +foreign import findIndexImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) (Nullable Offset) foreign import indexOfImpl :: forall a b. Fn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) foreign import lastIndexOfImpl :: forall a b. Fn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) @@ -158,11 +158,11 @@ class BinaryValue a t <= TypedArray (a :: ArrayViewType) (t :: Type) | a -> t wh -- | Traverses over each value traverse_ :: (t -> Offset -> Effect Unit) -> ArrayView a -> Effect Unit -- | Test a predicate to pass on all values - all :: (t -> Offset -> Effect Boolean) -> ArrayView a -> Effect Boolean + all :: (t -> Offset -> Boolean) -> ArrayView a -> Boolean -- | Test a predicate to pass on any value - any :: (t -> Offset -> Effect Boolean) -> ArrayView a -> Effect Boolean + any :: (t -> Offset -> Boolean) -> ArrayView a -> Boolean -- | Returns a new typed array with all values that pass the predicate - filter :: (t -> Offset -> Effect Boolean) -> ArrayView a -> Effect (ArrayView a) + filter :: (t -> Offset -> Boolean) -> ArrayView a -> ArrayView a -- | Tests if a value is an element of the typed array elem :: t -> Maybe Offset -> ArrayView a -> Boolean -- | Fetch element at index. @@ -176,9 +176,9 @@ class BinaryValue a t <= TypedArray (a :: ArrayViewType) (t :: Type) | a -> t wh -- | Assumes the typed array is non-empty foldr1M :: (t -> t -> Offset -> Effect t) -> ArrayView a -> Effect t -- | Returns the first value satisfying the predicate - find :: (t -> Offset -> Effect Boolean) -> ArrayView a -> Effect (Maybe t) + find :: (t -> Offset -> Boolean) -> ArrayView a -> Maybe t -- | Returns the first index of the value satisfying the predicate - findIndex :: (t -> Offset -> Effect Boolean) -> ArrayView a -> Effect (Maybe Offset) + findIndex :: (t -> Offset -> Boolean) -> ArrayView a -> Maybe Offset -- | Returns the first index of the element, if it exists, from the left indexOf :: t -> Maybe Offset -> ArrayView a -> Maybe Offset -- | Returns the first index of the element, if it exists, from the right @@ -191,8 +191,8 @@ instance typedArrayUint8Clamped :: TypedArray Uint8Clamped UInt where part a x y = runEffectFn3 newUint8ClampedArray a (toNullable (Just x)) (toNullable (Just y)) empty n = unsafePerformEffect (runEffectFn3 newUint8ClampedArray n (toNullable Nothing) (toNullable Nothing)) fromArray a = unsafePerformEffect (runEffectFn3 newUint8ClampedArray a (toNullable Nothing) (toNullable Nothing)) - all p a = runEffectFn2 everyImpl a (mkEffectFn2 p) - any p a = runEffectFn2 someImpl a (mkEffectFn2 p) + all p a = runFn2 everyImpl a (mkFn2 p) + any p a = runFn2 someImpl a (mkFn2 p) fill a x mz = case mz of Nothing -> runEffectFn4 fillImpl a x (toNullable Nothing) (toNullable Nothing) Just (Tuple s mq) -> case mq of @@ -202,15 +202,15 @@ instance typedArrayUint8Clamped :: TypedArray Uint8Clamped UInt where map f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o)))) traverse f a = runEffectFn2 mapImpl a (mkEffectFn2 f) traverse_ f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) - filter p a = runEffectFn2 filterImpl a (mkEffectFn2 p) + filter p a = runFn2 filterImpl a (mkFn2 p) elem x mo a = runFn3 includesImpl a x (toNullable mo) unsafeAt o a = runEffectFn2 unsafeAtImpl a o foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) - find f a = toMaybe <$> runEffectFn2 findImpl a (mkEffectFn2 f) - findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkEffectFn2 f) + find f a = toMaybe (runFn2 findImpl a (mkFn2 f)) + findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) instance typedArrayUint32 :: TypedArray Uint32 UInt where @@ -219,8 +219,8 @@ instance typedArrayUint32 :: TypedArray Uint32 UInt where part a x y = runEffectFn3 newUint32Array a (toNullable (Just x)) (toNullable (Just y)) empty n = unsafePerformEffect (runEffectFn3 newUint32Array n (toNullable Nothing) (toNullable Nothing)) fromArray a = unsafePerformEffect (runEffectFn3 newUint32Array (UInt.toNumber <$> a) (toNullable Nothing) (toNullable Nothing)) - all p a = runEffectFn2 everyImpl a (mkEffectFn2 (p <<< UInt.fromNumber)) - any p a = runEffectFn2 someImpl a (mkEffectFn2 (p <<< UInt.fromNumber)) + all p a = runFn2 everyImpl a (mkFn2 (p <<< UInt.fromNumber)) + any p a = runFn2 someImpl a (mkFn2 (p <<< UInt.fromNumber)) fill a x mz = case mz of Nothing -> runEffectFn4 fillImpl a (UInt.toNumber x) (toNullable Nothing) (toNullable Nothing) Just (Tuple s mq) -> case mq of @@ -231,15 +231,15 @@ instance typedArrayUint32 :: TypedArray Uint32 UInt where mkEffectFn2 \x o -> pure $ UInt.toNumber $ f (UInt.fromNumber x) o traverse f a = runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> UInt.toNumber <$> f (UInt.fromNumber x) o)) traverse_ f a = runEffectFn2 forEachImpl a (mkEffectFn2 (f <<< UInt.fromNumber)) - filter p a = runEffectFn2 filterImpl a (mkEffectFn2 (p <<< UInt.fromNumber)) + filter p a = runFn2 filterImpl a (mkFn2 (p <<< UInt.fromNumber)) elem x mo a = runFn3 includesImpl a (UInt.toNumber x) (toNullable mo) unsafeAt o a = UInt.fromNumber <$> runEffectFn2 unsafeAtImpl a o foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) - find f a = toMaybe <$> runEffectFn2 findImpl a (mkEffectFn2 f) - findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkEffectFn2 f) + find f a = toMaybe (runFn2 findImpl a (mkFn2 f)) + findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) instance typedArrayUint16 :: TypedArray Uint16 UInt where @@ -248,8 +248,8 @@ instance typedArrayUint16 :: TypedArray Uint16 UInt where part a x y = runEffectFn3 newUint16Array a (toNullable (Just x)) (toNullable (Just y)) empty n = unsafePerformEffect (runEffectFn3 newUint16Array n (toNullable Nothing) (toNullable Nothing)) fromArray a = unsafePerformEffect (runEffectFn3 newUint16Array a (toNullable Nothing) (toNullable Nothing)) - all p a = runEffectFn2 everyImpl a (mkEffectFn2 p) - any p a = runEffectFn2 someImpl a (mkEffectFn2 p) + all p a = runFn2 everyImpl a (mkFn2 p) + any p a = runFn2 someImpl a (mkFn2 p) fill a x mz = case mz of Nothing -> runEffectFn4 fillImpl a x (toNullable Nothing) (toNullable Nothing) Just (Tuple s mq) -> case mq of @@ -259,15 +259,15 @@ instance typedArrayUint16 :: TypedArray Uint16 UInt where map f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o)))) traverse f a = runEffectFn2 mapImpl a (mkEffectFn2 f) traverse_ f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) - filter p a = runEffectFn2 filterImpl a (mkEffectFn2 p) + filter p a = runFn2 filterImpl a (mkFn2 p) elem x mo a = runFn3 includesImpl a x (toNullable mo) unsafeAt o a = runEffectFn2 unsafeAtImpl a o foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) - find f a = toMaybe <$> runEffectFn2 findImpl a (mkEffectFn2 f) - findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkEffectFn2 f) + find f a = toMaybe (runFn2 findImpl a (mkFn2 f)) + findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) instance typedArrayUint8 :: TypedArray Uint8 UInt where @@ -276,8 +276,8 @@ instance typedArrayUint8 :: TypedArray Uint8 UInt where part a x y = runEffectFn3 newUint8Array a (toNullable (Just x)) (toNullable (Just y)) empty n = unsafePerformEffect (runEffectFn3 newUint8Array n (toNullable Nothing) (toNullable Nothing)) fromArray a = unsafePerformEffect (runEffectFn3 newUint8Array a (toNullable Nothing) (toNullable Nothing)) - all p a = runEffectFn2 everyImpl a (mkEffectFn2 p) - any p a = runEffectFn2 someImpl a (mkEffectFn2 p) + all p a = runFn2 everyImpl a (mkFn2 p) + any p a = runFn2 someImpl a (mkFn2 p) fill a x mz = case mz of Nothing -> runEffectFn4 fillImpl a x (toNullable Nothing) (toNullable Nothing) Just (Tuple s mq) -> case mq of @@ -287,15 +287,15 @@ instance typedArrayUint8 :: TypedArray Uint8 UInt where map f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o)))) traverse f a = runEffectFn2 mapImpl a (mkEffectFn2 f) traverse_ f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) - filter p a = runEffectFn2 filterImpl a (mkEffectFn2 p) + filter p a = runFn2 filterImpl a (mkFn2 p) elem x mo a = runFn3 includesImpl a x (toNullable mo) unsafeAt o a = runEffectFn2 unsafeAtImpl a o foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) - find f a = toMaybe <$> runEffectFn2 findImpl a (mkEffectFn2 f) - findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkEffectFn2 f) + find f a = toMaybe (runFn2 findImpl a (mkFn2 f)) + findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) instance typedArrayInt32 :: TypedArray Int32 Int where @@ -304,8 +304,8 @@ instance typedArrayInt32 :: TypedArray Int32 Int where part a x y = runEffectFn3 newInt32Array a (toNullable (Just x)) (toNullable (Just y)) empty n = unsafePerformEffect (runEffectFn3 newInt32Array n (toNullable Nothing) (toNullable Nothing)) fromArray a = unsafePerformEffect (runEffectFn3 newInt32Array a (toNullable Nothing) (toNullable Nothing)) - all p a = runEffectFn2 everyImpl a (mkEffectFn2 p) - any p a = runEffectFn2 someImpl a (mkEffectFn2 p) + all p a = runFn2 everyImpl a (mkFn2 p) + any p a = runFn2 someImpl a (mkFn2 p) fill a x mz = case mz of Nothing -> runEffectFn4 fillImpl a x (toNullable Nothing) (toNullable Nothing) Just (Tuple s mq) -> case mq of @@ -315,15 +315,15 @@ instance typedArrayInt32 :: TypedArray Int32 Int where map f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o)))) traverse f a = runEffectFn2 mapImpl a (mkEffectFn2 f) traverse_ f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) - filter p a = runEffectFn2 filterImpl a (mkEffectFn2 p) + filter p a = runFn2 filterImpl a (mkFn2 p) elem x mo a = runFn3 includesImpl a x (toNullable mo) unsafeAt o a = runEffectFn2 unsafeAtImpl a o foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) - find f a = toMaybe <$> runEffectFn2 findImpl a (mkEffectFn2 f) - findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkEffectFn2 f) + find f a = toMaybe (runFn2 findImpl a (mkFn2 f)) + findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) instance typedArrayInt16 :: TypedArray Int16 Int where @@ -332,8 +332,8 @@ instance typedArrayInt16 :: TypedArray Int16 Int where part a x y = runEffectFn3 newInt16Array a (toNullable (Just x)) (toNullable (Just y)) empty n = unsafePerformEffect (runEffectFn3 newInt16Array n (toNullable Nothing) (toNullable Nothing)) fromArray a = unsafePerformEffect (runEffectFn3 newInt16Array a (toNullable Nothing) (toNullable Nothing)) - all p a = runEffectFn2 everyImpl a (mkEffectFn2 p) - any p a = runEffectFn2 someImpl a (mkEffectFn2 p) + all p a = runFn2 everyImpl a (mkFn2 p) + any p a = runFn2 someImpl a (mkFn2 p) fill a x mz = case mz of Nothing -> runEffectFn4 fillImpl a x (toNullable Nothing) (toNullable Nothing) Just (Tuple s mq) -> case mq of @@ -343,15 +343,15 @@ instance typedArrayInt16 :: TypedArray Int16 Int where map f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o)))) traverse f a = runEffectFn2 mapImpl a (mkEffectFn2 f) traverse_ f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) - filter p a = runEffectFn2 filterImpl a (mkEffectFn2 p) + filter p a = runFn2 filterImpl a (mkFn2 p) elem x mo a = runFn3 includesImpl a x (toNullable mo) unsafeAt o a = runEffectFn2 unsafeAtImpl a o foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) - find f a = toMaybe <$> runEffectFn2 findImpl a (mkEffectFn2 f) - findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkEffectFn2 f) + find f a = toMaybe (runFn2 findImpl a (mkFn2 f)) + findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) instance typedArrayInt8 :: TypedArray Int8 Int where @@ -360,8 +360,8 @@ instance typedArrayInt8 :: TypedArray Int8 Int where part a x y = runEffectFn3 newInt8Array a (toNullable (Just x)) (toNullable (Just y)) empty n = unsafePerformEffect (runEffectFn3 newInt8Array n (toNullable Nothing) (toNullable Nothing)) fromArray a = unsafePerformEffect (runEffectFn3 newInt8Array a (toNullable Nothing) (toNullable Nothing)) - all p a = runEffectFn2 everyImpl a (mkEffectFn2 p) - any p a = runEffectFn2 someImpl a (mkEffectFn2 p) + all p a = runFn2 everyImpl a (mkFn2 p) + any p a = runFn2 someImpl a (mkFn2 p) fill a x mz = case mz of Nothing -> runEffectFn4 fillImpl a x (toNullable Nothing) (toNullable Nothing) Just (Tuple s mq) -> case mq of @@ -371,15 +371,15 @@ instance typedArrayInt8 :: TypedArray Int8 Int where map f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o)))) traverse f a = runEffectFn2 mapImpl a (mkEffectFn2 f) traverse_ f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) - filter p a = runEffectFn2 filterImpl a (mkEffectFn2 p) + filter p a = runFn2 filterImpl a (mkFn2 p) elem x mo a = runFn3 includesImpl a x (toNullable mo) unsafeAt o a = runEffectFn2 unsafeAtImpl a o foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) - find f a = toMaybe <$> runEffectFn2 findImpl a (mkEffectFn2 f) - findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkEffectFn2 f) + find f a = toMaybe (runFn2 findImpl a (mkFn2 f)) + findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) instance typedArrayFloat32 :: TypedArray Float32 Number where @@ -388,8 +388,8 @@ instance typedArrayFloat32 :: TypedArray Float32 Number where part a x y = runEffectFn3 newFloat32Array a (toNullable (Just x)) (toNullable (Just y)) empty n = unsafePerformEffect (runEffectFn3 newFloat32Array n (toNullable Nothing) (toNullable Nothing)) fromArray a = unsafePerformEffect (runEffectFn3 newFloat32Array a (toNullable Nothing) (toNullable Nothing)) - all p a = runEffectFn2 everyImpl a (mkEffectFn2 p) - any p a = runEffectFn2 someImpl a (mkEffectFn2 p) + all p a = runFn2 everyImpl a (mkFn2 p) + any p a = runFn2 someImpl a (mkFn2 p) fill a x mz = case mz of Nothing -> runEffectFn4 fillImpl a x (toNullable Nothing) (toNullable Nothing) Just (Tuple s mq) -> case mq of @@ -399,15 +399,15 @@ instance typedArrayFloat32 :: TypedArray Float32 Number where map f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o)))) traverse f a = runEffectFn2 mapImpl a (mkEffectFn2 f) traverse_ f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) - filter p a = runEffectFn2 filterImpl a (mkEffectFn2 p) + filter p a = runFn2 filterImpl a (mkFn2 p) elem x mo a = runFn3 includesImpl a x (toNullable mo) unsafeAt o a = runEffectFn2 unsafeAtImpl a o foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) - find f a = toMaybe <$> runEffectFn2 findImpl a (mkEffectFn2 f) - findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkEffectFn2 f) + find f a = toMaybe (runFn2 findImpl a (mkFn2 f)) + findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) instance typedArrayFloat64 :: TypedArray Float64 Number where @@ -416,8 +416,8 @@ instance typedArrayFloat64 :: TypedArray Float64 Number where part a x y = runEffectFn3 newFloat64Array a (toNullable (Just x)) (toNullable (Just y)) empty n = unsafePerformEffect (runEffectFn3 newFloat64Array n (toNullable Nothing) (toNullable Nothing)) fromArray a = unsafePerformEffect (runEffectFn3 newFloat64Array a (toNullable Nothing) (toNullable Nothing)) - all p a = runEffectFn2 everyImpl a (mkEffectFn2 p) - any p a = runEffectFn2 someImpl a (mkEffectFn2 p) + all p a = runFn2 everyImpl a (mkFn2 p) + any p a = runFn2 someImpl a (mkFn2 p) fill a x mz = case mz of Nothing -> runEffectFn4 fillImpl a x (toNullable Nothing) (toNullable Nothing) Just (Tuple s mq) -> case mq of @@ -427,15 +427,15 @@ instance typedArrayFloat64 :: TypedArray Float64 Number where map f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o)))) traverse f a = runEffectFn2 mapImpl a (mkEffectFn2 f) traverse_ f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) - filter p a = runEffectFn2 filterImpl a (mkEffectFn2 p) + filter p a = runFn2 filterImpl a (mkFn2 p) elem x mo a = runFn3 includesImpl a x (toNullable mo) unsafeAt o a = runEffectFn2 unsafeAtImpl a o foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) - find f a = toMaybe <$> runEffectFn2 findImpl a (mkEffectFn2 f) - findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkEffectFn2 f) + find f a = toMaybe (runFn2 findImpl a (mkFn2 f)) + findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) From fa85219ee19cbb502add34bf8bea35e353a0eaca Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Sat, 19 Jan 2019 06:24:42 -0700 Subject: [PATCH 02/79] using external float32 library --- bower.json | 3 ++- src/Data/ArrayBuffer/DataView.purs | 3 ++- src/Data/ArrayBuffer/Typed.purs | 3 ++- src/Data/ArrayBuffer/Typed/Gen.js | 9 --------- src/Data/ArrayBuffer/Typed/Gen.purs | 7 +++---- src/Data/ArrayBuffer/ValueMapping.purs | 3 ++- test/Properties/DataView.purs | 3 ++- 7 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 src/Data/ArrayBuffer/Typed/Gen.js diff --git a/bower.json b/bower.json index 2e030e6..c47dff8 100644 --- a/bower.json +++ b/bower.json @@ -20,7 +20,8 @@ "purescript-typelevel": "^4.0.0", "purescript-parseint": "^1.1.0", "purescript-uint": "^5.1.0", - "purescript-sized-vectors": "^3.1.0" + "purescript-sized-vectors": "^3.1.0", + "purescript-float32": "^0.0.1" }, "devDependencies": { "purescript-debug": "^4.0.0", diff --git a/src/Data/ArrayBuffer/DataView.purs b/src/Data/ArrayBuffer/DataView.purs index a568f40..09e2bc2 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -18,6 +18,7 @@ import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerValue) import Data.Maybe (Maybe(..)) import Data.Typelevel.Num (toInt', class Nat) import Data.UInt (UInt) +import Data.Float32 (Float32) as F import Effect (Effect) import Effect.Uncurried (EffectFn2, EffectFn3, EffectFn4, runEffectFn2, runEffectFn3, runEffectFn4) import Type.Proxy (Proxy(..)) @@ -133,7 +134,7 @@ instance dataViewUint32 :: (BytesPerValue Uint32 b, Nat b) => DataView Uint32 UI getLE AProxy = getter {functionName: "getUint32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} setLE AProxy = setter {functionName: "setUint32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} -instance dataViewFloat32 :: (BytesPerValue Float32 b, Nat b) => DataView Float32 Number where +instance dataViewFloat32 :: (BytesPerValue Float32 b, Nat b) => DataView Float32 F.Float32 where getBE AProxy = getter {functionName: "getFloat32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} setBE AProxy = setter {functionName: "setFloat32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} getLE AProxy = getter {functionName: "getFloat32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 46a0dd8..2b0880e 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -27,6 +27,7 @@ import Data.Maybe (Maybe(..)) import Data.Nullable (Nullable, notNull, null, toMaybe, toNullable) import Data.Tuple (Tuple(..)) import Data.UInt (UInt) +import Data.Float32 (Float32) as F import Effect (Effect) import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4, mkEffectFn2, mkEffectFn3, runEffectFn1, runEffectFn2, runEffectFn3, runEffectFn4) import Effect.Unsafe (unsafePerformEffect) @@ -143,7 +144,7 @@ instance typedArrayInt16 :: TypedArray Int16 Int where create = newInt16Array instance typedArrayInt8 :: TypedArray Int8 Int where create = newInt8Array -instance typedArrayFloat32 :: TypedArray Float32 Number where +instance typedArrayFloat32 :: TypedArray Float32 F.Float32 where create = newFloat32Array instance typedArrayFloat64 :: TypedArray Float64 Number where create = newFloat64Array diff --git a/src/Data/ArrayBuffer/Typed/Gen.js b/src/Data/ArrayBuffer/Typed/Gen.js deleted file mode 100644 index a592186..0000000 --- a/src/Data/ArrayBuffer/Typed/Gen.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; - -// module Data.ArrayBuffer.Typed.Gen - -exports.toFloat32 = function toFloat32(s) { - var r = new Float32Array(1); - r[0] = s; - return r[0]; -} diff --git a/src/Data/ArrayBuffer/Typed/Gen.purs b/src/Data/ArrayBuffer/Typed/Gen.purs index 2aa2474..47a419e 100644 --- a/src/Data/ArrayBuffer/Typed/Gen.purs +++ b/src/Data/ArrayBuffer/Typed/Gen.purs @@ -13,6 +13,7 @@ import Data.Maybe (Maybe(..), fromMaybe) import Data.Typelevel.Num (class Nat, toInt') import Data.UInt (UInt) import Data.UInt (fromInt) as UInt +import Data.Float32 (Float32, fromNumber) as F import Data.UInt.Gen (genUInt) as UInt import Data.Unfoldable (replicateA) import Data.Vec (Vec) @@ -52,10 +53,8 @@ genUint32 = UInt.genUInt bottom top genInt32 :: forall m. MonadGen m => m Int genInt32 = chooseInt bottom top -foreign import toFloat32 :: Number -> Number - -genFloat32 :: forall m. MonadGen m => m Number -genFloat32 = toFloat32 <$> chooseFloat (-3.40282347e+38) 3.40282347e+38 +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) 1.7976931348623157e+308 diff --git a/src/Data/ArrayBuffer/ValueMapping.purs b/src/Data/ArrayBuffer/ValueMapping.purs index 0ed8fb9..c17d677 100644 --- a/src/Data/ArrayBuffer/ValueMapping.purs +++ b/src/Data/ArrayBuffer/ValueMapping.purs @@ -6,6 +6,7 @@ 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) +import Data.Float32 (Float32) as F -- | Maps a `TypedArray`'s binary casted value, to the space occupied by that value, in bytes. @@ -32,5 +33,5 @@ instance binaryValueUint8 :: BinaryValue Uint8 UInt instance binaryValueInt32 :: BinaryValue Int32 Int instance binaryValueInt16 :: BinaryValue Int16 Int instance binaryValueInt8 :: BinaryValue Int8 Int -instance binaryValueFloat32 :: BinaryValue Float32 Number +instance binaryValueFloat32 :: BinaryValue Float32 F.Float32 instance binaryValueFloat64 :: BinaryValue Float64 Number diff --git a/test/Properties/DataView.purs b/test/Properties/DataView.purs index 7ce16f8..5cbca65 100644 --- a/test/Properties/DataView.purs +++ b/test/Properties/DataView.purs @@ -11,6 +11,7 @@ import Data.ArrayBuffer.ValueMapping (class BytesPerValue) import Data.Maybe (Maybe(..)) import Data.Typelevel.Num (class Nat, D1, D2, D4, D8) import Data.UInt (UInt) +import Data.Float32 (Float32) as F import Data.Vec (head) as Vec import Effect (Effect) import Effect.Console (log) @@ -82,7 +83,7 @@ overAll count f = do log " - Float32" quickCheckGen $ - let f' :: TestableViewF Float32 D4 n Number q + let f' :: TestableViewF Float32 D4 n F.Float32 q f' = f in f' <$> genWithOffsetAndValue (genDataView 20 Nothing) genFloat32 From 23c5135bea8c4e643134eb75f9a544c431b9e4c6 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Fri, 25 Jan 2019 21:27:01 +0100 Subject: [PATCH 03/79] Make empty effectful --- src/Data/ArrayBuffer/ArrayBuffer.js | 2 +- src/Data/ArrayBuffer/ArrayBuffer.purs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Data/ArrayBuffer/ArrayBuffer.js b/src/Data/ArrayBuffer/ArrayBuffer.js index 0952ca2..656d576 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.js +++ b/src/Data/ArrayBuffer/ArrayBuffer.js @@ -2,7 +2,7 @@ // module Data.ArrayBuffer.ArrayBuffer -exports.empty = function empty (s) { +exports.emptyImpl = function empty (s) { return new ArrayBuffer(s); }; diff --git a/src/Data/ArrayBuffer/ArrayBuffer.purs b/src/Data/ArrayBuffer/ArrayBuffer.purs index fe8a920..4bd11a0 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.purs +++ b/src/Data/ArrayBuffer/ArrayBuffer.purs @@ -12,10 +12,16 @@ import Data.Function.Uncurried (Fn3, runFn3) import Data.Maybe (Maybe(..)) import Data.Nullable (Nullable, notNull, null) import Data.Tuple (Tuple(..)) +import Effect (Effect) +import Effect.Uncurried (EffectFn1, runEffectFn1) + + +foreign import emptyImpl :: EffectFn1 ByteLength ArrayBuffer -- | Create an `ArrayBuffer` with the given capacity. -foreign import empty :: ByteLength -> ArrayBuffer +empty :: ByteLength -> Effect ArrayBuffer +empty l = runEffectFn1 emptyImpl l -- | Represents the length of an `ArrayBuffer` in bytes. foreign import byteLength :: ArrayBuffer -> ByteLength From 86fd6e84c1324089a46a18fc2245d3f492e64845 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Fri, 25 Jan 2019 21:28:16 +0100 Subject: [PATCH 04/79] Restore specific setters/getters in the API, changed implementation --- src/Data/ArrayBuffer/DataView.js | 2 +- src/Data/ArrayBuffer/DataView.purs | 319 ++++++++++++++++++++++------- test/Properties/DataView.purs | 27 +-- 3 files changed, 254 insertions(+), 94 deletions(-) diff --git a/src/Data/ArrayBuffer/DataView.js b/src/Data/ArrayBuffer/DataView.js index d51835c..44ad1b9 100644 --- a/src/Data/ArrayBuffer/DataView.js +++ b/src/Data/ArrayBuffer/DataView.js @@ -33,7 +33,7 @@ exports.getterImpl = function getterImpl (data, v, o) { : data.nothing; }; -exports.setterImpl = function setterImpl (data,v,n,o) { +exports.setterImpl = function setterImpl (data, v, o, n) { if (((o + data.bytesPerValue) >>> 0) <= v.byteLength) { v[data.functionName].call(v,o,n,data.littleEndian); return true; diff --git a/src/Data/ArrayBuffer/DataView.purs b/src/Data/ArrayBuffer/DataView.purs index 966b13a..0c0e235 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -2,18 +2,56 @@ -- | objects. See [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) for details. module Data.ArrayBuffer.DataView - ( whole - , remainder - , part - , buffer - , byteOffset - , byteLength - , AProxy (..) - , class DataView - , getBE, getLE, setBE, setLE - ) where - -import Data.ArrayBuffer.Types (ByteOffset, DataView, ByteLength, ArrayBuffer, kind ArrayViewType, Int32, Int16, Int8, Uint32, Uint16, Uint8, Float32, Float64) + ( AProxy (..) + , Endian (..) + , buffer + , byteLength + , byteOffset + , class DataView + , class ViewTypeName + , get + , getBE + , getFloat32be + , getFloat32le + , getFloat64be + , getFloat64le + , getInt16be + , getInt16le + , getInt32be + , getInt32le + , getInt8 + , getLE + , getUint16be + , getUint16le + , getUint32be + , getUint32le + , getUint8 + , nm + , part + , remainder + , set + , setBE + , setFloat32be + , setFloat32le + , setFloat64be + , setFloat64le + , setInt16be + , setInt16le + , setInt32be + , setInt32le + , setInt8 + , setLE + , setUint16be + , setUint16le + , setUint32be + , setUint32le + , setUint8 + , whole + ) where + +import Prelude + +import Data.ArrayBuffer.Types (ArrayBuffer, ByteLength, ByteOffset, DataView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, Uint8Clamped, kind ArrayViewType) import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerValue) import Data.Maybe (Maybe(..)) import Data.Typelevel.Num (toInt', class Nat) @@ -24,7 +62,6 @@ import Type.Proxy (Proxy(..)) - -- | View mapping the whole `ArrayBuffer`. foreign import whole :: ArrayBuffer -> DataView @@ -52,13 +89,47 @@ 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 + +class (BinaryValue a t, ViewTypeName a) <= DataView (a :: ArrayViewType) t | a -> t + +instance dataViewUint8Clamped :: DataView Uint8Clamped UInt +instance dataViewUint32 :: DataView Uint32 UInt +instance dataViewUint16 :: DataView Uint16 UInt +instance dataViewUint8 :: DataView Uint8 UInt +instance dataViewInt32 :: DataView Int32 Int +instance dataViewInt16 :: DataView Int16 Int +instance dataViewInt8 :: DataView Int8 Int +instance dataViewFloat32 :: DataView Float32 Number +instance dataViewFloat64 :: DataView Float64 Number -class BinaryValue a t <= DataView (a :: ArrayViewType) t | a -> t where - getLE :: AProxy a -> DataView -> ByteOffset -> Effect (Maybe t) - getBE :: AProxy a -> DataView -> ByteOffset -> Effect (Maybe t) - setBE :: AProxy a -> DataView -> t -> ByteOffset -> Effect Boolean - setLE :: AProxy a -> DataView -> t -> ByteOffset -> Effect Boolean +class ViewTypeName vty where + nm :: AProxy vty -> String + +instance viewTypeNameUint8Clamped :: ViewTypeName Uint8Clamped where + nm _ = "Uint8Clamped" +instance viewTypeNameViewUint32 :: ViewTypeName Uint32 where + nm _ = "Uint32" +instance viewTypeNameViewUint16 :: ViewTypeName Uint16 where + nm _ = "Uint16" +instance viewTypeNameViewUint8 :: ViewTypeName Uint8 where + nm _ = "Uint8" +instance viewTypeNameViewInt32 :: ViewTypeName Int32 where + nm _ = "Int32" +instance viewTypeNameViewInt16 :: ViewTypeName Int16 where + nm _ = "Int16" +instance viewTypeNameViewInt8 :: ViewTypeName Int8 where + nm _ = "Int8" +instance viewTypeNameViewFloat32 :: ViewTypeName Float32 where + nm _ = "Float32" +instance viewTypeNameViewFloat64 :: ViewTypeName Float64 where + nm _ = "Float64" foreign import getterImpl :: forall t . EffectFn3 { just :: t -> Maybe t @@ -68,8 +139,8 @@ foreign import getterImpl :: forall t , bytesPerValue :: ByteLength } DataView ByteOffset (Maybe t) -getter :: forall t - . { functionName :: String +getter :: forall t. + { functionName :: String , bytesPerValue :: ByteLength , littleEndian :: Boolean } @@ -83,64 +154,164 @@ getter data' d o = , bytesPerValue: data'.bytesPerValue } d o + +get :: forall a t b. DataView a t => BytesPerValue a b => Nat b => Endian -> AProxy a -> DataView -> ByteOffset -> Effect (Maybe t) +get endian prx = + let le = endian == LE + pnm = "get" <> nm prx + bpv = toInt' (Proxy :: Proxy b) + in getter { functionName: pnm + , bytesPerValue: bpv + , littleEndian: le + } + +getBE :: forall a t b. DataView a t => BytesPerValue a b => Nat b => AProxy a -> DataView -> ByteOffset -> Effect (Maybe t) +getBE = get BE + +getLE :: forall a t b. DataView a t => BytesPerValue a b => Nat b => AProxy a -> DataView -> ByteOffset -> Effect (Maybe t) +getLE = get LE + foreign import setterImpl :: forall t . EffectFn4 { functionName :: String , littleEndian :: Boolean , bytesPerValue :: ByteLength - } DataView t ByteOffset Boolean + } DataView ByteOffset t Boolean -setter :: forall t - . { functionName :: String +setter :: forall t. + { functionName :: String , bytesPerValue :: ByteLength , littleEndian :: Boolean - } -> DataView -> t -> ByteOffset -> Effect Boolean -setter d t o = runEffectFn4 setterImpl d t o - - -instance dataViewInt8 :: (BytesPerValue Int8 b, Nat b) => DataView Int8 Int where - getBE AProxy = getter {functionName: "getInt8", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - setBE AProxy = setter {functionName: "setInt8", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - getLE AProxy = getter {functionName: "getInt8", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - setLE AProxy = setter {functionName: "setInt8", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - -instance dataViewInt16 :: (BytesPerValue Int16 b, Nat b) => DataView Int16 Int where - getBE AProxy = getter {functionName: "getInt16", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - setBE AProxy = setter {functionName: "setInt16", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - getLE AProxy = getter {functionName: "getInt16", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - setLE AProxy = setter {functionName: "setInt16", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - -instance dataViewInt32 :: (BytesPerValue Int32 b, Nat b) => DataView Int32 Int where - getBE AProxy = getter {functionName: "getInt32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - setBE AProxy = setter {functionName: "setInt32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - getLE AProxy = getter {functionName: "getInt32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - setLE AProxy = setter {functionName: "setInt32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - -instance dataViewUint8 :: (BytesPerValue Uint8 b, Nat b) => DataView Uint8 UInt where - getBE AProxy = getter {functionName: "getUint8", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - setBE AProxy = setter {functionName: "setUint8", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - getLE AProxy = getter {functionName: "getUint8", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - setLE AProxy = setter {functionName: "setUint8", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - -instance dataViewUint16 :: (BytesPerValue Uint16 b, Nat b) => DataView Uint16 UInt where - getBE AProxy = getter {functionName: "getUint16", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - setBE AProxy = setter {functionName: "setUint16", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - getLE AProxy = getter {functionName: "getUint16", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - setLE AProxy = setter {functionName: "setUint16", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - -instance dataViewUint32 :: (BytesPerValue Uint32 b, Nat b) => DataView Uint32 UInt where - getBE AProxy = getter {functionName: "getUint32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - setBE AProxy = setter {functionName: "setUint32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - getLE AProxy = getter {functionName: "getUint32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - setLE AProxy = setter {functionName: "setUint32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - -instance dataViewFloat32 :: (BytesPerValue Float32 b, Nat b) => DataView Float32 Number where - getBE AProxy = getter {functionName: "getFloat32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - setBE AProxy = setter {functionName: "setFloat32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - getLE AProxy = getter {functionName: "getFloat32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - setLE AProxy = setter {functionName: "setFloat32", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - -instance dataViewFloat64 :: (BytesPerValue Float64 b, Nat b) => DataView Float64 Number where - getBE AProxy = getter {functionName: "getFloat64", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - setBE AProxy = setter {functionName: "setFloat64", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: false} - getLE AProxy = getter {functionName: "getFloat64", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} - setLE AProxy = setter {functionName: "setFloat64", bytesPerValue: toInt' (Proxy :: Proxy b), littleEndian: true} + } -> DataView -> ByteOffset -> t -> Effect Boolean +setter d o t = runEffectFn4 setterImpl d o t + +set :: forall a t b. DataView a t => BytesPerValue a b => Nat b => Endian -> AProxy a -> DataView -> ByteOffset -> t -> Effect Boolean +set endian prx = + let le = endian == LE + pnm = "set" <> nm prx + bpv = toInt' (Proxy :: Proxy b) + in setter { functionName: pnm + , bytesPerValue: bpv + , littleEndian: le + } + +-- | Fetch int8 value at a certain index in a `DataView`. +getInt8 :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt8 = getLE (AProxy :: AProxy Int8) + +-- | Fetch big-endian int16 value at a certain index in a `DataView`. +getInt16be :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt16be = getBE (AProxy :: AProxy Int16) + +-- | Fetch little-endian int16 value at a certain index in a `DataView`. +getInt16le :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt16le = getLE (AProxy :: AProxy Int16) + +-- | Fetch big-endian int32 value at a certain index in a `DataView`. +getInt32be :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt32be = getBE (AProxy :: AProxy Int32) + +-- | Fetch little-endian int32 value at a certain index in a `DataView`. +getInt32le :: DataView -> ByteOffset -> Effect (Maybe Int) +getInt32le = getLE (AProxy :: AProxy Int32) + +-- | Fetch uint8 value at a certain index in a `DataView`. +getUint8 :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint8 = getLE (AProxy :: AProxy Uint8) + +-- | Fetch big-endian uint16 value at a certain index in a `DataView`. +getUint16be :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint16be = getBE (AProxy :: AProxy Uint16) + +-- | Fetch little-endian uint16 value at a certain index in a `DataView`. +getUint16le :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint16le = getLE (AProxy :: AProxy Uint16) + +-- | Fetch big-endian uint32 value at a certain index in a `DataView`. +getUint32be :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint32be = getBE (AProxy :: AProxy Uint32) + +-- | Fetch little-endian uint32 value at a certain index in a `DataView`. +getUint32le :: DataView -> ByteOffset -> Effect (Maybe UInt) +getUint32le = getLE (AProxy :: AProxy Uint32) + +-- | Fetch big-endian float32 value at a certain index in a `DataView`. +getFloat32be :: DataView -> ByteOffset -> Effect (Maybe Number) +getFloat32be = getBE (AProxy :: AProxy Float32) + +-- | Fetch little-endian float32 value at a certain index in a `DataView`. +getFloat32le :: DataView -> ByteOffset -> Effect (Maybe Number) +getFloat32le = getLE (AProxy :: AProxy Float32) + +-- | Fetch big-endian float64 value at a certain index in a `DataView`. +getFloat64be :: DataView -> ByteOffset -> Effect (Maybe Number) +getFloat64be = getBE (AProxy :: AProxy Float64) + +-- | Fetch little-endian float64 value at a certain index in a `DataView`. +getFloat64le :: DataView -> ByteOffset -> Effect (Maybe Number) +getFloat64le = getLE (AProxy :: AProxy Float64) + + +-- | Store big-endian value at a certain index in a `DataView`. +setBE :: forall a t b. DataView a t => BytesPerValue a b => Nat b => AProxy a -> DataView -> ByteOffset -> t -> Effect Boolean +setBE = set BE + +-- | Store little-endian value at a certain index in a `DataView`. +setLE :: forall a t b. DataView a t => BytesPerValue a b => Nat b => AProxy 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) + +-- | Store big-endian int16 value at a certain index in a `DataView`. +setInt16be :: DataView -> ByteOffset -> Int -> Effect Boolean +setInt16be = setBE (AProxy :: AProxy Int16) + +-- | Store little-endian int16 value at a certain index in a `DataView`. +setInt16le :: DataView -> ByteOffset -> Int -> Effect Boolean +setInt16le = setLE (AProxy :: AProxy Int16) + +-- | Store big-endian int32 value at a certain index in a `DataView`. +setInt32be :: DataView -> ByteOffset -> Int -> Effect Boolean +setInt32be = setBE (AProxy :: AProxy Int32) + +-- | Store little-endian int32 value at a certain index in a `DataView`. +setInt32le :: DataView -> ByteOffset -> Int -> Effect Boolean +setInt32le = setLE (AProxy :: AProxy Int32) + +-- | Store uint8 value at a certain index in a `DataView`. +setUint8 :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint8 = setLE (AProxy :: AProxy Uint8) + + +-- | Store big-endian uint16 value at a certain index in a `DataView`. +setUint16be :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint16be = setBE (AProxy :: AProxy Uint16) + +-- | Store little-endian uint16 value at a certain index in a `DataView`. +setUint16le :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint16le = setLE (AProxy :: AProxy Uint16) + +-- | Store big-endian uint32 value at a certain index in a `DataView`. +setUint32be :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint32be = setBE (AProxy :: AProxy Uint32) + +-- | Store little-endian uint32 value at a certain index in a `DataView`. +setUint32le :: DataView -> ByteOffset -> UInt -> Effect Boolean +setUint32le = setLE (AProxy :: AProxy Uint32) + +-- | Store big-endian float32 value at a certain index in a `DataView`. +setFloat32be :: DataView -> ByteOffset -> Number -> Effect Boolean +setFloat32be = setBE (AProxy :: AProxy Float32) + +-- | Store little-endian float32 value at a certain index in a `DataView`. +setFloat32le :: DataView -> ByteOffset -> Number -> Effect Boolean +setFloat32le = setLE (AProxy :: AProxy Float32) + +-- | Store big-endian float64 value at a certain index in a `DataView`. +setFloat64be :: DataView -> ByteOffset -> Number -> Effect Boolean +setFloat64be = setBE (AProxy :: AProxy Float64) + +-- | Store little-endian float64 value at a certain index in a `DataView`. +setFloat64le :: DataView -> ByteOffset -> Number -> Effect Boolean +setFloat64le = setLE (AProxy :: AProxy Float64) diff --git a/test/Properties/DataView.purs b/test/Properties/DataView.purs index d399e1b..0664453 100644 --- a/test/Properties/DataView.purs +++ b/test/Properties/DataView.purs @@ -6,7 +6,7 @@ import Prelude 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 (Uint32, Uint16, Uint8, Int32, Int16, Int8, Float32, Float64) +import Data.ArrayBuffer.Types (Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8) import Data.ArrayBuffer.ValueMapping (class BytesPerValue) import Data.Maybe (Maybe(..)) import Data.Typelevel.Num (class Nat, D1, D2, D4, D8) @@ -24,9 +24,9 @@ import Test.QuickCheck (class Testable, quickCheckGen, Result, (===)) dataViewTests :: Ref Int -> Effect Unit dataViewTests count = do log " - setBE x o => getBE o === Just x" - placingAValueIsThereTestsBE count + placingAValueIsThereTests DV.BE count log " - setLE x o => getLE o === Just x" - placingAValueIsThereTestsLE count + placingAValueIsThereTests DV.LE count type TestableViewF a b n t q = @@ -93,25 +93,14 @@ overAll count f = do in f' <$> genWithOffsetAndValue genDataView genFloat64 -placingAValueIsThereTestsBE :: Ref Int -> Effect Unit -placingAValueIsThereTestsBE count = overAll count placingAValueIsThere +placingAValueIsThereTests :: DV.Endian -> Ref Int -> Effect Unit +placingAValueIsThereTests endian count = overAll count placingAValueIsThere where placingAValueIsThere :: forall a b t. TestableViewF a b D1 t Result placingAValueIsThere (WithOffsetAndValue os t xs) = let o = Vec.head os + prx = DV.AProxy :: DV.AProxy a in unsafePerformEffect do - _ <- DV.setBE (DV.AProxy :: DV.AProxy a) xs t o - my <- DV.getBE (DV.AProxy :: DV.AProxy a) xs o - pure (my === Just t) - - -placingAValueIsThereTestsLE :: Ref Int -> Effect Unit -placingAValueIsThereTestsLE count = overAll count placingAValueIsThere - where - placingAValueIsThere :: forall a b t. TestableViewF a b D1 t Result - placingAValueIsThere (WithOffsetAndValue os t xs) = - let o = Vec.head os - in unsafePerformEffect do - _ <- DV.setLE (DV.AProxy :: DV.AProxy a) xs t o - my <- DV.getLE (DV.AProxy :: DV.AProxy a) xs o + _ <- DV.set endian prx xs o t + my <- DV.get endian prx xs o pure (my === Just t) From 0fa0d7a21d591d4dd25eb7a41195caccf0098300 Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Fri, 25 Jan 2019 14:19:07 -0700 Subject: [PATCH 05/79] fixing tests --- test/Properties/DataView.purs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/Properties/DataView.purs b/test/Properties/DataView.purs index 9758f8c..3a13210 100644 --- a/test/Properties/DataView.purs +++ b/test/Properties/DataView.purs @@ -13,6 +13,7 @@ import Data.Typelevel.Num (class Nat, D1, D2, D4, D8) import Data.UInt (UInt) import Data.Float32 (Float32) as F import Data.Vec (head) as Vec +import Data.Symbol (class IsSymbol) import Effect (Effect) import Effect.Console (log) import Effect.Ref (Ref) @@ -30,66 +31,68 @@ dataViewTests count = do placingAValueIsThereTests DV.LE count -type TestableViewF a b n t q = +type TestableViewF a name b n t q = Show t => Eq t => Ord t => Semiring t => BytesPerValue a b + => DV.ShowArrayViewType a name + => IsSymbol name => Nat b => DV.DataView a t => WithOffsetAndValue n a t -> q -overAll :: forall q n. Testable q => Nat n => Ref Int -> (forall a b t. TestableViewF a b n t q) -> Effect Unit +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 count f = do void (Ref.modify (\x -> x + 1) count) log " - Uint32" quickCheckGen $ - let f' :: TestableViewF Uint32 D4 n UInt q + let f' :: TestableViewF Uint32 "Uint32" D4 n UInt q f' = f in f' <$> genWithOffsetAndValue genDataView genUint32 log " - Uint16" quickCheckGen $ - let f' :: TestableViewF Uint16 D2 n UInt q + let f' :: TestableViewF Uint16 "Uint16" D2 n UInt q f' = f in f' <$> genWithOffsetAndValue genDataView genUint16 log " - Uint8" quickCheckGen $ - let f' :: TestableViewF Uint8 D1 n UInt q + let f' :: TestableViewF Uint8 "Uint8" D1 n UInt q f' = f in f' <$> genWithOffsetAndValue genDataView genUint8 log " - Int32" quickCheckGen $ - let f' :: TestableViewF Int32 D4 n Int q + let f' :: TestableViewF Int32 "Int32" D4 n Int q f' = f in f' <$> genWithOffsetAndValue genDataView genInt32 log " - Int16" quickCheckGen $ - let f' :: TestableViewF Int16 D2 n Int q + let f' :: TestableViewF Int16 "Int16" D2 n Int q f' = f in f' <$> genWithOffsetAndValue genDataView genInt16 log " - Int8" quickCheckGen $ - let f' :: TestableViewF Int8 D1 n Int q + let f' :: TestableViewF Int8 "Int8" D1 n Int q f' = f in f' <$> genWithOffsetAndValue genDataView genInt8 log " - Float32" quickCheckGen $ - let f' :: TestableViewF Float32 D4 n F.Float32 q + let f' :: TestableViewF Float32 "Float32" D4 n F.Float32 q f' = f in f' <$> genWithOffsetAndValue genDataView genFloat32 log " - Float64" quickCheckGen $ - let f' :: TestableViewF Float64 D8 n Number q + let f' :: TestableViewF Float64 "Float64" D8 n Number q f' = f in f' <$> genWithOffsetAndValue genDataView genFloat64 @@ -97,7 +100,7 @@ overAll count f = do placingAValueIsThereTests :: DV.Endian -> Ref Int -> Effect Unit placingAValueIsThereTests endian count = overAll count placingAValueIsThere where - placingAValueIsThere :: forall a b t. TestableViewF a b D1 t Result + placingAValueIsThere :: forall a name b t. TestableViewF a name b D1 t Result placingAValueIsThere (WithOffsetAndValue os t xs) = let o = Vec.head os prx = DV.AProxy :: DV.AProxy a From 45f310a8b32874f280023ab904c07e6db08ad1cd Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Fri, 25 Jan 2019 14:24:41 -0700 Subject: [PATCH 06/79] restricted imports --- src/Data/ArrayBuffer/DataView/Gen.purs | 2 +- src/Data/ArrayBuffer/Typed.purs | 2 +- src/Data/ArrayBuffer/Typed/Gen.purs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Data/ArrayBuffer/DataView/Gen.purs b/src/Data/ArrayBuffer/DataView/Gen.purs index 46ba9ed..3423d5f 100644 --- a/src/Data/ArrayBuffer/DataView/Gen.purs +++ b/src/Data/ArrayBuffer/DataView/Gen.purs @@ -1,6 +1,6 @@ module Data.ArrayBuffer.DataView.Gen where -import Prelude +import Prelude ((<$>), bind, ($), (<=), (-), pure) import Control.Monad.Gen (suchThat) import Control.Monad.Gen.Class (class MonadGen, chooseInt) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 226d452..c7e04f3 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -21,7 +21,7 @@ module Data.ArrayBuffer.Typed , toString, toString', toArray ) where -import Prelude +import Prelude (Unit, (>=), (&&), (<<<), (<=), pure, (-), flip, (*), (*>)) 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) diff --git a/src/Data/ArrayBuffer/Typed/Gen.purs b/src/Data/ArrayBuffer/Typed/Gen.purs index 82daa80..ffe3dd8 100644 --- a/src/Data/ArrayBuffer/Typed/Gen.purs +++ b/src/Data/ArrayBuffer/Typed/Gen.purs @@ -2,7 +2,7 @@ module Data.ArrayBuffer.Typed.Gen where -import Prelude +import Prelude ((<$>), bind, (/), (-), negate, ($), bottom, pure, top) import Control.Monad.Gen.Class (class MonadGen, sized, chooseInt, chooseFloat) import Data.ArrayBuffer.Typed (class TypedArray) @@ -30,7 +30,7 @@ genTypedArray :: forall m a t genTypedArray gen = sized \s -> do n <- chooseInt 0 s a <- replicateA n gen - pure $ TA.fromArray a + pure (TA.fromArray a) genUint8 :: forall m. MonadGen m => m UInt genUint8 = UInt.fromInt <$> chooseInt 0 255 From 167edadeea52600d3638aac6d8483f926bde0c63 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sun, 27 Jan 2019 22:46:48 +0100 Subject: [PATCH 07/79] Changing some functions to be effectful --- src/Data/ArrayBuffer/Typed.purs | 55 ++-- src/Data/ArrayBuffer/Typed/Gen.purs | 8 +- test/Properties/TypedArray.purs | 390 ++++++++++++++-------------- 3 files changed, 222 insertions(+), 231 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index c7e04f3..0a376e6 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -21,22 +21,21 @@ module Data.ArrayBuffer.Typed , toString, toString', toArray ) where -import Prelude (Unit, (>=), (&&), (<<<), (<=), pure, (-), flip, (*), (*>)) - 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.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.Tuple (Tuple(..)) import Data.Typelevel.Num (class Nat, toInt') import Data.UInt (UInt) -import Data.Float32 (Float32) as F import Effect (Effect) import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4, mkEffectFn2, mkEffectFn3, runEffectFn1, runEffectFn2, runEffectFn3, runEffectFn4) import Effect.Unsafe (unsafePerformEffect) import Partial.Unsafe (unsafePartial) +import Prelude (Unit, (>=), (&&), (<<<), (<=), pure, (-), flip, (*), (*>)) import Type.Proxy (Proxy(..)) @@ -60,15 +59,15 @@ length = lengthImpl -- object creator implementations for each typed array -foreign import newUint8ClampedArray :: forall a. Fn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint8ClampedArray -foreign import newUint32Array :: forall a. Fn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint32Array -foreign import newUint16Array :: forall a. Fn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint16Array -foreign import newUint8Array :: forall a. Fn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint8Array -foreign import newInt32Array :: forall a. Fn3 a (Nullable ByteOffset) (Nullable ByteLength) Int32Array -foreign import newInt16Array :: forall a. Fn3 a (Nullable ByteOffset) (Nullable ByteLength) Int16Array -foreign import newInt8Array :: forall a. Fn3 a (Nullable ByteOffset) (Nullable ByteLength) Int8Array -foreign import newFloat32Array :: forall a. Fn3 a (Nullable ByteOffset) (Nullable ByteLength) Float32Array -foreign import newFloat64Array :: forall a. Fn3 a (Nullable ByteOffset) (Nullable ByteLength) Float64Array +foreign import newUint8ClampedArray :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint8ClampedArray +foreign import newUint32Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint32Array +foreign import newUint16Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint16Array +foreign import newUint8Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint8Array +foreign import newInt32Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Int32Array +foreign import newInt16Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Int16Array +foreign import newInt8Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Int8Array +foreign import newFloat32Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Float32Array +foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Float64Array -- ---- @@ -135,7 +134,7 @@ type Range = Maybe (Tuple Offset (Maybe Offset)) -- | - `toString` prints to a CSV, `toString'` allows you to supply the delimiter -- | - `toArray` returns an array of numeric values class BinaryValue a t <= TypedArray (a :: ArrayViewType) (t :: Type) | a -> t where - create :: forall x. Fn3 x (Nullable ByteOffset) (Nullable ByteLength) (ArrayView a) + create :: forall x. EffectFn3 x (Nullable ByteOffset) (Nullable ByteLength) (ArrayView a) instance typedArrayUint8Clamped :: TypedArray Uint8Clamped UInt where create = newUint8ClampedArray @@ -157,32 +156,32 @@ instance typedArrayFloat64 :: TypedArray Float64 Number where create = newFloat64Array -- | View mapping the whole `ArrayBuffer`. -whole :: forall a t. TypedArray a t => ArrayBuffer -> ArrayView a -whole a = runFn3 create a null null +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 -> Offset -> ArrayView a +remainder :: forall a b t. TypedArray a t => Nat b => BytesPerValue a b => ArrayBuffer -> Offset -> Effect (ArrayView a) remainder a x = remainder' a o where o = x * toInt' (Proxy :: Proxy b) -remainder' :: forall a t. TypedArray a t => ArrayBuffer -> ByteOffset -> ArrayView a -remainder' a x = runFn3 create a (notNull x) null +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 -> Offset -> Length -> ArrayView a +part :: forall a b t. TypedArray a t => Nat b => BytesPerValue a b => ArrayBuffer -> Offset -> Length -> Effect (ArrayView a) part a x y = part' a o y where o = x * toInt' (Proxy :: Proxy b) -part' :: forall a t. TypedArray a t => ArrayBuffer -> ByteOffset -> Length -> ArrayView a -part' a x y = runFn3 create a (notNull x) (notNull y) +part' :: forall a t. TypedArray a t => ArrayBuffer -> ByteOffset -> Length -> Effect (ArrayView a) +part' a x y = runEffectFn3 create a (notNull x) (notNull y) -- | Creates an empty typed array, where each value is assigned 0 -empty :: forall a t. TypedArray a t => Length -> ArrayView a -empty n = runFn3 create n null null +empty :: forall a t. TypedArray a t => Length -> Effect (ArrayView a) +empty n = runEffectFn3 create n null null -- | Creates a typed array from an input array of values, to be binary serialized -fromArray :: forall a t. TypedArray a t => Array t -> ArrayView a -fromArray a = runFn3 create a null null +fromArray :: forall a t. TypedArray a t => Array t -> Effect (ArrayView a) +fromArray a = runEffectFn3 create a null null -- | Fill the array with a value fill :: forall a t. TypedArray a t => ArrayView a -> t -> Range -> Effect Unit @@ -424,8 +423,8 @@ at a n = if a `hasIndex` n infixl 3 at as ! -foreign import toArrayImpl :: forall a b. ArrayView a -> Array b +foreign import toArrayImpl :: forall a b. EffectFn1 (ArrayView a) (Array b) -- | Turn typed array into an array. -toArray :: forall a t. TypedArray a t => ArrayView a -> Array t -toArray = toArrayImpl +toArray :: forall a t. TypedArray a t => ArrayView a -> Effect (Array t) +toArray a = runEffectFn1 toArrayImpl a diff --git a/src/Data/ArrayBuffer/Typed/Gen.purs b/src/Data/ArrayBuffer/Typed/Gen.purs index ffe3dd8..ebc7db0 100644 --- a/src/Data/ArrayBuffer/Typed/Gen.purs +++ b/src/Data/ArrayBuffer/Typed/Gen.purs @@ -2,23 +2,23 @@ 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.Float32 (Float32, fromNumber) as F import Data.Generic.Rep (class Generic) import Data.Maybe (Maybe(..)) import Data.Typelevel.Num (class Nat, toInt') import Data.UInt (UInt) import Data.UInt (fromInt) as UInt -import Data.Float32 (Float32, fromNumber) as F import Data.UInt.Gen (genUInt) as UInt import Data.Unfoldable (replicateA) import Data.Vec (Vec) import Data.Vec (fromArray) as Vec +import Effect.Unsafe (unsafePerformEffect) import Partial.Unsafe (unsafePartial) +import Prelude ((<$>), bind, (/), (-), negate, ($), bottom, pure, top) import Type.Proxy (Proxy(..)) @@ -30,7 +30,7 @@ genTypedArray :: forall m a t genTypedArray gen = sized \s -> do n <- chooseInt 0 s a <- replicateA n gen - pure (TA.fromArray a) + pure (unsafePerformEffect $ TA.fromArray a) genUint8 :: forall m. MonadGen m => m UInt genUint8 = UInt.fromInt <$> chooseInt 0 255 diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index e570952..b9cbfbd 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -4,7 +4,6 @@ module Test.Properties.TypedArray where import Prelude import Control.Monad.Gen (suchThat) -import Data.Array (drop, take) import Data.Array as Array import Data.ArrayBuffer.Typed (class TypedArray) import Data.ArrayBuffer.Typed as TA @@ -92,9 +91,7 @@ typedArrayTests count = do log " - let z' = subArray 0 (length x) x; q = toArray x; mutate z'; pure q /= toArray x" modifyingSubArrayMutatesOriginalAllTests count log " - let z' = subArray o x; q = toArray z'; mutate x; pure q == toArray z'" - modifyingOriginalDoesntMutateSubArrayPartTests count - log " - let z' = subArray 0 o x; q = toArray z'; mutate x; pure q == toArray z'" - modifyingOriginalDoesntMutateSubArrayPart2Tests count + modifyingOriginalMutatesSubArrayPartTests count log " - let z' = slice x; q = toArray z'; mutate x; pure q == toArray z'" modifyingOriginalDoesntMutateSliceTests count log " - let z' = slice o x; q = toArray z'; mutate x; pure q == toArray z'" @@ -119,7 +116,7 @@ type TestableArrayF a b n t q = => BytesPerValue a b => Nat b => WithOffset n a - -> q + -> 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 @@ -129,7 +126,7 @@ overAll' mn count f = do 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 log $ " - " <> s - quickCheckGen $ f <$> genWithOffset arr + quickCheckGen $ unsafePerformEffect <<< f <$> genWithOffset arr where arr :: Gen (ArrayView a) arr = genTypedArray gen `suchThat` \xs -> mn <= TA.length xs @@ -154,13 +151,12 @@ partBehavesLikeTakeDrop :: Ref Int -> Effect Unit partBehavesLikeTakeDrop count = overAll count f where f :: forall a b t. TestableArrayF a b D0 t Result - f (WithOffset _ a) = + f (WithOffset _ xs) = do let n = 2 - na = TA.toArray a - ba = TA.buffer a - pa :: ArrayView a - pa = TA.part ba n n - in take n (drop n na) === TA.toArray pa + 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 count byteLengthDivBytesPerValueEqLength @@ -168,21 +164,24 @@ byteLengthDivBytesPerValueTests count = overAll count byteLengthDivBytesPerValue byteLengthDivBytesPerValueEqLength :: forall a b t. TestableArrayF a b D0 t Result byteLengthDivBytesPerValueEqLength (WithOffset _ a) = let b = toInt' (Proxy :: Proxy b) - in TA.length a === (TA.byteLength a `div` b) + in pure $ TA.length a === (TA.byteLength a `div` b) fromArrayToArrayIsoTests :: Ref Int -> Effect Unit fromArrayToArrayIsoTests count = overAll count fromArrayToArrayIso where fromArrayToArrayIso :: forall a b t. TestableArrayF a b D0 t Result - fromArrayToArrayIso (WithOffset _ x) = - TA.toArray (TA.fromArray (TA.toArray x) :: ArrayView a) === TA.toArray x + fromArrayToArrayIso (WithOffset _ 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 count allAreFilled where allAreFilled :: forall a b t. TestableArrayF a b D0 t Result - allAreFilled (WithOffset _ xs) = unsafePerformEffect do + allAreFilled (WithOffset _ xs) = do let x = case TA.at xs 0 of Nothing -> zero Just y -> y @@ -195,7 +194,7 @@ setSingletonIsEqTests :: Ref Int -> Effect Unit setSingletonIsEqTests count = overAll count setSingletonIsEq where setSingletonIsEq :: forall a b t. TestableArrayF a b D1 t Result - setSingletonIsEq (WithOffset os xs) = unsafePerformEffect do + setSingletonIsEq (WithOffset os xs) = do case TA.at xs 0 of Nothing -> pure Success Just x -> do @@ -212,7 +211,7 @@ allImpliesAnyTests count = overAll count allImpliesAny let pred x = x /= zero all' = TA.all pred xs "All don't satisfy the predicate" any' = TA.any pred xs "None satisfy the predicate" - in (TA.length xs === zero) |=| all' ==> any' + in pure $ (TA.length xs === zero) |=| all' ==> any' -- | Should work with any arbitrary predicate, but we can't generate them @@ -224,7 +223,7 @@ filterImpliesAllTests count = overAll count filterImpliesAll let pred x = x /= zero ys = TA.filter pred xs all' = TA.all pred ys - in all' "Filter doesn't imply all" + in pure $ all' "Filter doesn't imply all" -- | Should work with any arbitrary predicate, but we can't generate them @@ -232,11 +231,12 @@ filterIsTotalTests :: Ref Int -> Effect Unit filterIsTotalTests count = overAll count filterIsTotal where filterIsTotal :: forall a b t. TestableArrayF a b D0 t Result - filterIsTotal (WithOffset _ xs) = + filterIsTotal (WithOffset _ xs) = do let pred x = x /= zero ys = TA.filter pred xs zs = TA.filter (\x -> not pred x) ys - in TA.toArray zs === [] + azs <- TA.toArray zs + pure $ azs === [] -- | Should work with any arbitrary predicate, but we can't generate them @@ -244,26 +244,28 @@ filterIsIdempotentTests :: Ref Int -> Effect Unit filterIsIdempotentTests count = overAll count filterIsIdempotent where filterIsIdempotent :: forall a b t. TestableArrayF a b D0 t Result - filterIsIdempotent (WithOffset _ xs) = + filterIsIdempotent (WithOffset _ xs) = do let pred x = x /= zero ys = TA.filter pred xs zs = TA.filter pred ys - in TA.toArray zs === TA.toArray ys + azs <- TA.toArray zs + ays <- TA.toArray ys + pure $ azs === ays withOffsetHasIndexTests :: Ref Int -> Effect Unit withOffsetHasIndexTests count = overAll1 count withOffsetHasIndex where withOffsetHasIndex :: forall a b t. TestableArrayF a b D5 t Result - withOffsetHasIndex (WithOffset os xs) = - Array.all (\o -> TA.hasIndex xs o) os "All doesn't have index of itself" + withOffsetHasIndex (WithOffset os xs) = pure $ + Array.all (TA.hasIndex xs) os "All doesn't have index of itself" withOffsetElemTests :: Ref Int -> Effect Unit withOffsetElemTests count = overAll1 count withOffsetElem where withOffsetElem :: forall a b t. TestableArrayF a b D5 t Result - withOffsetElem (WithOffset os xs) = + withOffsetElem (WithOffset os xs) = pure $ Array.all (\o -> TA.elem (unsafePartial (TA.unsafeAt xs o)) Nothing xs) os "All doesn't have an elem of itself" @@ -282,7 +284,7 @@ anyImpliesFindTests count = overAll count anyImpliesFind Just z -> if pred z then Success else Failed "Found value doesn't satisfy the predicate" - in p ==> q + in pure $ p ==> q -- | Should work with any arbitrary predicate, but we can't generate them @@ -293,7 +295,7 @@ findIndexImpliesAtTests count = overAll count findIndexImpliesAt findIndexImpliesAt (WithOffset _ xs) = let pred x o = x /= zero mo = TA.findIndex pred xs - in case mo of + in pure case mo of Nothing -> Success Just o -> case TA.at xs o of Nothing -> Failed "No value at found index" @@ -305,7 +307,7 @@ indexOfImpliesAtTests :: Ref Int -> Effect Unit indexOfImpliesAtTests count = overAll count indexOfImpliesAt where indexOfImpliesAt :: forall a b t. TestableArrayF a b D0 t Result - indexOfImpliesAt (WithOffset _ xs) = + indexOfImpliesAt (WithOffset _ xs) = pure case TA.at xs 0 of Nothing -> Success Just y -> case TA.indexOf y Nothing xs of @@ -317,7 +319,7 @@ lastIndexOfImpliesAtTests :: Ref Int -> Effect Unit lastIndexOfImpliesAtTests count = overAll count lastIndexOfImpliesAt where lastIndexOfImpliesAt :: forall a b t. TestableArrayF a b D0 t Result - lastIndexOfImpliesAt (WithOffset _ xs) = + lastIndexOfImpliesAt (WithOffset _ xs) = pure case TA.at xs 0 of Nothing -> Success Just y -> case TA.lastIndexOf y Nothing xs of @@ -329,84 +331,87 @@ foldrConsIsToArrayTests :: Ref Int -> Effect Unit foldrConsIsToArrayTests count = overAll count foldrConsIsToArray where foldrConsIsToArray :: forall a b t. TestableArrayF a b D0 t Result - foldrConsIsToArray (WithOffset _ xs) = - TA.foldr (\x acc -> Array.cons x acc) [] xs === TA.toArray xs + foldrConsIsToArray (WithOffset _ xs) = do + axs <- TA.toArray xs + pure $ TA.foldr (\x acc -> Array.cons x acc) [] xs === axs foldlSnocIsToArrayTests :: Ref Int -> Effect Unit foldlSnocIsToArrayTests count = overAll count foldlSnocIsToArray where foldlSnocIsToArray :: forall a b t. TestableArrayF a b D0 t Result - foldlSnocIsToArray (WithOffset _ xs) = - TA.foldl (\acc x -> Array.snoc acc x) [] xs === TA.toArray xs + foldlSnocIsToArray (WithOffset _ xs) = do + axs <- TA.toArray xs + pure $ TA.foldl (\acc x -> Array.snoc acc x) [] xs === axs mapIdentityIsIdentityTests :: Ref Int -> Effect Unit mapIdentityIsIdentityTests count = overAll count mapIdentityIsIdentity where mapIdentityIsIdentity :: forall a b t. TestableArrayF a b D0 t Result - mapIdentityIsIdentity (WithOffset _ xs) = - TA.toArray (TA.map identity xs) === TA.toArray xs + mapIdentityIsIdentity (WithOffset _ xs) = do + axs <- TA.toArray xs + mxs <- TA.toArray (TA.map identity xs) + pure $ axs === mxs traverseSnocIsToArrayTests :: Ref Int -> Effect Unit traverseSnocIsToArrayTests count = overAll count traverseSnocIsToArray where traverseSnocIsToArray :: forall a b t. TestableArrayF a b D0 t Result - traverseSnocIsToArray (WithOffset _ xs) = - let ys = unsafePerformEffect do - ref <- Ref.new [] - TA.traverse_ (\x -> void (Ref.modify (\xs' -> Array.snoc xs' x) ref)) xs - Ref.read ref - in TA.toArray xs === ys + traverseSnocIsToArray (WithOffset _ 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 count doubleReverseIsIdentity where doubleReverseIsIdentity :: forall a b t. TestableArrayF a b D0 t Result - doubleReverseIsIdentity (WithOffset _ xs) = - let ys = TA.toArray xs - _ = unsafePerformEffect do - TA.reverse xs - TA.reverse xs - in TA.toArray xs === ys + doubleReverseIsIdentity (WithOffset _ 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 count reverseIsArrayReverse where reverseIsArrayReverse :: forall a b t. TestableArrayF a b D0 t Result - reverseIsArrayReverse (WithOffset _ xs) = - let ys = Array.reverse (TA.toArray xs) - _ = unsafePerformEffect do - TA.reverse xs - in TA.toArray xs === ys + reverseIsArrayReverse (WithOffset _ 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 count sortIsIdempotent where sortIsIdempotent :: forall a b t. TestableArrayF a b D0 t Result - sortIsIdempotent (WithOffset _ xs) = - let ys = unsafePerformEffect do - TA.sort xs - pure (TA.toArray xs) - zs = unsafePerformEffect do - TA.sort xs - pure (TA.toArray xs) - in zs === ys + sortIsIdempotent (WithOffset _ 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 count sortIsArraySort where sortIsArraySort :: forall a b t. TestableArrayF a b D0 t Result - sortIsArraySort (WithOffset _ xs) = - let ys = Array.sort (TA.toArray xs) - _ = unsafePerformEffect do - TA.sort xs - in TA.toArray xs === ys + sortIsArraySort (WithOffset _ 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 @@ -414,231 +419,218 @@ toStringIsJoinWithCommaTests count = overAll count toStringIsJoinWithComma where toStringIsJoinWithComma :: forall a b t. TestableArrayF a b D0 t Result toStringIsJoinWithComma (WithOffset _ xs) = - TA.toString' xs "," === TA.toString xs + pure $ TA.toString' xs "," === TA.toString xs setTypedOfSubArrayIsIdentityTests :: Ref Int -> Effect Unit setTypedOfSubArrayIsIdentityTests count = overAll count setTypedOfSubArrayIsIdentity where setTypedOfSubArrayIsIdentity :: forall a b t. TestableArrayF a b D0 t Result - setTypedOfSubArrayIsIdentity (WithOffset _ xs) = - let ys = TA.toArray xs - zsSub = TA.subArray xs Nothing - zs = unsafePerformEffect do - _ <- TA.setTyped xs Nothing zsSub - pure (TA.toArray xs) - in zs === ys + setTypedOfSubArrayIsIdentity (WithOffset _ xs) = do + ys <- TA.toArray xs + let zsSub = TA.subArray xs Nothing + _ <- TA.setTyped xs Nothing zsSub + zs <- TA.toArray xs + pure $ zs === ys modifyingOriginalMutatesSubArrayTests :: Ref Int -> Effect Unit modifyingOriginalMutatesSubArrayTests count = overAll count modifyingOriginalMutatesSubArray where modifyingOriginalMutatesSubArray :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalMutatesSubArray (WithOffset _ xs) - | Array.all (eq zero) (TA.toArray xs) = Success - | otherwise = + modifyingOriginalMutatesSubArray (WithOffset _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs + then pure Success + else do let zsSub = TA.subArray xs Nothing - zs = TA.toArray zsSub - ys = unsafePerformEffect do - TA.fill xs zero Nothing - pure (TA.toArray zsSub) - in zs /== ys + zs <- TA.toArray zsSub + TA.fill xs zero Nothing + ys <- TA.toArray zsSub + pure $ zs /== ys modifyingSubArrayMutatesOriginalTests :: Ref Int -> Effect Unit modifyingSubArrayMutatesOriginalTests count = overAll count modifyingOriginalMutatesSubArray where modifyingOriginalMutatesSubArray :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalMutatesSubArray (WithOffset _ xs) - | Array.all (eq zero) (TA.toArray xs) = Success - | otherwise = + modifyingOriginalMutatesSubArray (WithOffset _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs + then pure Success + else do let zsSub = TA.subArray xs Nothing - zs = TA.toArray xs - ys = unsafePerformEffect do - TA.fill zsSub zero Nothing - pure (TA.toArray xs) - in zs /== ys + zs <- TA.toArray xs + TA.fill zsSub zero Nothing + ys <- TA.toArray xs + pure $ zs /== ys modifyingOriginalMutatesSubArrayZeroTests :: Ref Int -> Effect Unit modifyingOriginalMutatesSubArrayZeroTests count = overAll count modifyingOriginalMutatesSubArrayZero where modifyingOriginalMutatesSubArrayZero :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalMutatesSubArrayZero (WithOffset _ xs) - | Array.all (eq zero) (TA.toArray xs) = Success - | otherwise = + modifyingOriginalMutatesSubArrayZero (WithOffset _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs + then pure Success + else do let zsSub = TA.subArray xs (Just (Tuple 0 Nothing)) - zs = TA.toArray zsSub - ys = unsafePerformEffect do - TA.fill xs zero Nothing - pure (TA.toArray zsSub) - in zs /== ys + zs <- TA.toArray zsSub + TA.fill xs zero Nothing + ys <- TA.toArray zsSub + pure $ zs /== ys modifyingSubArrayMutatesOriginalZeroTests :: Ref Int -> Effect Unit modifyingSubArrayMutatesOriginalZeroTests count = overAll count modifyingSubArrayMutatesOriginalZero where modifyingSubArrayMutatesOriginalZero :: forall a b t. TestableArrayF a b D0 t Result - modifyingSubArrayMutatesOriginalZero (WithOffset _ xs) - | Array.all (eq zero) (TA.toArray xs) = Success - | otherwise = + modifyingSubArrayMutatesOriginalZero (WithOffset _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs + then pure Success + else do let zsSub = TA.subArray xs (Just (Tuple 0 Nothing)) - zs = TA.toArray xs - ys = unsafePerformEffect do - TA.fill zsSub zero Nothing - pure (TA.toArray xs) - in zs /== ys + zs <- TA.toArray xs + TA.fill zsSub zero Nothing + ys <- TA.toArray xs + pure $ zs /== ys modifyingOriginalMutatesSubArrayAllTests :: Ref Int -> Effect Unit modifyingOriginalMutatesSubArrayAllTests count = overAll count modifyingOriginalMutatesSubArrayAll where modifyingOriginalMutatesSubArrayAll :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalMutatesSubArrayAll (WithOffset _ xs) - | Array.all (eq zero) (TA.toArray xs) = Success - | otherwise = + modifyingOriginalMutatesSubArrayAll (WithOffset _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs + then pure Success + else do let zsSub = TA.subArray xs (Just (Tuple 0 (Just (TA.length xs)))) - zs = TA.toArray zsSub - ys = unsafePerformEffect do - TA.fill xs zero Nothing - pure (TA.toArray zsSub) - in zs /== ys + zs <- TA.toArray zsSub + TA.fill xs zero Nothing + ys <- TA.toArray zsSub + pure $ zs /== ys modifyingSubArrayMutatesOriginalAllTests :: Ref Int -> Effect Unit modifyingSubArrayMutatesOriginalAllTests count = overAll count modifyingSubArrayMutatesOriginalAll where modifyingSubArrayMutatesOriginalAll :: forall a b t. TestableArrayF a b D0 t Result - modifyingSubArrayMutatesOriginalAll (WithOffset _ xs) - | Array.all (eq zero) (TA.toArray xs) = Success - | otherwise = + modifyingSubArrayMutatesOriginalAll (WithOffset _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs + then pure Success + else do let zsSub = TA.subArray xs (Just (Tuple 0 (Just (TA.length xs)))) - zs = TA.toArray xs - ys = unsafePerformEffect do - TA.fill zsSub zero Nothing - pure (TA.toArray xs) - in zs /== ys + zs <- TA.toArray xs + TA.fill zsSub zero Nothing + ys <- TA.toArray xs + pure $ zs /== ys -modifyingOriginalDoesntMutateSubArrayPartTests :: Ref Int -> Effect Unit -modifyingOriginalDoesntMutateSubArrayPartTests count = overAll count modifyingOriginalMutatesSubArrayPart +modifyingOriginalMutatesSubArrayPartTests :: Ref Int -> Effect Unit +modifyingOriginalMutatesSubArrayPartTests count = overAll count modifyingOriginalMutatesSubArrayPart where modifyingOriginalMutatesSubArrayPart :: forall a b t. TestableArrayF a b D1 t Result - modifyingOriginalMutatesSubArrayPart (WithOffset os xs) - | Vec.head os == 0 = Success - | Array.all (eq zero) (TA.toArray (TA.subArray xs Nothing)) = Success - | TA.at xs (Vec.head os) == Just zero = Success - | otherwise = - let o = Vec.head os - zsSub = TA.subArray xs (Just (Tuple o Nothing)) - zs = TA.toArray zsSub - ys = unsafePerformEffect do - TA.fill xs zero Nothing - pure (TA.toArray zsSub) - in zs === ys - - -modifyingOriginalDoesntMutateSubArrayPart2Tests :: Ref Int -> Effect Unit -modifyingOriginalDoesntMutateSubArrayPart2Tests count = overAll count modifyingOriginalMutatesSubArrayPart2 - where - modifyingOriginalMutatesSubArrayPart2 :: forall a b t. TestableArrayF a b D1 t Result - modifyingOriginalMutatesSubArrayPart2 (WithOffset os xs) - | Vec.head os == 0 = Success - | Array.all (eq zero) (TA.toArray (TA.subArray xs Nothing)) = Success - | TA.at xs (Vec.head os) == Just zero = Success - | otherwise = - let o = Vec.head os - zsSub = TA.subArray xs (Just (Tuple 0 (Just o))) - zs = TA.toArray zsSub - ys = unsafePerformEffect do - TA.fill xs zero Nothing - pure (TA.toArray zsSub) - in zs === ys + modifyingOriginalMutatesSubArrayPart (WithOffset os xs) = do + let o = Vec.head os + zsSub = TA.subArray xs (Just (Tuple o Nothing)) + zs <- TA.toArray zsSub + if o == 0 || Array.all (eq zero) zs + then pure Success + else do + TA.fill xs zero Nothing + ys <- TA.toArray zsSub + pure $ zs /== ys modifyingOriginalDoesntMutateSliceTests :: Ref Int -> Effect Unit modifyingOriginalDoesntMutateSliceTests count = overAll count modifyingOriginalDoesntMutateSlice where modifyingOriginalDoesntMutateSlice :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalDoesntMutateSlice (WithOffset _ xs) - | Array.all (eq zero) (TA.toArray xs) = Success - | otherwise = + modifyingOriginalDoesntMutateSlice (WithOffset _ xs) = do + axs <- TA.toArray xs + if Array.all (eq zero) axs + then pure Success + else do let zsSub = TA.slice xs Nothing - zs = TA.toArray zsSub - ys = unsafePerformEffect do - TA.fill xs zero Nothing - pure (TA.toArray zsSub) - in zs === ys + zs <- TA.toArray zsSub + TA.fill xs zero Nothing + ys <- TA.toArray zsSub + pure $ zs === ys modifyingOriginalDoesntMutateSlicePartTests :: Ref Int -> Effect Unit modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOriginalDoesntMutateSlicePart where modifyingOriginalDoesntMutateSlicePart :: forall a b t. TestableArrayF a b D1 t Result - modifyingOriginalDoesntMutateSlicePart (WithOffset os xs) - | Array.all (eq zero) (TA.toArray (TA.slice xs (Just (Tuple (Vec.head os) Nothing)))) = Success - | TA.at xs (Vec.head os) == Just zero = Success - | otherwise = + modifyingOriginalDoesntMutateSlicePart (WithOffset os xs) = do + axs <- TA.toArray (TA.slice xs (Just (Tuple (Vec.head os) Nothing))) + if Array.all (eq zero) axs || TA.at xs (Vec.head os) == Just zero + then pure Success + else do let o = Vec.head os zsSub = TA.slice xs (Just (Tuple o Nothing)) - zs = TA.toArray zsSub - ys = unsafePerformEffect do - TA.fill xs zero Nothing - pure (TA.toArray zsSub) - in zs === ys + zs <- TA.toArray zsSub + TA.fill xs zero Nothing + ys <- TA.toArray zsSub + pure $ zs === ys modifyingOriginalDoesntMutateSlicePart2Tests :: Ref Int -> Effect Unit modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOriginalDoesntMutateSlicePart2 where modifyingOriginalDoesntMutateSlicePart2 :: forall a b t. TestableArrayF a b D1 t Result - modifyingOriginalDoesntMutateSlicePart2 (WithOffset os xs) - | Array.all (eq zero) (TA.toArray (TA.slice xs (Just (Tuple (Vec.head os) Nothing)))) = Success - | TA.at xs (Vec.head os) == Just zero = Success - | otherwise = + modifyingOriginalDoesntMutateSlicePart2 (WithOffset os xs) = do + axs <- TA.toArray (TA.slice xs (Just (Tuple (Vec.head os) Nothing))) + if Array.all (eq zero) axs || TA.at xs (Vec.head os) == Just zero + then pure Success + else do let o = Vec.head os zsSub = TA.slice xs (Just (Tuple 0 (Just o))) - zs = TA.toArray zsSub - ys = unsafePerformEffect do - TA.fill xs zero Nothing - pure (TA.toArray zsSub) - in zs === ys + zs <- TA.toArray zsSub + TA.fill xs zero Nothing + ys <- TA.toArray zsSub + pure $ zs === ys copyWithinSelfIsIdentityTests :: Ref Int -> Effect Unit copyWithinSelfIsIdentityTests count = overAll count copyWithinSelfIsIdentity where copyWithinSelfIsIdentity :: forall a b t. TestableArrayF a b D0 t Result - copyWithinSelfIsIdentity (WithOffset _ xs) = - let ys = TA.toArray xs - zs = unsafePerformEffect do - TA.copyWithin xs 0 0 (Just (TA.length xs)) - pure (TA.toArray xs) - in zs === ys + copyWithinSelfIsIdentity (WithOffset _ 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 count copyWithinIsSlice where copyWithinIsSlice :: forall a b t. TestableArrayF a b D1 t Result - copyWithinIsSlice (WithOffset os xs) = + copyWithinIsSlice (WithOffset os xs) = do let o = Vec.head os - ys = TA.toArray (TA.slice xs (Just (Tuple o Nothing))) - zs = unsafePerformEffect do - TA.copyWithin xs 0 o Nothing - pure $ Array.drop (Array.length ys) $ TA.toArray xs - in TA.toArray xs === ys <> zs + ys <- TA.toArray (TA.slice xs (Just (Tuple o Nothing))) + 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 count copyWithinViaSetTyped where copyWithinViaSetTyped :: forall a b t. TestableArrayF a b D1 t Result - copyWithinViaSetTyped (WithOffset os xs) = + copyWithinViaSetTyped (WithOffset os xs) = do let o = Vec.head os - xs' = TA.fromArray (TA.toArray xs) :: ArrayView a - _ = unsafePerformEffect do - let ys = TA.slice xs' (Just (Tuple o Nothing)) - _ <- TA.setTyped xs' Nothing ys - TA.copyWithin xs 0 o Nothing - in TA.toArray xs === TA.toArray xs' + txs <- TA.toArray xs + xs' <- TA.fromArray txs :: Effect (ArrayView a) + let ys = TA.slice xs' (Just (Tuple o Nothing)) + _ <- TA.setTyped xs' Nothing ys + TA.copyWithin xs 0 o Nothing + axs <- TA.toArray xs + axs' <- TA.toArray xs' + pure $ axs === axs' From a76f4c874536836358e1693972f96c9ca2b6554b Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sun, 27 Jan 2019 23:23:52 +0100 Subject: [PATCH 08/79] Effectful slice --- src/Data/ArrayBuffer/Typed.purs | 8 ++++---- test/Properties/TypedArray.purs | 27 +++++++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 0a376e6..f6bb84c 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -367,13 +367,13 @@ setTyped = setInternal length -- | Copy the entire contents of the typed array into a new buffer. -foreign import sliceImpl :: forall a. Fn3 (ArrayView a) (Nullable Offset) (Nullable Offset) (ArrayView a) +foreign import sliceImpl :: forall a. EffectFn3 (ArrayView a) (Nullable Offset) (Nullable Offset) (ArrayView a) -- | Copy part of the contents of a typed array into a new buffer, between some start and end indices. -slice :: forall a. ArrayView a -> Range -> ArrayView a +slice :: forall a. ArrayView a -> Range -> Effect (ArrayView a) slice a mz = case mz of - Nothing -> runFn3 sliceImpl a null null - Just (Tuple s me) -> runFn3 sliceImpl a (notNull s) (toNullable me) + Nothing -> runEffectFn3 sliceImpl a null null + Just (Tuple s me) -> runEffectFn3 sliceImpl a (notNull s) (toNullable me) foreign import sortImpl :: forall a. EffectFn1 (ArrayView a) Unit diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index b9cbfbd..978ff24 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -555,7 +555,7 @@ modifyingOriginalDoesntMutateSliceTests count = overAll count modifyingOriginalD if Array.all (eq zero) axs then pure Success else do - let zsSub = TA.slice xs Nothing + zsSub <- TA.slice xs Nothing zs <- TA.toArray zsSub TA.fill xs zero Nothing ys <- TA.toArray zsSub @@ -567,12 +567,13 @@ modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOrigi where modifyingOriginalDoesntMutateSlicePart :: forall a b t. TestableArrayF a b D1 t Result modifyingOriginalDoesntMutateSlicePart (WithOffset os xs) = do - axs <- TA.toArray (TA.slice xs (Just (Tuple (Vec.head os) Nothing))) - if Array.all (eq zero) axs || TA.at xs (Vec.head os) == Just zero + sl <- TA.slice xs (Just (Tuple (Vec.head os) Nothing)) + axs <- TA.toArray sl + let o = Vec.head os + if Array.all (eq zero) axs || TA.at xs o == Just zero then pure Success else do - let o = Vec.head os - zsSub = TA.slice xs (Just (Tuple o Nothing)) + zsSub <- TA.slice xs (Just (Tuple o Nothing)) zs <- TA.toArray zsSub TA.fill xs zero Nothing ys <- TA.toArray zsSub @@ -584,12 +585,13 @@ modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOrig where modifyingOriginalDoesntMutateSlicePart2 :: forall a b t. TestableArrayF a b D1 t Result modifyingOriginalDoesntMutateSlicePart2 (WithOffset os xs) = do - axs <- TA.toArray (TA.slice xs (Just (Tuple (Vec.head os) Nothing))) - if Array.all (eq zero) axs || TA.at xs (Vec.head os) == Just zero - then pure Success + sl <- TA.slice xs (Just (Tuple (Vec.head os) Nothing)) + axs <- TA.toArray sl + let o = Vec.head os + if Array.all (eq zero) axs || TA.at xs o == Just zero + then pure Success else do - let o = Vec.head os - zsSub = TA.slice xs (Just (Tuple 0 (Just o))) + zsSub <- TA.slice xs (Just (Tuple 0 (Just o))) zs <- TA.toArray zsSub TA.fill xs zero Nothing ys <- TA.toArray zsSub @@ -613,7 +615,8 @@ copyWithinIsSliceTests count = overAll count copyWithinIsSlice copyWithinIsSlice :: forall a b t. TestableArrayF a b D1 t Result copyWithinIsSlice (WithOffset os xs) = do let o = Vec.head os - ys <- TA.toArray (TA.slice xs (Just (Tuple o Nothing))) + sl <- TA.slice xs (Just (Tuple o Nothing)) + ys <- TA.toArray sl TA.copyWithin xs 0 o Nothing axs <- TA.toArray xs zs <- pure $ Array.drop (Array.length ys) axs @@ -628,7 +631,7 @@ copyWithinViaSetTypedTests count = overAll count copyWithinViaSetTyped let o = Vec.head os txs <- TA.toArray xs xs' <- TA.fromArray txs :: Effect (ArrayView a) - let ys = TA.slice xs' (Just (Tuple o Nothing)) + ys <- TA.slice xs' (Just (Tuple o Nothing)) _ <- TA.setTyped xs' Nothing ys TA.copyWithin xs 0 o Nothing axs <- TA.toArray xs From e50d73e9746f19b83aff18f6026d336ab7ddc6e4 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sun, 27 Jan 2019 23:34:17 +0100 Subject: [PATCH 09/79] Simplify some lambdas, remove some unneeded bindings --- test/Properties/TypedArray.purs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index 978ff24..6c17127 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -121,7 +121,7 @@ type TestableArrayF a b n t 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 - void (Ref.modify (\x -> x + 1) count) + 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 @@ -186,7 +186,7 @@ allAreFilledTests count = overAll count allAreFilled Nothing -> zero Just y -> y TA.fill xs x Nothing - let b = TA.all (\y -> y == x) xs + let b = TA.all (_ == x) xs pure (b "All aren't the filled value") @@ -234,7 +234,7 @@ filterIsTotalTests count = overAll count filterIsTotal filterIsTotal (WithOffset _ xs) = do let pred x = x /= zero ys = TA.filter pred xs - zs = TA.filter (\x -> not pred x) ys + zs = TA.filter (not pred) ys azs <- TA.toArray zs pure $ azs === [] @@ -333,7 +333,7 @@ foldrConsIsToArrayTests count = overAll count foldrConsIsToArray foldrConsIsToArray :: forall a b t. TestableArrayF a b D0 t Result foldrConsIsToArray (WithOffset _ xs) = do axs <- TA.toArray xs - pure $ TA.foldr (\x acc -> Array.cons x acc) [] xs === axs + pure $ TA.foldr Array.cons [] xs === axs foldlSnocIsToArrayTests :: Ref Int -> Effect Unit @@ -342,7 +342,7 @@ foldlSnocIsToArrayTests count = overAll count foldlSnocIsToArray foldlSnocIsToArray :: forall a b t. TestableArrayF a b D0 t Result foldlSnocIsToArray (WithOffset _ xs) = do axs <- TA.toArray xs - pure $ TA.foldl (\acc x -> Array.snoc acc x) [] xs === axs + pure $ TA.foldl Array.snoc [] xs === axs mapIdentityIsIdentityTests :: Ref Int -> Effect Unit @@ -567,8 +567,7 @@ modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOrigi where modifyingOriginalDoesntMutateSlicePart :: forall a b t. TestableArrayF a b D1 t Result modifyingOriginalDoesntMutateSlicePart (WithOffset os xs) = do - sl <- TA.slice xs (Just (Tuple (Vec.head os) Nothing)) - axs <- TA.toArray sl + axs <- TA.toArray =<< TA.slice xs (Just (Tuple (Vec.head os) Nothing)) let o = Vec.head os if Array.all (eq zero) axs || TA.at xs o == Just zero then pure Success @@ -585,8 +584,7 @@ modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOrig where modifyingOriginalDoesntMutateSlicePart2 :: forall a b t. TestableArrayF a b D1 t Result modifyingOriginalDoesntMutateSlicePart2 (WithOffset os xs) = do - sl <- TA.slice xs (Just (Tuple (Vec.head os) Nothing)) - axs <- TA.toArray sl + axs <- TA.toArray =<< TA.slice xs (Just (Tuple (Vec.head os) Nothing)) let o = Vec.head os if Array.all (eq zero) axs || TA.at xs o == Just zero then pure Success @@ -615,8 +613,7 @@ copyWithinIsSliceTests count = overAll count copyWithinIsSlice copyWithinIsSlice :: forall a b t. TestableArrayF a b D1 t Result copyWithinIsSlice (WithOffset os xs) = do let o = Vec.head os - sl <- TA.slice xs (Just (Tuple o Nothing)) - ys <- TA.toArray sl + ys <- TA.toArray =<< TA.slice xs (Just (Tuple o Nothing)) TA.copyWithin xs 0 o Nothing axs <- TA.toArray xs zs <- pure $ Array.drop (Array.length ys) axs From f6caddc4077aec9d0cad13ee3246be46d5d8fa3b Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Mon, 28 Jan 2019 20:48:08 +0100 Subject: [PATCH 10/79] Changed at to be effectful --- src/Data/ArrayBuffer/Typed.purs | 14 ++++---- test/Properties/TypedArray.purs | 62 ++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index f6bb84c..04720e2 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -35,7 +35,7 @@ import Effect (Effect) import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4, mkEffectFn2, mkEffectFn3, runEffectFn1, runEffectFn2, runEffectFn3, runEffectFn4) import Effect.Unsafe (unsafePerformEffect) import Partial.Unsafe (unsafePartial) -import Prelude (Unit, (>=), (&&), (<<<), (<=), pure, (-), flip, (*), (*>)) +import Prelude (Unit, flip, pure, (&&), (*), (*>), (-), (<$>), (<<<), (<=), (>=)) import Type.Proxy (Proxy(..)) @@ -268,8 +268,8 @@ elem :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Boolea elem x mo a = runFn3 includesImpl a x (toNullable mo) -- | Fetch element at index. -unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Offset -> t -unsafeAt a o = runFn2 unsafeAtImpl a o +unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Offset -> Effect t +unsafeAt a o = runEffectFn2 unsafeAtImpl a o -- | Folding from the left foldlM :: forall a t b. TypedArray a t => (b -> t -> Offset -> Effect b) -> b -> ArrayView a -> Effect b @@ -406,7 +406,7 @@ toString' :: forall a. ArrayView a -> String -> String toString' a s = runFn2 joinImpl a s -foreign import unsafeAtImpl :: forall a b. Fn2 (ArrayView a) Offset b +foreign import unsafeAtImpl :: forall a b. EffectFn2 (ArrayView a) Offset b foreign import hasIndexImpl :: forall a. Fn2 (ArrayView a) Offset Boolean @@ -415,10 +415,10 @@ hasIndex :: forall a. ArrayView a -> Offset -> Boolean hasIndex a o = runFn2 hasIndexImpl a o -- | Fetch element at index. -at :: forall a t. TypedArray a t => ArrayView a -> Offset -> Maybe t +at :: forall a t. TypedArray a t => ArrayView a -> Offset -> Effect (Maybe t) at a n = if a `hasIndex` n - then Just (unsafePartial (unsafeAt a n)) - else Nothing + then Just <$> unsafePartial (unsafeAt a n) + else pure Nothing infixl 3 at as ! diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index 6c17127..782fe9b 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -182,7 +182,8 @@ allAreFilledTests count = overAll count allAreFilled where allAreFilled :: forall a b t. TestableArrayF a b D0 t Result allAreFilled (WithOffset _ xs) = do - let x = case TA.at xs 0 of + e <- TA.at xs 0 + let x = case e of Nothing -> zero Just y -> y TA.fill xs x Nothing @@ -195,11 +196,14 @@ setSingletonIsEqTests count = overAll count setSingletonIsEq where setSingletonIsEq :: forall a b t. TestableArrayF a b D1 t Result setSingletonIsEq (WithOffset os xs) = do - case TA.at xs 0 of + e <- TA.at xs 0 + case e of Nothing -> pure Success Just x -> do - _ <- TA.set xs (Just (Vec.head os)) [x] - pure (TA.at xs (Vec.head os) === Just x) + let o = Vec.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 @@ -266,7 +270,7 @@ withOffsetElemTests count = overAll1 count withOffsetElem where withOffsetElem :: forall a b t. TestableArrayF a b D5 t Result withOffsetElem (WithOffset os xs) = pure $ - Array.all (\o -> TA.elem (unsafePartial (TA.unsafeAt xs o)) Nothing xs) os + Array.all (\o -> TA.elem (unsafePartial $ unsafePerformEffect $ TA.unsafeAt xs o) Nothing xs) os "All doesn't have an elem of itself" @@ -292,14 +296,16 @@ findIndexImpliesAtTests :: Ref Int -> Effect Unit findIndexImpliesAtTests count = overAll count findIndexImpliesAt where findIndexImpliesAt :: forall a b t. TestableArrayF a b D0 t Result - findIndexImpliesAt (WithOffset _ xs) = - let pred x o = x /= zero + findIndexImpliesAt (WithOffset _ xs) = do + let pred x _ = x /= zero mo = TA.findIndex pred xs - in pure case mo of - Nothing -> Success - Just o -> case TA.at xs o of - Nothing -> Failed "No value at found index" - Just x -> pred x o "Find index implies at" + 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" @@ -307,24 +313,30 @@ indexOfImpliesAtTests :: Ref Int -> Effect Unit indexOfImpliesAtTests count = overAll count indexOfImpliesAt where indexOfImpliesAt :: forall a b t. TestableArrayF a b D0 t Result - indexOfImpliesAt (WithOffset _ xs) = pure - case TA.at xs 0 of - Nothing -> Success + indexOfImpliesAt (WithOffset _ xs) = do + e <- TA.at xs 0 + case e of + Nothing -> pure Success Just y -> case TA.indexOf y Nothing xs of - Nothing -> Failed "no index of" - Just o -> TA.at xs o === Just y + 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 count lastIndexOfImpliesAt where lastIndexOfImpliesAt :: forall a b t. TestableArrayF a b D0 t Result - lastIndexOfImpliesAt (WithOffset _ xs) = pure - case TA.at xs 0 of - Nothing -> Success + lastIndexOfImpliesAt (WithOffset _ xs) = do + e <- TA.at xs 0 + case e of + Nothing -> pure Success Just y -> case TA.lastIndexOf y Nothing xs of - Nothing -> Failed "no lastIndex of" - Just o -> TA.at xs o === Just y + Nothing -> pure $ Failed "no lastIndex of" + Just o -> do + e' <- TA.at xs o + pure $ e' === Just y foldrConsIsToArrayTests :: Ref Int -> Effect Unit @@ -569,7 +581,8 @@ modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOrigi modifyingOriginalDoesntMutateSlicePart (WithOffset os xs) = do axs <- TA.toArray =<< TA.slice xs (Just (Tuple (Vec.head os) Nothing)) let o = Vec.head os - if Array.all (eq zero) axs || TA.at xs o == Just zero + e <- TA.at xs o + if Array.all (eq zero) axs || e == Just zero then pure Success else do zsSub <- TA.slice xs (Just (Tuple o Nothing)) @@ -586,7 +599,8 @@ modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOrig modifyingOriginalDoesntMutateSlicePart2 (WithOffset os xs) = do axs <- TA.toArray =<< TA.slice xs (Just (Tuple (Vec.head os) Nothing)) let o = Vec.head os - if Array.all (eq zero) axs || TA.at xs o == Just zero + e <- TA.at xs o + if Array.all (eq zero) axs || e == Just zero then pure Success else do zsSub <- TA.slice xs (Just (Tuple 0 (Just o))) From 8c59b1d6cff29323ef3ca3ef38fff736f77d1dbf Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Mon, 28 Jan 2019 23:46:25 +0100 Subject: [PATCH 11/79] Changed fill/slice/subArray to be consistent with Array/Node.Buffer --- src/Data/ArrayBuffer/ArrayBuffer.js | 4 +- src/Data/ArrayBuffer/ArrayBuffer.purs | 13 +-- src/Data/ArrayBuffer/Typed.js | 9 +-- src/Data/ArrayBuffer/Typed.purs | 31 +++---- test/Properties/TypedArray.purs | 111 +++++++++++++++++--------- 5 files changed, 94 insertions(+), 74 deletions(-) diff --git a/src/Data/ArrayBuffer/ArrayBuffer.js b/src/Data/ArrayBuffer/ArrayBuffer.js index 656d576..b341921 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.js +++ b/src/Data/ArrayBuffer/ArrayBuffer.js @@ -10,6 +10,6 @@ exports.byteLength = function byteLength (a) { return a.byteLength; }; -exports.sliceImpl = function sliceImpl (a, ms, me) { - return me === null ? (ms === null ? a.slice() : a.slice(ms)) : a.slice(ms,me); +exports.sliceImpl = function sliceImpl (a, s, e) { + return a.slice(s, e); }; diff --git a/src/Data/ArrayBuffer/ArrayBuffer.purs b/src/Data/ArrayBuffer/ArrayBuffer.purs index 4bd11a0..6dd5b4e 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.purs +++ b/src/Data/ArrayBuffer/ArrayBuffer.purs @@ -9,9 +9,6 @@ module Data.ArrayBuffer.ArrayBuffer import Data.ArrayBuffer.Types (ArrayBuffer, ByteOffset, ByteLength) import Data.Function.Uncurried (Fn3, runFn3) -import Data.Maybe (Maybe(..)) -import Data.Nullable (Nullable, notNull, null) -import Data.Tuple (Tuple(..)) import Effect (Effect) import Effect.Uncurried (EffectFn1, runEffectFn1) @@ -26,12 +23,8 @@ empty l = runEffectFn1 emptyImpl l -- | Represents the length of an `ArrayBuffer` in bytes. foreign import byteLength :: ArrayBuffer -> ByteLength -foreign import sliceImpl :: Fn3 ArrayBuffer (Nullable ByteOffset) (Nullable ByteOffset) ArrayBuffer +foreign import sliceImpl :: Fn3 ArrayBuffer ByteOffset ByteOffset ArrayBuffer -- | Returns a new `ArrayBuffer` whose contents are a copy of this ArrayBuffer's bytes from begin, inclusive, up to end, exclusive. -slice :: ArrayBuffer -> Maybe (Tuple ByteOffset (Maybe ByteOffset)) -> ArrayBuffer -slice a mz = case mz of - Nothing -> runFn3 sliceImpl a null null - Just (Tuple s me) -> case me of - Nothing -> runFn3 sliceImpl a (notNull s) null - Just e -> runFn3 sliceImpl a (notNull s) (notNull e) +slice :: ByteOffset -> ByteOffset -> ArrayBuffer -> ArrayBuffer +slice s e a = runFn3 sliceImpl a s e diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index fb56808..3f52aa7 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -145,18 +145,17 @@ exports.setImpl = function setImpl (a, off, b) { }; -exports.sliceImpl = function sliceImpl (a,ms,me) { - return me === null ? (ms === null ? a.slice() : a.slice(ms)) : a.slice(ms,me); +exports.sliceImpl = function sliceImpl (a, s, e) { + return a.slice(s,e); }; - exports.sortImpl = function sortImpl (a) { a.sort(); }; -exports.subArrayImpl = function subArrayImpl (a,ms,me) { - return me === null ? (ms === null ? a.subarray() : a.subarray(ms)) : a.subarray(ms,me); +exports.subArrayImpl = function subArrayImpl (a, s, e) { + return a.subarray(s, e); }; diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 04720e2..04d724b 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -3,7 +3,7 @@ module Data.ArrayBuffer.Typed ( polyFill - , Offset, Length, Range + , Offset, Length , buffer, byteOffset, byteLength, length , class TypedArray , create, whole, remainder, part, empty, fromArray @@ -28,7 +28,6 @@ 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.Tuple (Tuple(..)) import Data.Typelevel.Num (class Nat, toInt') import Data.UInt (UInt) import Effect (Effect) @@ -75,7 +74,7 @@ foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N foreign import everyImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean foreign import someImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean -foreign import fillImpl :: forall a b. EffectFn4 (ArrayView a) b (Nullable Offset) (Nullable Offset) Unit +foreign import fillImpl :: forall a b. EffectFn4 (ArrayView a) b Offset Offset Unit foreign import mapImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset b) (ArrayView a) foreign import forEachImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Unit) Unit @@ -96,10 +95,6 @@ type Offset = Int -- | Value-oriented array length type Length = Int --- | Represents a range of indices, where if omitted, it represents the whole span. --- | If only the second argument is omitted, then it represents the remainder of the span after the first index. -type Range = Maybe (Tuple Offset (Maybe Offset)) - -- TODO use purescript-quotient -- | Typeclass that associates a measured user-level type with a typed array. @@ -184,10 +179,8 @@ fromArray :: forall a t. TypedArray a t => Array t -> Effect (ArrayView a) fromArray a = runEffectFn3 create a null null -- | Fill the array with a value -fill :: forall a t. TypedArray a t => ArrayView a -> t -> Range -> Effect Unit -fill a x mz = case mz of - Nothing -> runEffectFn4 fillImpl a x null null - Just (Tuple s me) -> runEffectFn4 fillImpl a x (notNull s) (toNullable me) +fill :: forall a t. TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit +fill x s e a = runEffectFn4 fillImpl a x s e -- | Stores multiple values into the typed array set :: forall a t. TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean @@ -367,13 +360,11 @@ setTyped = setInternal length -- | Copy the entire contents of the typed array into a new buffer. -foreign import sliceImpl :: forall a. EffectFn3 (ArrayView a) (Nullable Offset) (Nullable Offset) (ArrayView a) +foreign import sliceImpl :: forall a. EffectFn3 (ArrayView a) Offset Offset (ArrayView a) -- | Copy part of the contents of a typed array into a new buffer, between some start and end indices. -slice :: forall a. ArrayView a -> Range -> Effect (ArrayView a) -slice a mz = case mz of - Nothing -> runEffectFn3 sliceImpl a null null - Just (Tuple s me) -> runEffectFn3 sliceImpl a (notNull s) (toNullable me) +slice :: forall a. Offset -> Offset -> ArrayView a -> Effect (ArrayView a) +slice s e a = runEffectFn3 sliceImpl a s e foreign import sortImpl :: forall a. EffectFn1 (ArrayView a) Unit @@ -382,7 +373,7 @@ sort :: forall a. ArrayView a -> Effect Unit sort a = runEffectFn1 sortImpl a -foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) (Nullable Offset) (Nullable Offset) (ArrayView a) +foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) Offset Offset (ArrayView a) -- | Returns a new typed array view of the same buffer, beginning at the index and ending at the second. -- | @@ -391,10 +382,8 @@ foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) (Nullable Offset) (Nu -- | mutable replica of the original array - the sub-array reference reflects mutations to the original array. -- | However, when the sub-array is is actually a smaller contiguous portion of the array, then it behaves -- | purely, because JavaScript interally calls `Data.ArrayBuffer.ArrayBuffer.slice`. -subArray :: forall a. ArrayView a -> Range -> ArrayView a -subArray a mz = case mz of - Nothing -> runFn3 subArrayImpl a null null - Just (Tuple s me) -> runFn3 subArrayImpl a (notNull s) (toNullable me) +subArray :: forall a. Offset -> Offset -> ArrayView a -> ArrayView a +subArray s e a = runFn3 subArrayImpl a s e -- | 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. foreign import toString :: forall a. ArrayView a -> String diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index 782fe9b..af84bc2 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -10,10 +10,9 @@ import Data.ArrayBuffer.Typed as TA import Data.ArrayBuffer.Typed.Gen (WithOffset(..), genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8, genWithOffset) import Data.ArrayBuffer.Types (ArrayView, Float32Array, Float64Array, Int16Array, Int32Array, Int8Array, Uint16Array, Uint8Array, Uint8ClampedArray, Uint32Array) import Data.ArrayBuffer.ValueMapping (class BytesPerValue) -import Data.Maybe (Maybe(..)) -import Data.Tuple (Tuple(..)) -import Data.Typelevel.Num (class Nat, D0, D1, D5, toInt') -import Data.Vec (head) as Vec +import Data.Maybe (Maybe(..), fromMaybe) +import Data.Typelevel.Num (class Nat, D0, D1, D2, D5, d0, d1, toInt') +import Data.Vec (head, index) as Vec import Effect (Effect) import Effect.Console (log) import Effect.Ref (Ref) @@ -28,8 +27,12 @@ import Type.Proxy (Proxy(..)) typedArrayTests :: Ref Int -> Effect Unit typedArrayTests count = do + log " - subarrayBehavesLikeArraySlice" + subarrayBehavesLikeArraySliceTests count + log " - sliceBehavesLikeArraySlice" + sliceBehavesLikeArraySliceTests count log " - partBehavesLikeTakeDrop" - partBehavesLikeTakeDrop count + partBehavesLikeTakeDropTests count log " - byteLength x / bytesPerValue === length x" byteLengthDivBytesPerValueTests count log " - fromArray (toArray x) === x" @@ -147,8 +150,32 @@ overAll count f = overAll' 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 -partBehavesLikeTakeDrop :: Ref Int -> Effect Unit -partBehavesLikeTakeDrop count = overAll count f +subarrayBehavesLikeArraySliceTests :: Ref Int -> Effect Unit +subarrayBehavesLikeArraySliceTests count = overAll count f + where + f :: forall a b t. TestableArrayF a b D2 t Result + f (WithOffset os xs) = do + let s = os `Vec.index` d0 + e = os `Vec.index` d1 + 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 count f + where + f :: forall a b t. TestableArrayF a b D2 t Result + f (WithOffset os xs) = do + let s = os `Vec.index` d0 + e = os `Vec.index` d1 + 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 count f where f :: forall a b t. TestableArrayF a b D0 t Result f (WithOffset _ xs) = do @@ -183,10 +210,9 @@ allAreFilledTests count = overAll count allAreFilled allAreFilled :: forall a b t. TestableArrayF a b D0 t Result allAreFilled (WithOffset _ xs) = do e <- TA.at xs 0 - let x = case e of - Nothing -> zero - Just y -> y - TA.fill xs x Nothing + let x = fromMaybe zero e + l = TA.length xs + TA.fill x 0 l xs let b = TA.all (_ == x) xs pure (b "All aren't the filled value") @@ -440,7 +466,8 @@ setTypedOfSubArrayIsIdentityTests count = overAll count setTypedOfSubArrayIsIden setTypedOfSubArrayIsIdentity :: forall a b t. TestableArrayF a b D0 t Result setTypedOfSubArrayIsIdentity (WithOffset _ xs) = do ys <- TA.toArray xs - let zsSub = TA.subArray xs Nothing + let l = TA.length xs + zsSub = TA.subArray 0 l xs _ <- TA.setTyped xs Nothing zsSub zs <- TA.toArray xs pure $ zs === ys @@ -455,9 +482,10 @@ modifyingOriginalMutatesSubArrayTests count = overAll count modifyingOriginalMut if Array.all (eq zero) axs then pure Success else do - let zsSub = TA.subArray xs Nothing + let l = TA.length xs + zsSub = TA.subArray 0 l xs zs <- TA.toArray zsSub - TA.fill xs zero Nothing + TA.fill zero 0 l xs ys <- TA.toArray zsSub pure $ zs /== ys @@ -471,9 +499,10 @@ modifyingSubArrayMutatesOriginalTests count = overAll count modifyingOriginalMut if Array.all (eq zero) axs then pure Success else do - let zsSub = TA.subArray xs Nothing + let l = TA.length xs + zsSub = TA.subArray 0 l xs zs <- TA.toArray xs - TA.fill zsSub zero Nothing + TA.fill zero 0 l zsSub ys <- TA.toArray xs pure $ zs /== ys @@ -487,9 +516,10 @@ modifyingOriginalMutatesSubArrayZeroTests count = overAll count modifyingOrigina if Array.all (eq zero) axs then pure Success else do - let zsSub = TA.subArray xs (Just (Tuple 0 Nothing)) + let l = TA.length xs + zsSub = TA.subArray 0 l xs zs <- TA.toArray zsSub - TA.fill xs zero Nothing + TA.fill zero 0 l xs ys <- TA.toArray zsSub pure $ zs /== ys @@ -503,9 +533,10 @@ modifyingSubArrayMutatesOriginalZeroTests count = overAll count modifyingSubArra if Array.all (eq zero) axs then pure Success else do - let zsSub = TA.subArray xs (Just (Tuple 0 Nothing)) + let l = TA.length xs + zsSub = TA.subArray 0 l xs zs <- TA.toArray xs - TA.fill zsSub zero Nothing + TA.fill zero 0 l zsSub ys <- TA.toArray xs pure $ zs /== ys @@ -519,9 +550,10 @@ modifyingOriginalMutatesSubArrayAllTests count = overAll count modifyingOriginal if Array.all (eq zero) axs then pure Success else do - let zsSub = TA.subArray xs (Just (Tuple 0 (Just (TA.length xs)))) + let l = TA.length xs + zsSub = TA.subArray 0 l xs zs <- TA.toArray zsSub - TA.fill xs zero Nothing + TA.fill zero 0 l xs ys <- TA.toArray zsSub pure $ zs /== ys @@ -535,9 +567,10 @@ modifyingSubArrayMutatesOriginalAllTests count = overAll count modifyingSubArray if Array.all (eq zero) axs then pure Success else do - let zsSub = TA.subArray xs (Just (Tuple 0 (Just (TA.length xs)))) + let l = TA.length xs + zsSub = TA.subArray 0 l xs zs <- TA.toArray xs - TA.fill zsSub zero Nothing + TA.fill zero 0 l zsSub ys <- TA.toArray xs pure $ zs /== ys @@ -548,12 +581,13 @@ modifyingOriginalMutatesSubArrayPartTests count = overAll count modifyingOrigina modifyingOriginalMutatesSubArrayPart :: forall a b t. TestableArrayF a b D1 t Result modifyingOriginalMutatesSubArrayPart (WithOffset os xs) = do let o = Vec.head os - zsSub = TA.subArray xs (Just (Tuple o Nothing)) + 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 xs zero Nothing + TA.fill zero 0 l xs ys <- TA.toArray zsSub pure $ zs /== ys @@ -567,9 +601,10 @@ modifyingOriginalDoesntMutateSliceTests count = overAll count modifyingOriginalD if Array.all (eq zero) axs then pure Success else do - zsSub <- TA.slice xs Nothing + let l = TA.length xs + zsSub <- TA.slice 0 l xs zs <- TA.toArray zsSub - TA.fill xs zero Nothing + TA.fill zero 0 l xs ys <- TA.toArray zsSub pure $ zs === ys @@ -579,15 +614,16 @@ modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOrigi where modifyingOriginalDoesntMutateSlicePart :: forall a b t. TestableArrayF a b D1 t Result modifyingOriginalDoesntMutateSlicePart (WithOffset os xs) = do - axs <- TA.toArray =<< TA.slice xs (Just (Tuple (Vec.head os) Nothing)) + let l = TA.length xs + axs <- TA.toArray =<< TA.slice 0 l xs let o = Vec.head os e <- TA.at xs o if Array.all (eq zero) axs || e == Just zero then pure Success else do - zsSub <- TA.slice xs (Just (Tuple o Nothing)) + zsSub <- TA.slice o l xs zs <- TA.toArray zsSub - TA.fill xs zero Nothing + TA.fill zero 0 l xs ys <- TA.toArray zsSub pure $ zs === ys @@ -597,15 +633,16 @@ modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOrig where modifyingOriginalDoesntMutateSlicePart2 :: forall a b t. TestableArrayF a b D1 t Result modifyingOriginalDoesntMutateSlicePart2 (WithOffset os xs) = do - axs <- TA.toArray =<< TA.slice xs (Just (Tuple (Vec.head os) Nothing)) let o = Vec.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 xs (Just (Tuple 0 (Just o))) + zsSub <- TA.slice o l xs zs <- TA.toArray zsSub - TA.fill xs zero Nothing + TA.fill zero 0 l xs ys <- TA.toArray zsSub pure $ zs === ys @@ -627,7 +664,8 @@ copyWithinIsSliceTests count = overAll count copyWithinIsSlice copyWithinIsSlice :: forall a b t. TestableArrayF a b D1 t Result copyWithinIsSlice (WithOffset os xs) = do let o = Vec.head os - ys <- TA.toArray =<< TA.slice xs (Just (Tuple o Nothing)) + 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 @@ -642,7 +680,8 @@ copyWithinViaSetTypedTests count = overAll count copyWithinViaSetTyped let o = Vec.head os txs <- TA.toArray xs xs' <- TA.fromArray txs :: Effect (ArrayView a) - ys <- TA.slice xs' (Just (Tuple o Nothing)) + 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 From 3cfed24f76b26d528dda3115f5e4db045cc52b40 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Mon, 28 Jan 2019 23:53:45 +0100 Subject: [PATCH 12/79] Remove unused dependency --- bower.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bower.json b/bower.json index f05f8d1..64e11d0 100644 --- a/bower.json +++ b/bower.json @@ -18,7 +18,6 @@ "purescript-effect": "^2.0.0", "purescript-nullable": "^4.1.0", "purescript-typelevel": "^4.0.0", - "purescript-parseint": "^1.1.0", "purescript-uint": "^5.1.0", "purescript-sized-vectors": "^3.1.0", "purescript-float32": "^0.0.1" From d1c5a2bb7df6015ce5cedaff9d2b48aab2e540c8 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Mon, 28 Jan 2019 23:57:19 +0100 Subject: [PATCH 13/79] Removed note about subArray, the behaviour seems correct --- src/Data/ArrayBuffer/Typed.purs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 04d724b..f9981f6 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -376,12 +376,6 @@ sort a = runEffectFn1 sortImpl a foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) Offset Offset (ArrayView a) -- | Returns a new typed array view of the same buffer, beginning at the index and ending at the second. --- | --- | **Note**: there is really peculiar behavior with `subArray` - if the first offset argument is omitted, or --- | is `0`, and likewise if the second argument is the length of the array, then the "sub-array" is actually a --- | mutable replica of the original array - the sub-array reference reflects mutations to the original array. --- | However, when the sub-array is is actually a smaller contiguous portion of the array, then it behaves --- | purely, because JavaScript interally calls `Data.ArrayBuffer.ArrayBuffer.slice`. subArray :: forall a. Offset -> Offset -> ArrayView a -> ArrayView a subArray s e a = runFn3 subArrayImpl a s e From 5e7ac0dc493560494ecc20a5eff7a35dca004430 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 29 Jan 2019 22:25:17 +0100 Subject: [PATCH 14/79] Use Nullable --- src/Data/ArrayBuffer/DataView.js | 4 ++-- src/Data/ArrayBuffer/DataView.purs | 22 +++++++++------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Data/ArrayBuffer/DataView.js b/src/Data/ArrayBuffer/DataView.js index 44ad1b9..6bfee81 100644 --- a/src/Data/ArrayBuffer/DataView.js +++ b/src/Data/ArrayBuffer/DataView.js @@ -29,8 +29,8 @@ exports.byteLength = function byteLength (v) { exports.getterImpl = function getterImpl (data, v, o) { return ((o + data.bytesPerValue) >>> 0) <= v.byteLength - ? data.just (v[data.functionName].call(v,o,data.littleEndian)) - : data.nothing; + ? v[data.functionName].call(v,o,data.littleEndian) + : null; }; exports.setterImpl = function setterImpl (data, v, o, n) { diff --git a/src/Data/ArrayBuffer/DataView.purs b/src/Data/ArrayBuffer/DataView.purs index cffe5ec..001f37b 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -48,17 +48,17 @@ module Data.ArrayBuffer.DataView , whole ) where -import Prelude (class Eq, (==), (<>)) - import Data.ArrayBuffer.Types (ArrayBuffer, ByteLength, ByteOffset, DataView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, Uint8Clamped, kind ArrayViewType) import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerValue) -import Data.Maybe (Maybe(..)) +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 Data.Float32 (Float32) as F -import Data.Symbol (SProxy (..), class IsSymbol, reflectSymbol) import Effect (Effect) import Effect.Uncurried (EffectFn2, EffectFn3, EffectFn4, runEffectFn2, runEffectFn3, runEffectFn4) +import Prelude (class Eq, (<$>), (<>), (==)) import Type.Proxy (Proxy(..)) @@ -122,12 +122,10 @@ instance showArrayViewTypeViewFloat32 :: ShowArrayViewType Float32 "Float32" instance showArrayViewTypeViewFloat64 :: ShowArrayViewType Float64 "Float64" foreign import getterImpl :: forall t - . EffectFn3 { just :: t -> Maybe t - , nothing :: Maybe t - , functionName :: String + . EffectFn3 { functionName :: String , littleEndian :: Boolean , bytesPerValue :: ByteLength - } DataView ByteOffset (Maybe t) + } DataView ByteOffset (Nullable t) getter :: forall t. { functionName :: String @@ -135,11 +133,9 @@ getter :: forall t. , littleEndian :: Boolean } -> DataView -> ByteOffset -> Effect (Maybe t) -getter data' d o = +getter data' d o = toMaybe <$> runEffectFn3 getterImpl - { just: Just - , nothing: Nothing - , functionName: data'.functionName + { functionName: data'.functionName , littleEndian: data'.littleEndian , bytesPerValue: data'.bytesPerValue } d o From d7771c251299a8b9fdfb58374d95c681babe01ed Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 29 Jan 2019 22:36:03 +0100 Subject: [PATCH 15/79] Effectful finds --- src/Data/ArrayBuffer/Typed.purs | 28 ++++++++++++------------- test/Properties/TypedArray.purs | 36 ++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index f9981f6..dd58d3e 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -84,10 +84,10 @@ foreign import reduceImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c foreign import reduce1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Offset b) b foreign import reduceRightImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Offset c) c c foreign import reduceRight1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Offset b) b -foreign import findImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) (Nullable b) -foreign import findIndexImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) (Nullable Offset) -foreign import indexOfImpl :: forall a b. Fn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) -foreign import lastIndexOfImpl :: forall a b. Fn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) +foreign import findImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) (Nullable b) +foreign import findIndexImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) (Nullable Offset) +foreign import indexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) +foreign import lastIndexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) -- | Value-oriented array offset @@ -281,26 +281,26 @@ foldr1M :: forall a t. TypedArray a t => (t -> t -> Offset -> Effect t) -> Array foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) -- | Returns the first value satisfying the predicate -find :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Maybe t +find :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (Maybe t) find = findWithIndex' <<< ap1 -findWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Maybe t +findWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect (Maybe t) findWithIndex = findWithIndex' <<< flip -findWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Maybe t -findWithIndex' f a = toMaybe (runFn2 findImpl a (mkFn2 f)) +findWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (Maybe t) +findWithIndex' f a = toMaybe <$> runEffectFn2 findImpl a (mkFn2 f) -- | Returns the first index of the value satisfying the predicate -findIndex :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Maybe Offset -findIndex f a = toMaybe (runFn2 findIndexImpl a (mkFn2 f)) +findIndex :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (Maybe Offset) +findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkFn2 f) -- | Returns the first index of the element, if it exists, from the left -indexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Maybe Offset -indexOf x mo a = toMaybe (runFn3 indexOfImpl a x (toNullable mo)) +indexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset) +indexOf x mo a = toMaybe <$> runEffectFn3 indexOfImpl a x (toNullable mo) -- | Returns the first index of the element, if it exists, from the right -lastIndexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Maybe Offset -lastIndexOf x mo a = toMaybe (runFn3 lastIndexOfImpl a x (toNullable mo)) +lastIndexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset) +lastIndexOf x mo a = toMaybe <$> runEffectFn3 lastIndexOfImpl a x (toNullable mo) foldl :: forall a b t. TypedArray a t => (b -> t -> b) -> b -> ArrayView a -> b foldl f = foldlWithIndex' (\a x _ -> f a x) diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index af84bc2..6faf4f9 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -305,16 +305,16 @@ anyImpliesFindTests :: Ref Int -> Effect Unit anyImpliesFindTests count = overAll count anyImpliesFind where anyImpliesFind :: forall a b t. TestableArrayF a b D0 t Result - anyImpliesFind (WithOffset _ xs) = + anyImpliesFind (WithOffset _ xs) = do let pred x = x /= zero p = TA.any pred xs "All don't satisfy the predicate" - q = - case TA.find pred xs of + 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" - in pure $ p ==> q + pure $ p ==> q -- | Should work with any arbitrary predicate, but we can't generate them @@ -324,7 +324,7 @@ findIndexImpliesAtTests count = overAll count findIndexImpliesAt findIndexImpliesAt :: forall a b t. TestableArrayF a b D0 t Result findIndexImpliesAt (WithOffset _ xs) = do let pred x _ = x /= zero - mo = TA.findIndex pred xs + mo <- TA.findIndex pred xs case mo of Nothing -> pure Success Just o -> do @@ -338,16 +338,18 @@ findIndexImpliesAtTests count = overAll count findIndexImpliesAt indexOfImpliesAtTests :: Ref Int -> Effect Unit indexOfImpliesAtTests count = overAll count indexOfImpliesAt where - indexOfImpliesAt :: forall a b t. TestableArrayF a b D0 t Result + indexOfImpliesAt :: forall a b t. TestableArrayF a b D1 t Result indexOfImpliesAt (WithOffset _ xs) = do e <- TA.at xs 0 case e of Nothing -> pure Success - Just y -> case TA.indexOf y Nothing xs of - Nothing -> pure $ Failed "no index of" - Just o -> do - e' <- TA.at xs o - pure $ e' === Just y + 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 @@ -358,11 +360,13 @@ lastIndexOfImpliesAtTests count = overAll count lastIndexOfImpliesAt e <- TA.at xs 0 case e of Nothing -> pure Success - Just y -> case TA.lastIndexOf y Nothing xs of - Nothing -> pure $ Failed "no lastIndex of" - Just o -> do - e' <- TA.at xs o - pure $ e' === Just y + 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 From e1aead144a3c022f1822d10742eb6777044c71d6 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 29 Jan 2019 22:46:14 +0100 Subject: [PATCH 16/79] Effectful folds --- src/Data/ArrayBuffer/Typed.purs | 28 ++++++++++++++-------------- test/Properties/TypedArray.purs | 6 ++++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index dd58d3e..8332e41 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -302,35 +302,35 @@ indexOf x mo a = toMaybe <$> runEffectFn3 indexOfImpl a x (toNullable mo) lastIndexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset) lastIndexOf x mo a = toMaybe <$> runEffectFn3 lastIndexOfImpl a x (toNullable mo) -foldl :: forall a b t. TypedArray a t => (b -> t -> b) -> b -> ArrayView a -> b +foldl :: forall a b t. TypedArray a t => (b -> t -> b) -> b -> ArrayView a -> Effect b foldl f = foldlWithIndex' (\a x _ -> f a x) -foldlWithIndex :: forall a b t. TypedArray a t => (Offset -> b -> t -> b) -> b -> ArrayView a -> b +foldlWithIndex :: forall a b t. TypedArray a t => (Offset -> b -> t -> b) -> b -> ArrayView a -> Effect b foldlWithIndex f = foldlWithIndex' (\a x o -> f o a x) -foldlWithIndex' :: forall a b t. TypedArray a t => (b -> t -> Offset -> b) -> b -> ArrayView a -> b -foldlWithIndex' f i = unsafePerformEffect <<< foldlM (\a x o -> pure (f a x o)) i +foldlWithIndex' :: forall a b t. TypedArray a t => (b -> t -> Offset -> b) -> b -> ArrayView a -> Effect b +foldlWithIndex' f i = foldlM (\a x o -> pure (f a x o)) i -foldr :: forall a b t. TypedArray a t => (t -> b -> b) -> b -> ArrayView a -> b +foldr :: forall a b t. TypedArray a t => (t -> b -> b) -> b -> ArrayView a -> Effect b foldr f = foldrWithIndex' (\a x _ -> f a x) -foldrWithIndex :: forall a b t. TypedArray a t => (Offset -> t -> b -> b) -> b -> ArrayView a -> b +foldrWithIndex :: forall a b t. TypedArray a t => (Offset -> t -> b -> b) -> b -> ArrayView a -> Effect b foldrWithIndex f = foldrWithIndex' (\a x o -> f o a x) -foldrWithIndex' :: forall a b t. TypedArray a t => (t -> b -> Offset -> b) -> b -> ArrayView a -> b -foldrWithIndex' f i = unsafePerformEffect <<< foldrM (\x a o -> pure (f x a o)) i +foldrWithIndex' :: forall a b t. TypedArray a t => (t -> b -> Offset -> b) -> b -> ArrayView a -> Effect b +foldrWithIndex' f i = foldrM (\x a o -> pure (f x a o)) i -foldl1 :: forall a t. TypedArray a t => (t -> t -> t) -> ArrayView a -> t +foldl1 :: forall a t. TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t foldl1 f = foldl1WithIndex (\_ a x -> f a x) -foldl1WithIndex :: forall a t. TypedArray a t => (Offset -> t -> t -> t) -> ArrayView a -> t -foldl1WithIndex f = unsafePerformEffect <<< foldl1M (\acc x o -> pure (f o acc x)) +foldl1WithIndex :: forall a t. TypedArray a t => (Offset -> t -> t -> t) -> ArrayView a -> Effect t +foldl1WithIndex f = foldl1M (\acc x o -> pure (f o acc x)) -foldr1 :: forall a t. TypedArray a t => (t -> t -> t) -> ArrayView a -> t +foldr1 :: forall a t. TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t foldr1 f = foldr1WithIndex (\_ a x -> f a x) -foldr1WithIndex :: forall a t. TypedArray a t => (Offset -> t -> t -> t) -> ArrayView a -> t -foldr1WithIndex f = unsafePerformEffect <<< foldr1M (\x a o -> pure (f o x a)) +foldr1WithIndex :: forall a t. TypedArray a t => (Offset -> t -> t -> t) -> ArrayView a -> Effect t +foldr1WithIndex f = foldr1M (\x a o -> pure (f o x a)) foreign import copyWithinImpl :: forall a. EffectFn4 (ArrayView a) Offset Offset (Nullable Offset) Unit diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index 6faf4f9..49517d3 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -375,7 +375,8 @@ foldrConsIsToArrayTests count = overAll count foldrConsIsToArray foldrConsIsToArray :: forall a b t. TestableArrayF a b D0 t Result foldrConsIsToArray (WithOffset _ xs) = do axs <- TA.toArray xs - pure $ TA.foldr Array.cons [] xs === axs + rxs <- TA.foldr Array.cons [] xs + pure $ rxs === axs foldlSnocIsToArrayTests :: Ref Int -> Effect Unit @@ -384,7 +385,8 @@ foldlSnocIsToArrayTests count = overAll count foldlSnocIsToArray foldlSnocIsToArray :: forall a b t. TestableArrayF a b D0 t Result foldlSnocIsToArray (WithOffset _ xs) = do axs <- TA.toArray xs - pure $ TA.foldl Array.snoc [] xs === axs + rxs <- TA.foldl Array.snoc [] xs + pure $ rxs === axs mapIdentityIsIdentityTests :: Ref Int -> Effect Unit From aa126bcc39e5b0bbb1e44b3281c73960b03533d9 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 29 Jan 2019 23:07:26 +0100 Subject: [PATCH 17/79] Made some filters/reducers effectful --- src/Data/ArrayBuffer/Typed.purs | 36 ++++++++++++++--------------- test/Properties/TypedArray.purs | 41 +++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 8332e41..a0a4ac1 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -71,15 +71,15 @@ foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N -- ---- -foreign import everyImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean -foreign import someImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean +foreign import everyImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean +foreign import someImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean foreign import fillImpl :: forall a b. EffectFn4 (ArrayView a) b Offset Offset Unit foreign import mapImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset b) (ArrayView a) foreign import forEachImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Unit) Unit -foreign import filterImpl :: forall a b. Fn2 (ArrayView a) (Fn2 b Offset Boolean) (ArrayView a) -foreign import includesImpl :: forall a b. Fn3 (ArrayView a) b (Nullable Offset) Boolean +foreign import filterImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) (ArrayView a) +foreign import includesImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Offset) Boolean foreign import reduceImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Offset c) c c foreign import reduce1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Offset b) b foreign import reduceRightImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Offset c) c c @@ -227,38 +227,38 @@ traverseWithIndex_' :: forall a t. TypedArray a t => (t -> Offset -> Effect Unit traverseWithIndex_' f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) -- | Test a predicate to pass on all values -all :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Boolean +all :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean all = every <<< ap1 -allWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Boolean +allWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect Boolean allWithIndex = every <<< flip -every :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Boolean -every p a = runFn2 everyImpl a (mkFn2 p) +every :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean +every p a = runEffectFn2 everyImpl a (mkFn2 p) -- | Test a predicate to pass on any value -any :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Boolean +any :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean any = some <<< ap1 -anyWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Boolean +anyWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect Boolean anyWithIndex = some <<< flip -some :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Boolean -some p a = runFn2 someImpl a (mkFn2 p) +some :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean +some p a = runEffectFn2 someImpl a (mkFn2 p) -- | Returns a new typed array with all values that pass the predicate -filter :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> ArrayView a +filter :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (ArrayView a) filter = filterWithIndex' <<< ap1 -filterWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> ArrayView a +filterWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect (ArrayView a) filterWithIndex = filterWithIndex' <<< flip -filterWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> ArrayView a -filterWithIndex' p a = runFn2 filterImpl a (mkFn2 p) +filterWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (ArrayView a) +filterWithIndex' p a = runEffectFn2 filterImpl a (mkFn2 p) -- | Tests if a value is an element of the typed array -elem :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Boolean -elem x mo a = runFn3 includesImpl a x (toNullable mo) +elem :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect Boolean +elem x mo a = runEffectFn3 includesImpl a x (toNullable mo) -- | Fetch element at index. unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Offset -> Effect t diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index 49517d3..aee4451 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -213,7 +213,7 @@ allAreFilledTests count = overAll count allAreFilled let x = fromMaybe zero e l = TA.length xs TA.fill x 0 l xs - let b = TA.all (_ == x) xs + b <- TA.all (_ == x) xs pure (b "All aren't the filled value") @@ -237,11 +237,13 @@ allImpliesAnyTests :: Ref Int -> Effect Unit allImpliesAnyTests count = overAll count allImpliesAny where allImpliesAny :: forall a b t. TestableArrayF a b D0 t Result - allImpliesAny (WithOffset _ xs) = + allImpliesAny (WithOffset _ xs) = do let pred x = x /= zero - all' = TA.all pred xs "All don't satisfy the predicate" - any' = TA.any pred xs "None satisfy the predicate" - in pure $ (TA.length xs === zero) |=| all' ==> any' + 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' -- | Should work with any arbitrary predicate, but we can't generate them @@ -249,11 +251,11 @@ filterImpliesAllTests :: Ref Int -> Effect Unit filterImpliesAllTests count = overAll count filterImpliesAll where filterImpliesAll :: forall a b t. TestableArrayF a b D0 t Result - filterImpliesAll (WithOffset _ xs) = + filterImpliesAll (WithOffset _ xs) = do let pred x = x /= zero - ys = TA.filter pred xs - all' = TA.all pred ys - in pure $ all' "Filter doesn't imply all" + 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 @@ -263,8 +265,8 @@ filterIsTotalTests count = overAll count filterIsTotal filterIsTotal :: forall a b t. TestableArrayF a b D0 t Result filterIsTotal (WithOffset _ xs) = do let pred x = x /= zero - ys = TA.filter pred xs - zs = TA.filter (not pred) ys + ys <- TA.filter pred xs + zs <- TA.filter (not pred) ys azs <- TA.toArray zs pure $ azs === [] @@ -276,8 +278,8 @@ filterIsIdempotentTests count = overAll count filterIsIdempotent filterIsIdempotent :: forall a b t. TestableArrayF a b D0 t Result filterIsIdempotent (WithOffset _ xs) = do let pred x = x /= zero - ys = TA.filter pred xs - zs = TA.filter pred ys + ys <- TA.filter pred xs + zs <- TA.filter pred ys azs <- TA.toArray zs ays <- TA.toArray ys pure $ azs === ays @@ -295,9 +297,13 @@ withOffsetElemTests :: Ref Int -> Effect Unit withOffsetElemTests count = overAll1 count withOffsetElem where withOffsetElem :: forall a b t. TestableArrayF a b D5 t Result - withOffsetElem (WithOffset os xs) = pure $ - Array.all (\o -> TA.elem (unsafePartial $ unsafePerformEffect $ TA.unsafeAt xs o) Nothing xs) os - "All doesn't have an elem of itself" + withOffsetElem (WithOffset os xs) = do + let valid :: TA.Offset -> Boolean + valid o = unsafePerformEffect do + e <- unsafePartial $ TA.unsafeAt xs o + b <- TA.elem e Nothing xs + pure b + pure $ Array.all valid os "All doesn't have an elem of itself" -- | Should work with any arbitrary predicate, but we can't generate them @@ -307,7 +313,8 @@ anyImpliesFindTests count = overAll count anyImpliesFind anyImpliesFind :: forall a b t. TestableArrayF a b D0 t Result anyImpliesFind (WithOffset _ xs) = do let pred x = x /= zero - p = TA.any pred xs "All don't satisfy the predicate" + 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" From 52693b76d6bd21325fb9e330d8316c9be1ec56c9 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 29 Jan 2019 23:26:53 +0100 Subject: [PATCH 18/79] Simplify --- test/Properties/TypedArray.purs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index aee4451..fd0f099 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -10,7 +10,8 @@ import Data.ArrayBuffer.Typed as TA import Data.ArrayBuffer.Typed.Gen (WithOffset(..), genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8, genWithOffset) import Data.ArrayBuffer.Types (ArrayView, Float32Array, Float64Array, Int16Array, Int32Array, Int8Array, Uint16Array, Uint8Array, Uint8ClampedArray, Uint32Array) import Data.ArrayBuffer.ValueMapping (class BytesPerValue) -import Data.Maybe (Maybe(..), fromMaybe) +import Data.Maybe (Maybe(..), fromMaybe, isJust) +import Data.Traversable (traverse) import Data.Typelevel.Num (class Nat, D0, D1, D2, D5, d0, d1, toInt') import Data.Vec (head, index) as Vec import Effect (Effect) @@ -18,7 +19,6 @@ import Effect.Console (log) import Effect.Ref (Ref) import Effect.Ref as Ref import Effect.Unsafe (unsafePerformEffect) -import Partial.Unsafe (unsafePartial) import Test.QuickCheck (class Testable, Result(..), quickCheckGen, (/==), (), (===)) import Test.QuickCheck.Combinators ((==>), (|=|)) import Test.QuickCheck.Gen (Gen) @@ -298,12 +298,9 @@ withOffsetElemTests count = overAll1 count withOffsetElem where withOffsetElem :: forall a b t. TestableArrayF a b D5 t Result withOffsetElem (WithOffset os xs) = do - let valid :: TA.Offset -> Boolean - valid o = unsafePerformEffect do - e <- unsafePartial $ TA.unsafeAt xs o - b <- TA.elem e Nothing xs - pure b - pure $ Array.all valid os "All doesn't have an elem of itself" + 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 From ea63698cef557beb31629f7aa159241c4996b0b3 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 29 Jan 2019 23:35:25 +0100 Subject: [PATCH 19/79] Effectful toString --- src/Data/ArrayBuffer/Typed.js | 2 +- src/Data/ArrayBuffer/Typed.purs | 11 +++++++---- test/Properties/TypedArray.purs | 6 ++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index 3f52aa7..3b536e7 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -159,7 +159,7 @@ exports.subArrayImpl = function subArrayImpl (a, s, e) { }; -exports.toString = function toString (a) { +exports.toStringImpl = function toStringImpl (a) { return a.toString(); }; diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index a0a4ac1..d411fa4 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -379,14 +379,17 @@ foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) Offset Offset (ArrayV subArray :: forall a. Offset -> Offset -> ArrayView a -> ArrayView a subArray s e a = runFn3 subArrayImpl a s e +foreign import toStringImpl :: forall a. EffectFn1 (ArrayView a) String + -- | 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. -foreign import toString :: forall a. ArrayView a -> String +toString :: forall a. ArrayView a -> Effect String +toString a = runEffectFn1 toStringImpl a -foreign import joinImpl :: forall a. Fn2 (ArrayView a) String String +foreign import joinImpl :: forall a. EffectFn2 (ArrayView a) String 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. -toString' :: forall a. ArrayView a -> String -> String -toString' a s = runFn2 joinImpl a s +toString' :: forall a. ArrayView a -> String -> Effect String +toString' a s = runEffectFn2 joinImpl a s foreign import unsafeAtImpl :: forall a b. EffectFn2 (ArrayView a) Offset b diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index fd0f099..0ecaebc 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -466,8 +466,10 @@ toStringIsJoinWithCommaTests :: Ref Int -> Effect Unit toStringIsJoinWithCommaTests count = overAll count toStringIsJoinWithComma where toStringIsJoinWithComma :: forall a b t. TestableArrayF a b D0 t Result - toStringIsJoinWithComma (WithOffset _ xs) = - pure $ TA.toString' xs "," === TA.toString xs + toStringIsJoinWithComma (WithOffset _ xs) = do + s1 <- TA.toString' xs "," + s2 <- TA.toString xs + pure $ s1 === s2 setTypedOfSubArrayIsIdentityTests :: Ref Int -> Effect Unit From 355f17e97f6d2f9f4f40d6f49102f752d81c322e Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 29 Jan 2019 23:48:35 +0100 Subject: [PATCH 20/79] toString' -> join, changed args order --- src/Data/ArrayBuffer/Typed.purs | 13 +++++++------ test/Properties/TypedArray.purs | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index d411fa4..3c7758e 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -18,7 +18,7 @@ module Data.ArrayBuffer.Typed , foldlM, foldl1M, foldl, foldl1, foldrM, foldr1M, foldr, foldr1 , find, findIndex, indexOf, lastIndexOf , slice, subArray - , toString, toString', toArray + , toString, join, toArray ) where import Data.Array (length) as A @@ -126,7 +126,7 @@ type Length = Int -- | - `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 --- | - `toString` prints to a CSV, `toString'` allows you to supply the delimiter +-- | - `toString` prints to a CSV, `join` allows you to supply the delimiter -- | - `toArray` returns an array of numeric values class BinaryValue a t <= TypedArray (a :: ArrayViewType) (t :: Type) | a -> t where create :: forall x. EffectFn3 x (Nullable ByteOffset) (Nullable ByteLength) (ArrayView a) @@ -388,18 +388,19 @@ toString a = runEffectFn1 toStringImpl a foreign import joinImpl :: forall a. EffectFn2 (ArrayView a) String 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. -toString' :: forall a. ArrayView a -> String -> Effect String -toString' a s = runEffectFn2 joinImpl a s +join :: forall a. String -> ArrayView a -> Effect String +join s a = runEffectFn2 joinImpl a s -foreign import unsafeAtImpl :: forall a b. EffectFn2 (ArrayView a) Offset b - foreign import hasIndexImpl :: forall a. Fn2 (ArrayView a) Offset Boolean -- | Determine if a certain index is valid. hasIndex :: forall a. ArrayView a -> Offset -> Boolean hasIndex a o = runFn2 hasIndexImpl a o + +foreign import unsafeAtImpl :: forall a b. EffectFn2 (ArrayView a) Offset b + -- | Fetch element at index. at :: forall a t. TypedArray a t => ArrayView a -> Offset -> Effect (Maybe t) at a n = if a `hasIndex` n diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index 0ecaebc..ec4d811 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -77,7 +77,7 @@ typedArrayTests count = do sortIsIdempotentTests count log " - toArray (sort x) == Array.sort (toArray x)" sortIsArraySortTests count - log " - toString' \",\" x == toString x" + log " - join \",\" x == toString x" toStringIsJoinWithCommaTests count log " - setTyped x (subArray x) == x" setTypedOfSubArrayIsIdentityTests count @@ -467,7 +467,7 @@ toStringIsJoinWithCommaTests count = overAll count toStringIsJoinWithComma where toStringIsJoinWithComma :: forall a b t. TestableArrayF a b D0 t Result toStringIsJoinWithComma (WithOffset _ xs) = do - s1 <- TA.toString' xs "," + s1 <- TA.join "," xs s2 <- TA.toString xs pure $ s1 === s2 From 85dcb57e842614fa2000abb4bfcad7347afc737e Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Wed, 30 Jan 2019 00:09:00 +0100 Subject: [PATCH 21/79] toNullable accepts undefined, no need to check --- src/Data/ArrayBuffer/Typed.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index 3b536e7..bb4e21a 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -108,12 +108,12 @@ exports.reduceRight1Impl = function reduceRight1Impl (a,f) { }; exports.findImpl = function findImpl (a,f) { - var x = a.find(f); - return (x === undefined) ? null : x; + return a.find(f); }; + exports.findIndexImpl = function findIndexImpl (a,f) { - var x = a.findIndex(f); - return (x === -1) ? null : x; + var r = a.findIndex(f); + return r === -1 ? null : r; }; exports.indexOfImpl = function indexOfImpl (a,x,mo) { var r = mo === null ? a.indexOf(x) : a.indexOf(x,mo); From e8ebe3929e0a6e06d09c5c378082e819d8d95506 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Wed, 30 Jan 2019 00:10:24 +0100 Subject: [PATCH 22/79] Simplify fill --- src/Data/ArrayBuffer/Typed.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index bb4e21a..1969c21 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -73,8 +73,8 @@ exports.someImpl = function someImpl (a,p) { }; -exports.fillImpl = function fillImpl (a,x,ms,me) { - return me === null ? (ms === null ? a.fill(x) : a.fill(x,ms)) : a.fill(x,ms,me); +exports.fillImpl = function fillImpl (a,x,s,e) { + return a.fill(x,s,e); }; From bdc0c0dd3e9c8173857aefc01c1688814a8456b5 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Wed, 30 Jan 2019 00:13:48 +0100 Subject: [PATCH 23/79] JS args order --- src/Data/ArrayBuffer/Typed.js | 2 +- src/Data/ArrayBuffer/Typed.purs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index 1969c21..d7e2785 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -73,7 +73,7 @@ exports.someImpl = function someImpl (a,p) { }; -exports.fillImpl = function fillImpl (a,x,s,e) { +exports.fillImpl = function fillImpl (x, s, e, a) { return a.fill(x,s,e); }; diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 3c7758e..2b8b10b 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -74,7 +74,7 @@ foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N foreign import everyImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean foreign import someImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean -foreign import fillImpl :: forall a b. EffectFn4 (ArrayView a) b Offset Offset Unit +foreign import fillImpl :: forall a b. EffectFn4 b Offset Offset (ArrayView a) Unit foreign import mapImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset b) (ArrayView a) foreign import forEachImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Unit) Unit @@ -180,7 +180,7 @@ fromArray a = runEffectFn3 create a null null -- | Fill the array with a value fill :: forall a t. TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit -fill x s e a = runEffectFn4 fillImpl a x s e +fill x s e a = runEffectFn4 fillImpl x s e a -- | Stores multiple values into the typed array set :: forall a t. TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean From 6602ee480a5583d7d5972c671bb1c895e386c0ea Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Wed, 30 Jan 2019 00:22:15 +0100 Subject: [PATCH 24/79] Simplify at --- src/Data/ArrayBuffer/Typed.purs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 2b8b10b..1d0f699 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -403,9 +403,7 @@ foreign import unsafeAtImpl :: forall a b. EffectFn2 (ArrayView a) Offset b -- | Fetch element at index. at :: forall a t. TypedArray a t => ArrayView a -> Offset -> Effect (Maybe t) -at a n = if a `hasIndex` n - then Just <$> unsafePartial (unsafeAt a n) - else pure Nothing +at a n = toMaybe <$> runEffectFn2 unsafeAtImpl a n infixl 3 at as ! From 24ee28c11ff1427a98f5f3173d995021c846fe56 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Wed, 30 Jan 2019 00:27:31 +0100 Subject: [PATCH 25/79] Moved to module doc --- src/Data/ArrayBuffer/Typed.purs | 60 +++++++++++++++------------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 1d0f699..f00d3f4 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -1,5 +1,33 @@ -- | This module represents the functional bindings to JavaScript's `TypedArray` and other -- | objects. See [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) for details. +-- | +-- | #### Creation +-- | +-- | - `whole`, `remainder`, and `part` are functions for building a typed array accessible interface +-- | on top of an existing `ArrayBuffer` +-- | - `empty` and `fromArray` are functions for creating pure typed arrays +-- | +-- | #### Modification +-- | +-- | - `fill`, `set`, and `setTyped` are functions for assigning values from external sources +-- | - `map` and `traverse` allow you to create a new array from the existing values in another +-- | - `copyWithin` allows you to set values to the array that exist in other parts of the array +-- | - `filter` creates a new array without the values that don't pass a predicate +-- | - `reverse` modifies an existing array in-place, with all values reversed +-- | - `sort` modifies an existing array in-place, with all values sorted +-- | +-- | #### Access +-- | +-- | - `elem`, `all`, and `any` are functions for testing the contents of an array +-- | - `unsafeAt`, `hasIndex`, and `at` are used to get values from an array, with an offset +-- | - `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 +-- | - `toString` prints to a CSV, `join` allows you to supply the delimiter +-- | - `toArray` returns an array of numeric values + module Data.ArrayBuffer.Typed ( polyFill @@ -96,38 +124,6 @@ type Offset = Int type Length = Int --- TODO use purescript-quotient --- | Typeclass that associates a measured user-level type with a typed array. --- | --- | #### Creation --- | --- | - `whole`, `remainder`, and `part` are methods for building a typed array accessible interface --- | on top of an existing `ArrayBuffer` - Note, `part` and `remainder` may behave unintuitively - --- | when the operation is isomorphic to `whole`, the new TypedArray uses the same buffer as the input, --- | but not when the portion is a sub-array of the original buffer, a new one is made with --- | `Data.ArrayBuffer.ArrayBuffer.slice`. --- | - `empty` and `fromArray` are methods for creating pure typed arrays --- | --- | #### Modification --- | --- | - `fill`, `set`, and `setTyped` are methods for assigning values from external sources --- | - `map` and `traverse` allow you to create a new array from the existing values in another --- | - `copyWithin` allows you to set values to the array that exist in other parts of the array --- | - `filter` creates a new array without the values that don't pass a predicate --- | - `reverse` modifies an existing array in-place, with all values reversed --- | - `sort` modifies an existing array in-place, with all values sorted --- | --- | #### Access --- | --- | - `elem`, `all`, and `any` are functions for testing the contents of an array --- | - `unsafeAt`, `hasIndex`, and `at` are used to get values from an array, with an offset --- | - `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 --- | - `toString` prints to a CSV, `join` allows you to supply the delimiter --- | - `toArray` returns an array of numeric values class BinaryValue a t <= TypedArray (a :: ArrayViewType) (t :: Type) | a -> t where create :: forall x. EffectFn3 x (Nullable ByteOffset) (Nullable ByteLength) (ArrayView a) From 881787c0fe070ffdb009089cb0c7b0272ec09ac4 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Wed, 30 Jan 2019 00:31:32 +0100 Subject: [PATCH 26/79] Document length --- src/Data/ArrayBuffer/Typed.purs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index f00d3f4..5d20531 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -54,14 +54,13 @@ import Data.ArrayBuffer.Types (ArrayView, kind ArrayViewType, ArrayBuffer, ByteO import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerValue) import Data.Float32 (Float32) as F import Data.Function.Uncurried (Fn2, Fn3, mkFn2, runFn2, runFn3) -import Data.Maybe (Maybe(..), fromMaybe) +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) import Effect.Unsafe (unsafePerformEffect) -import Partial.Unsafe (unsafePartial) import Prelude (Unit, flip, pure, (&&), (*), (*>), (-), (<$>), (<<<), (<=), (>=)) import Type.Proxy (Proxy(..)) @@ -80,6 +79,7 @@ foreign import byteLength :: forall a. ArrayView a -> ByteLength foreign import lengthImpl :: forall a. ArrayView a -> Length +-- | Represents the number of elements in this typed array. length :: forall a. ArrayView a -> Length length = lengthImpl From bf9c6821a74fa973ca6f038ea67d21d2337375e9 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Wed, 30 Jan 2019 00:47:55 +0100 Subject: [PATCH 27/79] Docs --- src/Data/ArrayBuffer/Typed.purs | 51 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 5d20531..6218b7f 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -118,9 +118,9 @@ foreign import indexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Of foreign import lastIndexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) --- | Value-oriented array offset +-- | Value-oriented array offset. type Offset = Int --- | Value-oriented array length +-- | Value-oriented array length. type Length = Int @@ -166,19 +166,19 @@ part a x y = part' a o y part' :: forall a t. TypedArray a t => ArrayBuffer -> ByteOffset -> Length -> Effect (ArrayView a) part' a x y = runEffectFn3 create a (notNull x) (notNull y) --- | Creates an empty typed array, where each value is assigned 0 +-- | Creates an empty typed array, where each value is assigned 0. empty :: forall a t. TypedArray a t => Length -> Effect (ArrayView a) empty n = runEffectFn3 create n null null --- | Creates a typed array from an input array of values, to be binary serialized +-- | Creates a typed array from an input array of values, to be binary serialized. fromArray :: forall a t. TypedArray a t => Array t -> Effect (ArrayView a) fromArray a = runEffectFn3 create a null null --- | Fill the array with a value +-- | Fill the array with a value. fill :: forall a t. TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit fill x s e a = runEffectFn4 fillImpl x s e a --- | Stores multiple values into the typed array +-- | Stores multiple values into the typed array. set :: forall a t. TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean set = setInternal A.length @@ -193,56 +193,58 @@ map = mapWithIndex' <<< ap1 -- | Apply a function to each element in an array, supplying a -- | generated zero-based index integer along with the element, --- | creating a typed array with the new elements +-- | creating a typed array with the new elements. mapWithIndex :: forall a t. TypedArray a t => (Offset -> t -> t) -> ArrayView a -> ArrayView a mapWithIndex = mapWithIndex' <<< flip mapWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> t) -> ArrayView a -> ArrayView a mapWithIndex' f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o)))) --- | Traverses over each value, returning a new one +-- | Traverses over each value, returning a new one. traverse :: forall a t. TypedArray a t => (t -> Effect t) -> ArrayView a -> Effect (ArrayView a) traverse = traverseWithIndex' <<< ap1 --- | Traverses over each value, returning a new one +-- | Traverses over each value, returning a new one. traverseWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Effect t) -> ArrayView a -> Effect (ArrayView a) traverseWithIndex = traverseWithIndex' <<< flip traverseWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Effect t) -> ArrayView a -> Effect (ArrayView a) traverseWithIndex' f a = runEffectFn2 mapImpl a (mkEffectFn2 f) --- | Traverses over each value +-- | Traverses over each value. traverse_ :: forall a t. TypedArray a t => (t -> Effect Unit) -> ArrayView a -> Effect Unit traverse_ = traverseWithIndex_' <<< ap1 --- | Traverses over each value +-- | Traverses over each value. traverseWithIndex_ :: forall a t. TypedArray a t => (Offset -> t -> Effect Unit) -> ArrayView a -> Effect Unit traverseWithIndex_ = traverseWithIndex_' <<< flip traverseWithIndex_' :: forall a t. TypedArray a t => (t -> Offset -> Effect Unit) -> ArrayView a -> Effect Unit traverseWithIndex_' f a = runEffectFn2 forEachImpl a (mkEffectFn2 f) --- | Test a predicate to pass on all values +-- | Test a predicate to pass on all values. all :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean all = every <<< ap1 +-- | Test a predicate (that receives also an index) to pass on all values. allWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect Boolean allWithIndex = every <<< flip every :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean every p a = runEffectFn2 everyImpl a (mkFn2 p) --- | Test a predicate to pass on any value +-- | Test a predicate to pass on any value. any :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean any = some <<< ap1 +-- | Test a predicate (that receives also an index) to pass on any value. anyWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect Boolean anyWithIndex = some <<< flip some :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean some p a = runEffectFn2 someImpl a (mkFn2 p) --- | Returns a new typed array with all values that pass the predicate +-- | Returns a new typed array with all values that pass the predicate. filter :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (ArrayView a) filter = filterWithIndex' <<< ap1 @@ -252,7 +254,7 @@ filterWithIndex = filterWithIndex' <<< flip filterWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (ArrayView a) filterWithIndex' p a = runEffectFn2 filterImpl a (mkFn2 p) --- | Tests if a value is an element of the typed array +-- | Tests if a value is an element of the typed array. elem :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect Boolean elem x mo a = runEffectFn3 includesImpl a x (toNullable mo) @@ -260,23 +262,23 @@ elem x mo a = runEffectFn3 includesImpl a x (toNullable mo) unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Offset -> Effect t unsafeAt a o = runEffectFn2 unsafeAtImpl a o --- | Folding from the left +-- | Folding from the left. foldlM :: forall a t b. TypedArray a t => (b -> t -> Offset -> Effect b) -> b -> ArrayView a -> Effect b foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i --- | Assumes the typed array is non-empty +-- | Folding from the left. Assumes the typed array is non-empty. foldl1M :: forall a t. TypedArray a t => (t -> t -> Offset -> Effect t) -> ArrayView a -> Effect t foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) --- | Folding from the right +-- | Folding from the right. foldrM :: forall a t b. TypedArray a t => (t -> b -> Offset -> Effect b) -> b -> ArrayView a -> Effect b foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i --- | Assumes the typed array is non-empty +-- | Folding from the right. Assumes the typed array is non-empty. foldr1M :: forall a t. TypedArray a t => (t -> t -> Offset -> Effect t) -> ArrayView a -> Effect t foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o)) --- | Returns the first value satisfying the predicate +-- | Returns the first value satisfying the predicate. find :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (Maybe t) find = findWithIndex' <<< ap1 @@ -286,18 +288,19 @@ findWithIndex = findWithIndex' <<< flip findWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (Maybe t) findWithIndex' f a = toMaybe <$> runEffectFn2 findImpl a (mkFn2 f) --- | Returns the first index of the value satisfying the predicate +-- | Returns the first index of the value satisfying the predicate. findIndex :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (Maybe Offset) findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkFn2 f) --- | Returns the first index of the element, if it exists, from the left +-- | Returns the first index of the element, if it exists, from the left. indexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset) indexOf x mo a = toMaybe <$> runEffectFn3 indexOfImpl a x (toNullable mo) --- | Returns the first index of the element, if it exists, from the right +-- | Returns the first index of the element, if it exists, from the right. lastIndexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset) lastIndexOf x mo a = toMaybe <$> runEffectFn3 lastIndexOfImpl a x (toNullable mo) + foldl :: forall a b t. TypedArray a t => (b -> t -> b) -> b -> ArrayView a -> Effect b foldl f = foldlWithIndex' (\a x _ -> f a x) @@ -364,7 +367,7 @@ slice s e a = runEffectFn3 sliceImpl a s e foreign import sortImpl :: forall a. EffectFn1 (ArrayView a) Unit --- | Sorts the values in-place +-- | Sorts the values in-place. sort :: forall a. ArrayView a -> Effect Unit sort a = runEffectFn1 sortImpl a From f68f7cdc515f72db486aadf0c0c218677870999f Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Wed, 30 Jan 2019 22:53:45 +0100 Subject: [PATCH 28/79] Moved *Impl functions near their call site --- src/Data/ArrayBuffer/ArrayBuffer.purs | 8 +-- src/Data/ArrayBuffer/DataView.purs | 29 +++++----- src/Data/ArrayBuffer/Typed.purs | 77 ++++++++++----------------- 3 files changed, 44 insertions(+), 70 deletions(-) diff --git a/src/Data/ArrayBuffer/ArrayBuffer.purs b/src/Data/ArrayBuffer/ArrayBuffer.purs index 6dd5b4e..1206040 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.purs +++ b/src/Data/ArrayBuffer/ArrayBuffer.purs @@ -12,19 +12,15 @@ import Data.Function.Uncurried (Fn3, runFn3) import Effect (Effect) import Effect.Uncurried (EffectFn1, runEffectFn1) - -foreign import emptyImpl :: EffectFn1 ByteLength ArrayBuffer - - -- | 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. foreign import byteLength :: ArrayBuffer -> ByteLength -foreign import sliceImpl :: Fn3 ArrayBuffer ByteOffset ByteOffset ArrayBuffer - -- | 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/DataView.purs b/src/Data/ArrayBuffer/DataView.purs index 001f37b..2637003 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -66,17 +66,16 @@ import Type.Proxy (Proxy(..)) -- | View mapping the whole `ArrayBuffer`. foreign import whole :: ArrayBuffer -> DataView -foreign import remainderImpl :: EffectFn2 ArrayBuffer ByteOffset 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 partImpl :: EffectFn3 ArrayBuffer ByteOffset ByteLength DataView +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. foreign import buffer :: DataView -> ArrayBuffer @@ -121,12 +120,6 @@ instance showArrayViewTypeViewInt8 :: ShowArrayViewType Int8 "Int8" instance showArrayViewTypeViewFloat32 :: ShowArrayViewType Float32 "Float32" instance showArrayViewTypeViewFloat64 :: ShowArrayViewType Float64 "Float64" -foreign import getterImpl :: forall t - . EffectFn3 { functionName :: String - , littleEndian :: Boolean - , bytesPerValue :: ByteLength - } DataView ByteOffset (Nullable t) - getter :: forall t. { functionName :: String , bytesPerValue :: ByteLength @@ -139,6 +132,12 @@ getter data' d o = toMaybe <$> , 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 b @@ -175,18 +174,18 @@ getLE :: forall a name t b => AProxy a -> DataView -> ByteOffset -> Effect (Maybe t) getLE = get LE -foreign import setterImpl :: forall t - . EffectFn4 { functionName :: String - , littleEndian :: Boolean - , bytesPerValue :: ByteLength - } DataView ByteOffset t Boolean - 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 b . DataView a t diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 6218b7f..0d8c504 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -77,12 +77,10 @@ foreign import byteOffset :: forall a. ArrayView a -> ByteOffset -- | Represents the length of this typed array, in bytes. foreign import byteLength :: forall a. ArrayView a -> ByteLength -foreign import lengthImpl :: forall a. ArrayView a -> Length - -- | 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 @@ -99,24 +97,6 @@ foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N -- ---- -foreign import everyImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean -foreign import someImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean - -foreign import fillImpl :: forall a b. EffectFn4 b Offset Offset (ArrayView a) Unit - -foreign import mapImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset b) (ArrayView a) -foreign import forEachImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Offset Unit) Unit -foreign import filterImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) (ArrayView a) -foreign import includesImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Offset) Boolean -foreign import reduceImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Offset c) c c -foreign import reduce1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Offset b) b -foreign import reduceRightImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Offset c) c c -foreign import reduceRight1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Offset b) b -foreign import findImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) (Nullable b) -foreign import findIndexImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) (Nullable Offset) -foreign import indexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) -foreign import lastIndexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) - -- | Value-oriented array offset. type Offset = Int @@ -177,6 +157,7 @@ fromArray a = runEffectFn3 create a null null -- | Fill the array with a value. fill :: forall a t. TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit fill x s e a = runEffectFn4 fillImpl x s e a +foreign import fillImpl :: forall a b. EffectFn4 b Offset Offset (ArrayView a) Unit -- | Stores multiple values into the typed array. set :: forall a t. TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean @@ -199,6 +180,7 @@ mapWithIndex = mapWithIndex' <<< flip mapWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> 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 Offset b) (ArrayView a) -- | Traverses over each value, returning a new one. traverse :: forall a t. TypedArray a t => (t -> Effect t) -> ArrayView a -> Effect (ArrayView a) @@ -221,6 +203,7 @@ traverseWithIndex_ = traverseWithIndex_' <<< flip traverseWithIndex_' :: forall a t. TypedArray a t => (t -> Offset -> 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 Offset Unit) Unit -- | Test a predicate to pass on all values. all :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean @@ -232,6 +215,7 @@ allWithIndex = every <<< flip every :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean every p a = runEffectFn2 everyImpl a (mkFn2 p) +foreign import everyImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean -- | Test a predicate to pass on any value. any :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean @@ -243,6 +227,7 @@ anyWithIndex = some <<< flip some :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean some p a = runEffectFn2 someImpl a (mkFn2 p) +foreign import someImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) Boolean -- | Returns a new typed array with all values that pass the predicate. filter :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (ArrayView a) @@ -253,10 +238,12 @@ filterWithIndex = filterWithIndex' <<< flip filterWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> 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 Offset Boolean) (ArrayView a) -- | Tests if a value is an element of the typed array. elem :: forall a t. TypedArray a t => t -> Maybe Offset -> 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 Offset) Boolean -- | Fetch element at index. unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Offset -> Effect t @@ -265,18 +252,22 @@ unsafeAt a o = runEffectFn2 unsafeAtImpl a o -- | Folding from the left. foldlM :: forall a t b. TypedArray a t => (b -> t -> Offset -> Effect b) -> b -> ArrayView a -> Effect b foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i +foreign import reduceImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Offset c) c c -- | Folding from the left. Assumes the typed array is non-empty. foldl1M :: forall a t. TypedArray a t => (t -> t -> Offset -> Effect t) -> ArrayView a -> Effect t foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) +foreign import reduce1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Offset b) b -- | Folding from the right. foldrM :: forall a t b. TypedArray a t => (t -> b -> Offset -> Effect b) -> b -> ArrayView a -> Effect b foldrM 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 Offset c) c c -- | Folding from the right. Assumes the typed array is non-empty. foldr1M :: forall a t. TypedArray a t => (t -> t -> Offset -> Effect t) -> ArrayView a -> Effect t foldr1M 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 Offset b) b -- | Returns the first value satisfying the predicate. find :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (Maybe t) @@ -287,19 +278,22 @@ findWithIndex = findWithIndex' <<< flip findWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> 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 Offset Boolean) (Nullable b) -- | Returns the first index of the value satisfying the predicate. findIndex :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (Maybe Offset) findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkFn2 f) +foreign import findIndexImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boolean) (Nullable Offset) -- | Returns the first index of the element, if it exists, from the left. indexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset) indexOf x mo a = toMaybe <$> runEffectFn3 indexOfImpl a x (toNullable mo) +foreign import indexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) -- | Returns the first index of the element, if it exists, from the right. lastIndexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset) lastIndexOf x mo a = toMaybe <$> runEffectFn3 lastIndexOfImpl a x (toNullable mo) - +foreign import lastIndexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Offset) (Nullable Offset) foldl :: forall a b t. TypedArray a t => (b -> t -> b) -> b -> ArrayView a -> Effect b foldl f = foldlWithIndex' (\a x _ -> f a x) @@ -331,19 +325,16 @@ foldr1 f = foldr1WithIndex (\_ a x -> f a x) foldr1WithIndex :: forall a t. TypedArray a t => (Offset -> t -> t -> t) -> ArrayView a -> Effect t foldr1WithIndex f = foldr1M (\x a o -> pure (f o x a)) -foreign import copyWithinImpl :: forall a. EffectFn4 (ArrayView a) Offset Offset (Nullable Offset) Unit - -- | 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 -> Offset -> Offset -> Maybe Offset -> Effect Unit copyWithin a t s me = runEffectFn4 copyWithinImpl a t s (toNullable me) - -foreign import reverseImpl :: forall a. EffectFn1 (ArrayView a) Unit +foreign import copyWithinImpl :: forall a. EffectFn4 (ArrayView a) Offset Offset (Nullable Offset) 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 setImpl :: forall a b. EffectFn3 (ArrayView a) Offset b Unit setInternal :: forall a b. (b -> Length) -> ArrayView a -> Maybe Offset -> b -> Effect Boolean setInternal lenfn a mo b = @@ -351,64 +342,52 @@ setInternal lenfn a mo b = 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) Offset b Unit + -- | Stores multiple values in the typed array, reading input values from the second typed array. setTyped :: forall a. ArrayView a -> Maybe Offset -> ArrayView a -> Effect Boolean setTyped = setInternal length - --- | Copy the entire contents of the typed array into a new buffer. -foreign import sliceImpl :: forall a. EffectFn3 (ArrayView a) Offset Offset (ArrayView a) - -- | Copy part of the contents of a typed array into a new buffer, between some start and end indices. slice :: forall a. Offset -> Offset -> ArrayView a -> Effect (ArrayView a) slice s e a = runEffectFn3 sliceImpl a s e - -foreign import sortImpl :: forall a. EffectFn1 (ArrayView a) Unit +foreign import sliceImpl :: forall a. EffectFn3 (ArrayView a) Offset Offset (ArrayView a) -- | Sorts the values in-place. sort :: forall a. ArrayView a -> Effect Unit sort a = runEffectFn1 sortImpl a - - -foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) Offset Offset (ArrayView 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. Offset -> Offset -> ArrayView a -> ArrayView a subArray s e a = runFn3 subArrayImpl a s e - -foreign import toStringImpl :: forall a. EffectFn1 (ArrayView a) String +foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) Offset Offset (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 joinImpl :: forall a. EffectFn2 (ArrayView a) String String +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 hasIndexImpl :: forall a. Fn2 (ArrayView a) Offset Boolean +foreign import joinImpl :: forall a. EffectFn2 (ArrayView a) String String -- | Determine if a certain index is valid. hasIndex :: forall a. ArrayView a -> Offset -> Boolean hasIndex a o = runFn2 hasIndexImpl a o - - -foreign import unsafeAtImpl :: forall a b. EffectFn2 (ArrayView a) Offset b +foreign import hasIndexImpl :: forall a. Fn2 (ArrayView a) Offset Boolean -- | Fetch element at index. at :: forall a t. TypedArray a t => ArrayView a -> Offset -> Effect (Maybe t) at a n = toMaybe <$> runEffectFn2 unsafeAtImpl a n +foreign import unsafeAtImpl :: forall a b. EffectFn2 (ArrayView a) Offset b infixl 3 at as ! - -foreign import toArrayImpl :: forall a b. EffectFn1 (ArrayView a) (Array b) - -- | 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) From 7e5febce607fd17b1bdc7f2aad34c00d8a23119d Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Wed, 30 Jan 2019 23:02:53 +0100 Subject: [PATCH 29/79] Docs --- src/Data/ArrayBuffer/Typed.purs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 0d8c504..8cc7cec 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -95,9 +95,6 @@ foreign import newFloat32Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Float64Array --- ---- - - -- | Value-oriented array offset. type Offset = Int -- | Value-oriented array length. @@ -209,7 +206,8 @@ foreign import forEachImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b O all :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean all = every <<< ap1 --- | Test a predicate (that receives also an index) to pass on all values. +-- | Test a predicate to pass on all values. The predicate function +-- | receives the offset and the element. allWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect Boolean allWithIndex = every <<< flip @@ -233,6 +231,9 @@ foreign import someImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Offset Boo filter :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (ArrayView a) filter = filterWithIndex' <<< ap1 +-- | Returns a new typed array with all values that pass the +-- | predicate. The predicate function receives the offset and the +-- | element. filterWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect (ArrayView a) filterWithIndex = filterWithIndex' <<< flip From 87efb53ae22075c84c43cb19bde1fd027b930142 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Thu, 31 Jan 2019 00:06:34 +0100 Subject: [PATCH 30/79] Renamed Offset->Index, removed foldr1WithIndex/foldl1WithIndex, docs --- src/Data/ArrayBuffer/Typed.purs | 182 ++++++++++++++-------------- src/Data/ArrayBuffer/Typed/Gen.purs | 12 +- test/Properties/TypedArray.purs | 102 ++++++++-------- 3 files changed, 149 insertions(+), 147 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 8cc7cec..9dd6b15 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -19,7 +19,7 @@ -- | #### Access -- | -- | - `elem`, `all`, and `any` are functions for testing the contents of an array --- | - `unsafeAt`, `hasIndex`, and `at` are used to get values from an array, with an offset +-- | - `unsafeAt`, `hasIndex`, and `at` are used to get values from an array, with an index -- | - `foldr`, `foldrM`, `foldr1`, `foldr1M`, `foldl`, `foldlM`, `foldl1`, `foldl1M` all can reduce an array -- | - `find` and `findIndex` are searching functions via a predicate -- | - `indexOf` and `lastIndexOf` are searching functions via equality @@ -31,7 +31,7 @@ module Data.ArrayBuffer.Typed ( polyFill - , Offset, Length + , Index, Length , buffer, byteOffset, byteLength, length , class TypedArray , create, whole, remainder, part, empty, fromArray @@ -43,7 +43,7 @@ module Data.ArrayBuffer.Typed , all, any , allWithIndex, anyWithIndex , unsafeAt, hasIndex, at, (!) - , foldlM, foldl1M, foldl, foldl1, foldrM, foldr1M, foldr, foldr1 + , reduce, reduce1, foldl, foldl1, reduceRight, reduceRight1, foldr, foldr1 , find, findIndex, indexOf, lastIndexOf , slice, subArray , toString, join, toArray @@ -61,7 +61,7 @@ import Data.UInt (UInt) import Effect (Effect) import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4, mkEffectFn2, mkEffectFn3, runEffectFn1, runEffectFn2, runEffectFn3, runEffectFn4) import Effect.Unsafe (unsafePerformEffect) -import Prelude (Unit, flip, pure, (&&), (*), (*>), (-), (<$>), (<<<), (<=), (>=)) +import Prelude (Unit, flip, pure, ($), (&&), (*), (*>), (-), (<$>), (<<<), (<=), (>=)) import Type.Proxy (Proxy(..)) @@ -95,8 +95,8 @@ foreign import newFloat32Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Float64Array --- | Value-oriented array offset. -type Offset = Int +-- | Value-oriented array index. +type Index = Int -- | Value-oriented array length. type Length = Int @@ -128,7 +128,7 @@ 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 -> Offset -> Effect (ArrayView a) +remainder :: forall a b t. TypedArray a t => Nat b => BytesPerValue a b => ArrayBuffer -> Index -> Effect (ArrayView a) remainder a x = remainder' a o where o = x * toInt' (Proxy :: Proxy b) @@ -136,7 +136,7 @@ remainder' :: forall a t. TypedArray a t => ArrayBuffer -> ByteOffset -> Effect 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 -> Offset -> Length -> Effect (ArrayView a) +part :: forall a b t. TypedArray a t => Nat b => BytesPerValue a b => ArrayBuffer -> Index -> Length -> Effect (ArrayView a) part a x y = part' a o y where o = x * toInt' (Proxy :: Proxy b) @@ -152,12 +152,12 @@ fromArray :: forall a t. TypedArray a t => Array t -> Effect (ArrayView a) fromArray a = runEffectFn3 create a null null -- | Fill the array with a value. -fill :: forall a t. TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit +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 Offset Offset (ArrayView a) Unit +foreign import fillImpl :: forall a b. EffectFn4 b Index Index (ArrayView a) Unit -- | Stores multiple values into the typed array. -set :: forall a t. TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean +set :: forall a t. TypedArray a t => ArrayView a -> Maybe Index -> Array t -> Effect Boolean set = setInternal A.length ap1 :: forall a b c. (a -> c) -> (a -> b -> c) @@ -172,22 +172,22 @@ map = mapWithIndex' <<< ap1 -- | Apply a function to each element in an array, supplying a -- | generated zero-based index integer along with the element, -- | creating a typed array with the new elements. -mapWithIndex :: forall a t. TypedArray a t => (Offset -> t -> t) -> ArrayView a -> ArrayView a +mapWithIndex :: forall a t. TypedArray a t => (Index -> t -> t) -> ArrayView a -> ArrayView a mapWithIndex = mapWithIndex' <<< flip -mapWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> 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 Offset b) (ArrayView a) +mapWithIndex' :: forall a t. TypedArray a t => (t -> Index -> t) -> ArrayView a -> ArrayView a +mapWithIndex' f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 \x o -> pure (f x o))) +foreign import mapImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Index b) (ArrayView a) -- | Traverses over each value, returning a new one. traverse :: forall a t. TypedArray a t => (t -> Effect t) -> ArrayView a -> Effect (ArrayView a) traverse = traverseWithIndex' <<< ap1 -- | Traverses over each value, returning a new one. -traverseWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Effect t) -> ArrayView a -> Effect (ArrayView a) +traverseWithIndex :: forall a t. TypedArray a t => (Index -> t -> Effect t) -> ArrayView a -> Effect (ArrayView a) traverseWithIndex = traverseWithIndex' <<< flip -traverseWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Effect t) -> ArrayView a -> Effect (ArrayView a) +traverseWithIndex' :: forall a t. TypedArray a t => (t -> Index -> Effect t) -> ArrayView a -> Effect (ArrayView a) traverseWithIndex' f a = runEffectFn2 mapImpl a (mkEffectFn2 f) -- | Traverses over each value. @@ -195,141 +195,143 @@ traverse_ :: forall a t. TypedArray a t => (t -> Effect Unit) -> ArrayView a -> traverse_ = traverseWithIndex_' <<< ap1 -- | Traverses over each value. -traverseWithIndex_ :: forall a t. TypedArray a t => (Offset -> t -> Effect Unit) -> ArrayView a -> Effect Unit +traverseWithIndex_ :: forall a t. TypedArray a t => (Index -> t -> Effect Unit) -> ArrayView a -> Effect Unit traverseWithIndex_ = traverseWithIndex_' <<< flip -traverseWithIndex_' :: forall a t. TypedArray a t => (t -> Offset -> Effect Unit) -> ArrayView a -> Effect Unit +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 Offset Unit) Unit +foreign import forEachImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn2 b Index Unit) Unit -- | Test a predicate to pass on all values. all :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean all = every <<< ap1 -- | Test a predicate to pass on all values. The predicate function --- | receives the offset and the element. -allWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect Boolean +-- | receives the index and the element. +allWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect Boolean allWithIndex = every <<< flip -every :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean +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 Offset Boolean) Boolean +foreign import everyImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Index Boolean) Boolean -- | Test a predicate to pass on any value. any :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean any = some <<< ap1 -- | Test a predicate (that receives also an index) to pass on any value. -anyWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect Boolean +anyWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect Boolean anyWithIndex = some <<< flip -some :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean +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 Offset Boolean) Boolean +foreign import someImpl :: forall a b. EffectFn2 (ArrayView a) (Fn2 b Index Boolean) Boolean -- | Returns a new typed array with all values that pass the predicate. filter :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (ArrayView a) filter = filterWithIndex' <<< ap1 -- | Returns a new typed array with all values that pass the --- | predicate. The predicate function receives the offset and the +-- | predicate. The predicate function receives the index and the -- | element. -filterWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect (ArrayView a) +filterWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect (ArrayView a) filterWithIndex = filterWithIndex' <<< flip -filterWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (ArrayView a) +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 Offset Boolean) (ArrayView a) +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 Offset -> ArrayView a -> Effect Boolean +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 Offset) Boolean +foreign import includesImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Index) Boolean -- | Fetch element at index. -unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Offset -> Effect t +unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Index -> Effect t unsafeAt a o = runEffectFn2 unsafeAtImpl a o -- | Folding from the left. -foldlM :: forall a t b. TypedArray a t => (b -> t -> Offset -> Effect b) -> b -> ArrayView a -> Effect b -foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i -foreign import reduceImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn3 c b Offset c) c c +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. -foldl1M :: forall a t. TypedArray a t => (t -> t -> Offset -> Effect t) -> ArrayView a -> Effect t -foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f) -foreign import reduce1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Offset b) b +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. -foldrM :: forall a t b. TypedArray a t => (t -> b -> Offset -> Effect b) -> b -> ArrayView a -> Effect b -foldrM 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 Offset c) c c +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. -foldr1M :: forall a t. TypedArray a t => (t -> t -> Offset -> Effect t) -> ArrayView a -> Effect t -foldr1M 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 Offset b) b +reduceRight1 :: forall a t. Partial => TypedArray a t => (t -> t -> Index -> Effect t) -> ArrayView a -> Effect t +reduceRight1 f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 \acc x o -> f x acc o) +foreign import reduceRight1Impl :: forall a b. EffectFn2 (ArrayView a) (EffectFn3 b b Index b) b -- | Returns the first value satisfying the predicate. find :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (Maybe t) find = findWithIndex' <<< ap1 -findWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect (Maybe t) +-- | Returns the first value satisfying the predicate. The predicate +-- | receives the index and the element at that index. +findWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect (Maybe t) findWithIndex = findWithIndex' <<< flip -findWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (Maybe t) +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 Offset Boolean) (Nullable b) +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 -> Offset -> Boolean) -> ArrayView a -> Effect (Maybe Offset) +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 Offset Boolean) (Nullable Offset) +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 Offset -> ArrayView a -> Effect (Maybe Offset) +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 Offset) (Nullable Offset) +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 Offset -> ArrayView a -> Effect (Maybe Offset) +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 Offset) (Nullable Offset) +foreign import lastIndexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Index) (Nullable Index) +-- | Fold a list from the left, accumulating the result using the +-- | specified function. foldl :: forall a b t. TypedArray a t => (b -> t -> b) -> b -> ArrayView a -> Effect b -foldl f = foldlWithIndex' (\a x _ -> f a x) +foldl f = reduce \a x _ -> pure $ f a x -foldlWithIndex :: forall a b t. TypedArray a t => (Offset -> b -> t -> b) -> b -> ArrayView a -> Effect b -foldlWithIndex f = foldlWithIndex' (\a x o -> f o a x) - -foldlWithIndex' :: forall a b t. TypedArray a t => (b -> t -> Offset -> b) -> b -> ArrayView a -> Effect b -foldlWithIndex' f i = foldlM (\a x o -> pure (f a x o)) i +-- | Fold a list from the left, accumulating the result using the +-- | supplied function. The accumulating function receives the index, +-- | the accumulated value and the element. +foldlWithIndex :: forall a b t. TypedArray a t => (Index -> b -> t -> b) -> b -> ArrayView a -> Effect b +foldlWithIndex f = reduce \a x o -> pure $ f o a x +-- | Fold a list from the right, accumulating the result using the +-- | specified function. foldr :: forall a b t. TypedArray a t => (t -> b -> b) -> b -> ArrayView a -> Effect b -foldr f = foldrWithIndex' (\a x _ -> f a x) - -foldrWithIndex :: forall a b t. TypedArray a t => (Offset -> t -> b -> b) -> b -> ArrayView a -> Effect b -foldrWithIndex f = foldrWithIndex' (\a x o -> f o a x) - -foldrWithIndex' :: forall a b t. TypedArray a t => (t -> b -> Offset -> b) -> b -> ArrayView a -> Effect b -foldrWithIndex' f i = foldrM (\x a o -> pure (f x a o)) i +foldr f = reduceRight \a x _ -> pure $ f a x -foldl1 :: forall a t. TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t -foldl1 f = foldl1WithIndex (\_ a x -> f a x) +-- | Fold a list from the right, accumulating the result using the +-- | supplied function. The accumulating function receives the index, +-- | the element and the accumulated value. +foldrWithIndex :: forall a b t. TypedArray a t => (Index -> t -> b -> b) -> b -> ArrayView a -> Effect b +foldrWithIndex f = reduceRight \a x o -> pure $ f o a x -foldl1WithIndex :: forall a t. TypedArray a t => (Offset -> t -> t -> t) -> ArrayView a -> Effect t -foldl1WithIndex f = foldl1M (\acc x o -> pure (f o acc x)) - -foldr1 :: forall a t. TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t -foldr1 f = foldr1WithIndex (\_ a x -> f a x) +-- | Folding from the left. Assumes the typed array is non-empty. +foldl1 :: forall a t. Partial => TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t +foldl1 f = reduce1 \a x _ -> pure $ f a x -foldr1WithIndex :: forall a t. TypedArray a t => (Offset -> t -> t -> t) -> ArrayView a -> Effect t -foldr1WithIndex f = foldr1M (\x a o -> pure (f o x a)) +-- | Folding from the right. Assumes the typed array is non-empty. +foldr1 :: forall a t. Partial => TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t +foldr1 f = reduceRight1 \x a _ -> pure $ f a x -- | Internally copy values - see [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) for details. -copyWithin :: forall a. ArrayView a -> Offset -> Offset -> Maybe Offset -> Effect Unit +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) Offset Offset (Nullable Offset) Unit +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 @@ -337,24 +339,24 @@ reverse a = runEffectFn1 reverseImpl a foreign import reverseImpl :: forall a. EffectFn1 (ArrayView a) Unit -setInternal :: forall a b. (b -> Length) -> ArrayView a -> Maybe Offset -> b -> Effect Boolean +setInternal :: forall a b. (b -> Length) -> ArrayView a -> Maybe Index -> b -> Effect Boolean setInternal lenfn a mo b = 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) Offset b Unit +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 Offset -> ArrayView a -> Effect Boolean +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. -slice :: forall a. Offset -> Offset -> ArrayView a -> Effect (ArrayView a) +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) Offset Offset (ArrayView a) +foreign import sliceImpl :: forall a. EffectFn3 (ArrayView a) Index Index (ArrayView a) -- | Sorts the values in-place. sort :: forall a. ArrayView a -> Effect Unit @@ -362,9 +364,9 @@ 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. Offset -> Offset -> ArrayView a -> ArrayView a +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) Offset Offset (ArrayView a) +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 @@ -377,14 +379,14 @@ 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 -> Offset -> Boolean +hasIndex :: forall a. ArrayView a -> Index -> Boolean hasIndex a o = runFn2 hasIndexImpl a o -foreign import hasIndexImpl :: forall a. Fn2 (ArrayView a) Offset Boolean +foreign import hasIndexImpl :: forall a. Fn2 (ArrayView a) Index Boolean -- | Fetch element at index. -at :: forall a t. TypedArray a t => ArrayView a -> Offset -> Effect (Maybe t) +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) Offset b +foreign import unsafeAtImpl :: forall a b. EffectFn2 (ArrayView a) Index b infixl 3 at as ! diff --git a/src/Data/ArrayBuffer/Typed/Gen.purs b/src/Data/ArrayBuffer/Typed/Gen.purs index ebc7db0..4470a12 100644 --- a/src/Data/ArrayBuffer/Typed/Gen.purs +++ b/src/Data/ArrayBuffer/Typed/Gen.purs @@ -58,19 +58,19 @@ 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 WithOffset n a = WithOffset (Vec n TA.Offset) (ArrayView a) -derive instance genericWithOffset :: Generic (ArrayView a) a' => Generic (WithOffset n a) _ +data WithIndices n a = WithIndices (Vec n TA.Index) (ArrayView a) +derive instance genericWithIndices :: Generic (ArrayView a) a' => Generic (WithIndices n a) _ -genWithOffset :: forall m n a +genWithIndices :: forall m n a . MonadGen m => Nat n => m (ArrayView a) - -> m (WithOffset n a) -genWithOffset gen = do + -> m (WithIndices n a) +genWithIndices gen = do let n = toInt' (Proxy :: Proxy n) xs <- gen let l = TA.length xs mos <- replicateA n (chooseInt 0 (l - 1)) let os = unsafePartial $ case Vec.fromArray mos of Just q -> q - pure (WithOffset os xs) + pure (WithIndices os xs) diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index ec4d811..c9599a0 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -7,7 +7,7 @@ import Control.Monad.Gen (suchThat) import Data.Array as Array import Data.ArrayBuffer.Typed (class TypedArray) import Data.ArrayBuffer.Typed as TA -import Data.ArrayBuffer.Typed.Gen (WithOffset(..), genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8, genWithOffset) +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.Maybe (Maybe(..), fromMaybe, isJust) @@ -50,9 +50,9 @@ typedArrayTests count = do log " - filter p (filter p x) == filter p x" filterIsIdempotentTests count log " - forall os `in` xs. all (\\o -> hasIndex o xs)" - withOffsetHasIndexTests count + withIndicesHasIndexTests count log " - forall os `in` xs. all (\\o -> elem (at o xs) xs)" - withOffsetElemTests count + withIndicesElemTests count log " - any p x => p (find p x)" anyImpliesFindTests count log " - p (at x (findIndex p x))" @@ -118,7 +118,7 @@ type TestableArrayF a b n t q = => TypedArray a t => BytesPerValue a b => Nat b - => WithOffset n a + => WithIndices n a -> Effect q @@ -129,7 +129,7 @@ overAll' mn count f = do 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 log $ " - " <> s - quickCheckGen $ unsafePerformEffect <<< f <$> genWithOffset arr + quickCheckGen $ unsafePerformEffect <<< f <$> genWithIndices arr where arr :: Gen (ArrayView a) arr = genTypedArray gen `suchThat` \xs -> mn <= TA.length xs @@ -154,7 +154,7 @@ subarrayBehavesLikeArraySliceTests :: Ref Int -> Effect Unit subarrayBehavesLikeArraySliceTests count = overAll count f where f :: forall a b t. TestableArrayF a b D2 t Result - f (WithOffset os xs) = do + f (WithIndices os xs) = do let s = os `Vec.index` d0 e = os `Vec.index` d1 axs <- TA.toArray xs @@ -166,7 +166,7 @@ sliceBehavesLikeArraySliceTests :: Ref Int -> Effect Unit sliceBehavesLikeArraySliceTests count = overAll count f where f :: forall a b t. TestableArrayF a b D2 t Result - f (WithOffset os xs) = do + f (WithIndices os xs) = do let s = os `Vec.index` d0 e = os `Vec.index` d1 axs <- TA.toArray xs @@ -178,7 +178,7 @@ partBehavesLikeTakeDropTests :: Ref Int -> Effect Unit partBehavesLikeTakeDropTests count = overAll count f where f :: forall a b t. TestableArrayF a b D0 t Result - f (WithOffset _ xs) = do + f (WithIndices _ xs) = do let n = 2 axs <- TA.toArray xs pxs <- TA.part (TA.buffer xs) n n :: Effect (ArrayView a) @@ -189,7 +189,7 @@ byteLengthDivBytesPerValueTests :: Ref Int -> Effect Unit byteLengthDivBytesPerValueTests count = overAll count byteLengthDivBytesPerValueEqLength where byteLengthDivBytesPerValueEqLength :: forall a b t. TestableArrayF a b D0 t Result - byteLengthDivBytesPerValueEqLength (WithOffset _ a) = + byteLengthDivBytesPerValueEqLength (WithIndices _ a) = let b = toInt' (Proxy :: Proxy b) in pure $ TA.length a === (TA.byteLength a `div` b) @@ -197,7 +197,7 @@ fromArrayToArrayIsoTests :: Ref Int -> Effect Unit fromArrayToArrayIsoTests count = overAll count fromArrayToArrayIso where fromArrayToArrayIso :: forall a b t. TestableArrayF a b D0 t Result - fromArrayToArrayIso (WithOffset _ xs) = do + fromArrayToArrayIso (WithIndices _ xs) = do axs <- TA.toArray xs xs' <- TA.fromArray axs :: Effect (ArrayView a) axs' <- TA.toArray xs' @@ -208,7 +208,7 @@ allAreFilledTests :: Ref Int -> Effect Unit allAreFilledTests count = overAll count allAreFilled where allAreFilled :: forall a b t. TestableArrayF a b D0 t Result - allAreFilled (WithOffset _ xs) = do + allAreFilled (WithIndices _ xs) = do e <- TA.at xs 0 let x = fromMaybe zero e l = TA.length xs @@ -221,7 +221,7 @@ setSingletonIsEqTests :: Ref Int -> Effect Unit setSingletonIsEqTests count = overAll count setSingletonIsEq where setSingletonIsEq :: forall a b t. TestableArrayF a b D1 t Result - setSingletonIsEq (WithOffset os xs) = do + setSingletonIsEq (WithIndices os xs) = do e <- TA.at xs 0 case e of Nothing -> pure Success @@ -237,7 +237,7 @@ allImpliesAnyTests :: Ref Int -> Effect Unit allImpliesAnyTests count = overAll count allImpliesAny where allImpliesAny :: forall a b t. TestableArrayF a b D0 t Result - allImpliesAny (WithOffset _ xs) = do + allImpliesAny (WithIndices _ xs) = do let pred x = x /= zero all'' <- TA.all pred xs let all' = all'' "All don't satisfy the predicate" @@ -251,7 +251,7 @@ filterImpliesAllTests :: Ref Int -> Effect Unit filterImpliesAllTests count = overAll count filterImpliesAll where filterImpliesAll :: forall a b t. TestableArrayF a b D0 t Result - filterImpliesAll (WithOffset _ xs) = do + filterImpliesAll (WithIndices _ xs) = do let pred x = x /= zero ys <- TA.filter pred xs all' <- TA.all pred ys @@ -263,7 +263,7 @@ filterIsTotalTests :: Ref Int -> Effect Unit filterIsTotalTests count = overAll count filterIsTotal where filterIsTotal :: forall a b t. TestableArrayF a b D0 t Result - filterIsTotal (WithOffset _ xs) = do + filterIsTotal (WithIndices _ xs) = do let pred x = x /= zero ys <- TA.filter pred xs zs <- TA.filter (not pred) ys @@ -276,7 +276,7 @@ filterIsIdempotentTests :: Ref Int -> Effect Unit filterIsIdempotentTests count = overAll count filterIsIdempotent where filterIsIdempotent :: forall a b t. TestableArrayF a b D0 t Result - filterIsIdempotent (WithOffset _ xs) = do + filterIsIdempotent (WithIndices _ xs) = do let pred x = x /= zero ys <- TA.filter pred xs zs <- TA.filter pred ys @@ -285,19 +285,19 @@ filterIsIdempotentTests count = overAll count filterIsIdempotent pure $ azs === ays -withOffsetHasIndexTests :: Ref Int -> Effect Unit -withOffsetHasIndexTests count = overAll1 count withOffsetHasIndex +withIndicesHasIndexTests :: Ref Int -> Effect Unit +withIndicesHasIndexTests count = overAll1 count withIndicesHasIndex where - withOffsetHasIndex :: forall a b t. TestableArrayF a b D5 t Result - withOffsetHasIndex (WithOffset os xs) = pure $ + withIndicesHasIndex :: forall a b t. TestableArrayF a b D5 t Result + withIndicesHasIndex (WithIndices os xs) = pure $ Array.all (TA.hasIndex xs) os "All doesn't have index of itself" -withOffsetElemTests :: Ref Int -> Effect Unit -withOffsetElemTests count = overAll1 count withOffsetElem +withIndicesElemTests :: Ref Int -> Effect Unit +withIndicesElemTests count = overAll1 count withIndicesElem where - withOffsetElem :: forall a b t. TestableArrayF a b D5 t Result - withOffsetElem (WithOffset os xs) = do + withIndicesElem :: forall a b t. TestableArrayF a b D5 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" @@ -308,7 +308,7 @@ anyImpliesFindTests :: Ref Int -> Effect Unit anyImpliesFindTests count = overAll count anyImpliesFind where anyImpliesFind :: forall a b t. TestableArrayF a b D0 t Result - anyImpliesFind (WithOffset _ xs) = do + anyImpliesFind (WithIndices _ xs) = do let pred x = x /= zero a <- TA.any pred xs let p = a "All don't satisfy the predicate" @@ -326,7 +326,7 @@ findIndexImpliesAtTests :: Ref Int -> Effect Unit findIndexImpliesAtTests count = overAll count findIndexImpliesAt where findIndexImpliesAt :: forall a b t. TestableArrayF a b D0 t Result - findIndexImpliesAt (WithOffset _ xs) = do + findIndexImpliesAt (WithIndices _ xs) = do let pred x _ = x /= zero mo <- TA.findIndex pred xs case mo of @@ -343,7 +343,7 @@ indexOfImpliesAtTests :: Ref Int -> Effect Unit indexOfImpliesAtTests count = overAll count indexOfImpliesAt where indexOfImpliesAt :: forall a b t. TestableArrayF a b D1 t Result - indexOfImpliesAt (WithOffset _ xs) = do + indexOfImpliesAt (WithIndices _ xs) = do e <- TA.at xs 0 case e of Nothing -> pure Success @@ -360,7 +360,7 @@ lastIndexOfImpliesAtTests :: Ref Int -> Effect Unit lastIndexOfImpliesAtTests count = overAll count lastIndexOfImpliesAt where lastIndexOfImpliesAt :: forall a b t. TestableArrayF a b D0 t Result - lastIndexOfImpliesAt (WithOffset _ xs) = do + lastIndexOfImpliesAt (WithIndices _ xs) = do e <- TA.at xs 0 case e of Nothing -> pure Success @@ -377,7 +377,7 @@ foldrConsIsToArrayTests :: Ref Int -> Effect Unit foldrConsIsToArrayTests count = overAll count foldrConsIsToArray where foldrConsIsToArray :: forall a b t. TestableArrayF a b D0 t Result - foldrConsIsToArray (WithOffset _ xs) = do + foldrConsIsToArray (WithIndices _ xs) = do axs <- TA.toArray xs rxs <- TA.foldr Array.cons [] xs pure $ rxs === axs @@ -387,7 +387,7 @@ foldlSnocIsToArrayTests :: Ref Int -> Effect Unit foldlSnocIsToArrayTests count = overAll count foldlSnocIsToArray where foldlSnocIsToArray :: forall a b t. TestableArrayF a b D0 t Result - foldlSnocIsToArray (WithOffset _ xs) = do + foldlSnocIsToArray (WithIndices _ xs) = do axs <- TA.toArray xs rxs <- TA.foldl Array.snoc [] xs pure $ rxs === axs @@ -397,7 +397,7 @@ mapIdentityIsIdentityTests :: Ref Int -> Effect Unit mapIdentityIsIdentityTests count = overAll count mapIdentityIsIdentity where mapIdentityIsIdentity :: forall a b t. TestableArrayF a b D0 t Result - mapIdentityIsIdentity (WithOffset _ xs) = do + mapIdentityIsIdentity (WithIndices _ xs) = do axs <- TA.toArray xs mxs <- TA.toArray (TA.map identity xs) pure $ axs === mxs @@ -407,7 +407,7 @@ traverseSnocIsToArrayTests :: Ref Int -> Effect Unit traverseSnocIsToArrayTests count = overAll count traverseSnocIsToArray where traverseSnocIsToArray :: forall a b t. TestableArrayF a b D0 t Result - traverseSnocIsToArray (WithOffset _ xs) = do + traverseSnocIsToArray (WithIndices _ xs) = do ref <- Ref.new [] TA.traverse_ (\x -> void (Ref.modify (\xs' -> Array.snoc xs' x) ref)) xs ys <- Ref.read ref @@ -419,7 +419,7 @@ doubleReverseIsIdentityTests :: Ref Int -> Effect Unit doubleReverseIsIdentityTests count = overAll count doubleReverseIsIdentity where doubleReverseIsIdentity :: forall a b t. TestableArrayF a b D0 t Result - doubleReverseIsIdentity (WithOffset _ xs) = do + doubleReverseIsIdentity (WithIndices _ xs) = do axs <- TA.toArray xs TA.reverse xs TA.reverse xs @@ -431,7 +431,7 @@ reverseIsArrayReverseTests :: Ref Int -> Effect Unit reverseIsArrayReverseTests count = overAll count reverseIsArrayReverse where reverseIsArrayReverse :: forall a b t. TestableArrayF a b D0 t Result - reverseIsArrayReverse (WithOffset _ xs) = do + reverseIsArrayReverse (WithIndices _ xs) = do axs <- TA.toArray xs TA.reverse xs rxs <- TA.toArray xs @@ -442,7 +442,7 @@ sortIsIdempotentTests :: Ref Int -> Effect Unit sortIsIdempotentTests count = overAll count sortIsIdempotent where sortIsIdempotent :: forall a b t. TestableArrayF a b D0 t Result - sortIsIdempotent (WithOffset _ xs) = do + sortIsIdempotent (WithIndices _ xs) = do TA.sort xs ys <- TA.toArray xs TA.sort xs @@ -454,7 +454,7 @@ sortIsArraySortTests :: Ref Int -> Effect Unit sortIsArraySortTests count = overAll count sortIsArraySort where sortIsArraySort :: forall a b t. TestableArrayF a b D0 t Result - sortIsArraySort (WithOffset _ xs) = do + sortIsArraySort (WithIndices _ xs) = do axs <- TA.toArray xs let ys = Array.sort axs TA.sort xs @@ -466,7 +466,7 @@ toStringIsJoinWithCommaTests :: Ref Int -> Effect Unit toStringIsJoinWithCommaTests count = overAll count toStringIsJoinWithComma where toStringIsJoinWithComma :: forall a b t. TestableArrayF a b D0 t Result - toStringIsJoinWithComma (WithOffset _ xs) = do + toStringIsJoinWithComma (WithIndices _ xs) = do s1 <- TA.join "," xs s2 <- TA.toString xs pure $ s1 === s2 @@ -476,7 +476,7 @@ setTypedOfSubArrayIsIdentityTests :: Ref Int -> Effect Unit setTypedOfSubArrayIsIdentityTests count = overAll count setTypedOfSubArrayIsIdentity where setTypedOfSubArrayIsIdentity :: forall a b t. TestableArrayF a b D0 t Result - setTypedOfSubArrayIsIdentity (WithOffset _ xs) = do + setTypedOfSubArrayIsIdentity (WithIndices _ xs) = do ys <- TA.toArray xs let l = TA.length xs zsSub = TA.subArray 0 l xs @@ -489,7 +489,7 @@ modifyingOriginalMutatesSubArrayTests :: Ref Int -> Effect Unit modifyingOriginalMutatesSubArrayTests count = overAll count modifyingOriginalMutatesSubArray where modifyingOriginalMutatesSubArray :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalMutatesSubArray (WithOffset _ xs) = do + modifyingOriginalMutatesSubArray (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs then pure Success @@ -506,7 +506,7 @@ modifyingSubArrayMutatesOriginalTests :: Ref Int -> Effect Unit modifyingSubArrayMutatesOriginalTests count = overAll count modifyingOriginalMutatesSubArray where modifyingOriginalMutatesSubArray :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalMutatesSubArray (WithOffset _ xs) = do + modifyingOriginalMutatesSubArray (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs then pure Success @@ -523,7 +523,7 @@ modifyingOriginalMutatesSubArrayZeroTests :: Ref Int -> Effect Unit modifyingOriginalMutatesSubArrayZeroTests count = overAll count modifyingOriginalMutatesSubArrayZero where modifyingOriginalMutatesSubArrayZero :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalMutatesSubArrayZero (WithOffset _ xs) = do + modifyingOriginalMutatesSubArrayZero (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs then pure Success @@ -540,7 +540,7 @@ modifyingSubArrayMutatesOriginalZeroTests :: Ref Int -> Effect Unit modifyingSubArrayMutatesOriginalZeroTests count = overAll count modifyingSubArrayMutatesOriginalZero where modifyingSubArrayMutatesOriginalZero :: forall a b t. TestableArrayF a b D0 t Result - modifyingSubArrayMutatesOriginalZero (WithOffset _ xs) = do + modifyingSubArrayMutatesOriginalZero (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs then pure Success @@ -557,7 +557,7 @@ modifyingOriginalMutatesSubArrayAllTests :: Ref Int -> Effect Unit modifyingOriginalMutatesSubArrayAllTests count = overAll count modifyingOriginalMutatesSubArrayAll where modifyingOriginalMutatesSubArrayAll :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalMutatesSubArrayAll (WithOffset _ xs) = do + modifyingOriginalMutatesSubArrayAll (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs then pure Success @@ -574,7 +574,7 @@ modifyingSubArrayMutatesOriginalAllTests :: Ref Int -> Effect Unit modifyingSubArrayMutatesOriginalAllTests count = overAll count modifyingSubArrayMutatesOriginalAll where modifyingSubArrayMutatesOriginalAll :: forall a b t. TestableArrayF a b D0 t Result - modifyingSubArrayMutatesOriginalAll (WithOffset _ xs) = do + modifyingSubArrayMutatesOriginalAll (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs then pure Success @@ -591,7 +591,7 @@ modifyingOriginalMutatesSubArrayPartTests :: Ref Int -> Effect Unit modifyingOriginalMutatesSubArrayPartTests count = overAll count modifyingOriginalMutatesSubArrayPart where modifyingOriginalMutatesSubArrayPart :: forall a b t. TestableArrayF a b D1 t Result - modifyingOriginalMutatesSubArrayPart (WithOffset os xs) = do + modifyingOriginalMutatesSubArrayPart (WithIndices os xs) = do let o = Vec.head os l = TA.length xs zsSub = TA.subArray 0 l xs @@ -608,7 +608,7 @@ modifyingOriginalDoesntMutateSliceTests :: Ref Int -> Effect Unit modifyingOriginalDoesntMutateSliceTests count = overAll count modifyingOriginalDoesntMutateSlice where modifyingOriginalDoesntMutateSlice :: forall a b t. TestableArrayF a b D0 t Result - modifyingOriginalDoesntMutateSlice (WithOffset _ xs) = do + modifyingOriginalDoesntMutateSlice (WithIndices _ xs) = do axs <- TA.toArray xs if Array.all (eq zero) axs then pure Success @@ -625,7 +625,7 @@ modifyingOriginalDoesntMutateSlicePartTests :: Ref Int -> Effect Unit modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOriginalDoesntMutateSlicePart where modifyingOriginalDoesntMutateSlicePart :: forall a b t. TestableArrayF a b D1 t Result - modifyingOriginalDoesntMutateSlicePart (WithOffset os xs) = do + modifyingOriginalDoesntMutateSlicePart (WithIndices os xs) = do let l = TA.length xs axs <- TA.toArray =<< TA.slice 0 l xs let o = Vec.head os @@ -644,7 +644,7 @@ modifyingOriginalDoesntMutateSlicePart2Tests :: Ref Int -> Effect Unit modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOriginalDoesntMutateSlicePart2 where modifyingOriginalDoesntMutateSlicePart2 :: forall a b t. TestableArrayF a b D1 t Result - modifyingOriginalDoesntMutateSlicePart2 (WithOffset os xs) = do + modifyingOriginalDoesntMutateSlicePart2 (WithIndices os xs) = do let o = Vec.head os l = TA.length xs axs <- TA.toArray =<< TA.slice o l xs @@ -663,7 +663,7 @@ copyWithinSelfIsIdentityTests :: Ref Int -> Effect Unit copyWithinSelfIsIdentityTests count = overAll count copyWithinSelfIsIdentity where copyWithinSelfIsIdentity :: forall a b t. TestableArrayF a b D0 t Result - copyWithinSelfIsIdentity (WithOffset _ xs) = do + copyWithinSelfIsIdentity (WithIndices _ xs) = do ys <- TA.toArray xs TA.copyWithin xs 0 0 (Just (TA.length xs)) zs <- TA.toArray xs @@ -674,7 +674,7 @@ copyWithinIsSliceTests :: Ref Int -> Effect Unit copyWithinIsSliceTests count = overAll count copyWithinIsSlice where copyWithinIsSlice :: forall a b t. TestableArrayF a b D1 t Result - copyWithinIsSlice (WithOffset os xs) = do + copyWithinIsSlice (WithIndices os xs) = do let o = Vec.head os l = TA.length xs ys <- TA.toArray =<< TA.slice o l xs @@ -688,7 +688,7 @@ copyWithinViaSetTypedTests :: Ref Int -> Effect Unit copyWithinViaSetTypedTests count = overAll count copyWithinViaSetTyped where copyWithinViaSetTyped :: forall a b t. TestableArrayF a b D1 t Result - copyWithinViaSetTyped (WithOffset os xs) = do + copyWithinViaSetTyped (WithIndices os xs) = do let o = Vec.head os txs <- TA.toArray xs xs' <- TA.fromArray txs :: Effect (ArrayView a) From f224bbf120f3c858a65585f8dc1accac23087be6 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Thu, 31 Jan 2019 09:16:34 +0100 Subject: [PATCH 31/79] Execute polyFill always --- src/Data/ArrayBuffer/Typed.js | 5 ++++- src/Data/ArrayBuffer/Typed.purs | 6 +----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index d7e2785..cf2d733 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -1,7 +1,9 @@ "use strict"; -exports.polyFill = function polyFill () { + +// 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 @@ -15,6 +17,7 @@ exports.polyFill = function polyFill () { } }; +polyFill(); // module Data.ArrayBuffer.Typed diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index 9dd6b15..e28c7c7 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -30,8 +30,7 @@ module Data.ArrayBuffer.Typed - ( polyFill - , Index, Length + ( Index, Length , buffer, byteOffset, byteLength, length , class TypedArray , create, whole, remainder, part, empty, fromArray @@ -65,9 +64,6 @@ import Prelude (Unit, flip, pure, ($), (&&), (*), (*>), (-), (<$>), (<<<), (<=), import Type.Proxy (Proxy(..)) --- | Lightweight polyfill for ie - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill -foreign import polyFill :: Effect Unit - -- | `ArrayBuffer` being mapped by the typed array. foreign import buffer :: forall a. ArrayView a -> ArrayBuffer From 70f7ad4f46e245df3ccd95234a9ac4e287048c05 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Fri, 1 Feb 2019 14:33:20 +0100 Subject: [PATCH 32/79] compare/eq, unsafe Show/Ord/Eq/Semigroup/Monoid --- bower.json | 7 +- src/Data/ArrayBuffer/Typed.purs | 12 ++- src/Data/ArrayBuffer/Typed/Gen.purs | 4 +- src/Data/ArrayBuffer/Typed/Unsafe.purs | 32 ++++++++ test/Properties.purs | 2 + test/Properties/DataView.purs | 2 +- test/Properties/Typed/Laws.purs | 104 +++++++++++++++++++++++++ 7 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 src/Data/ArrayBuffer/Typed/Unsafe.purs create mode 100644 test/Properties/Typed/Laws.purs diff --git a/bower.json b/bower.json index 64e11d0..56b7442 100644 --- a/bower.json +++ b/bower.json @@ -20,12 +20,13 @@ "purescript-typelevel": "^4.0.0", "purescript-uint": "^5.1.0", "purescript-sized-vectors": "^3.1.0", - "purescript-float32": "^0.0.1" + "purescript-partial": "^2.0.0", + "purescript-float32": "~0.1.1" }, "devDependencies": { "purescript-debug": "^4.0.0", "purescript-quickcheck": "^5.0.0", - "purescript-partial": "^2.0.0", - "purescript-quickcheck-combinators": "^0.1.0" + "purescript-quickcheck-combinators": "~0.1.0", + "purescript-quickcheck-laws": "^4.0.0" } } diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index e28c7c7..aa14ef6 100644 --- a/src/Data/ArrayBuffer/Typed.purs +++ b/src/Data/ArrayBuffer/Typed.purs @@ -32,6 +32,7 @@ module Data.ArrayBuffer.Typed ( Index, Length , buffer, byteOffset, byteLength, length + , compare, eq , class TypedArray , create, whole, remainder, part, empty, fromArray , fill, set, setTyped, copyWithin @@ -60,7 +61,8 @@ import Data.UInt (UInt) import Effect (Effect) import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4, mkEffectFn2, mkEffectFn3, runEffectFn1, runEffectFn2, runEffectFn3, runEffectFn4) import Effect.Unsafe (unsafePerformEffect) -import Prelude (Unit, flip, pure, ($), (&&), (*), (*>), (-), (<$>), (<<<), (<=), (>=)) +import Prelude (class Eq, class Ord, Ordering, Unit, flip, pure, ($), (&&), (*), (*>), (-), (<$>), (<*>), (<<<), (<=), (>=)) +import Prelude as Prelude import Type.Proxy (Proxy(..)) @@ -390,3 +392,11 @@ infixl 3 at as ! 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. +compare :: forall a t. TypedArray a t => Ord t => ArrayView a -> ArrayView a -> Effect Ordering +compare a b = Prelude.compare <$> toArray a <*> toArray b + +-- | Equality test for typed arrays. +eq :: forall a t. TypedArray a t => Eq t => ArrayView a -> ArrayView a -> Effect Boolean +eq a b = Prelude.eq <$> toArray a <*> toArray b diff --git a/src/Data/ArrayBuffer/Typed/Gen.purs b/src/Data/ArrayBuffer/Typed/Gen.purs index 4470a12..913c880 100644 --- a/src/Data/ArrayBuffer/Typed/Gen.purs +++ b/src/Data/ArrayBuffer/Typed/Gen.purs @@ -6,7 +6,7 @@ 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.Float32 (Float32, fromNumber) as F +import Data.Float32 (Float32, fromNumber') as F import Data.Generic.Rep (class Generic) import Data.Maybe (Maybe(..)) import Data.Typelevel.Num (class Nat, toInt') @@ -51,7 +51,7 @@ genInt32 :: forall m. MonadGen m => m Int genInt32 = chooseInt bottom top genFloat32 :: forall m. MonadGen m => m F.Float32 -genFloat32 = F.fromNumber <$> chooseFloat (-3.40282347e+38) 3.40282347e+38 +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) diff --git a/src/Data/ArrayBuffer/Typed/Unsafe.purs b/src/Data/ArrayBuffer/Typed/Unsafe.purs new file mode 100644 index 0000000..b4714d9 --- /dev/null +++ b/src/Data/ArrayBuffer/Typed/Unsafe.purs @@ -0,0 +1,32 @@ +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 Effect.Unsafe (unsafePerformEffect) +import Prelude (class Eq, class Monoid, class Ord, class Semigroup, class Show, bind, discard, pure, void, ($), (+), (<>)) + +newtype AV a t = AV (ArrayView a) + +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 diff --git a/test/Properties.purs b/test/Properties.purs index 77f0d14..6bf5407 100644 --- a/test/Properties.purs +++ b/test/Properties.purs @@ -6,6 +6,7 @@ import Effect.Ref (new, read) as Ref import Prelude (Unit, bind, discard, ($), (<>), (*), show) import Test.Properties.DataView (dataViewTests) import Test.Properties.TypedArray (typedArrayTests) +import Test.Properties.Typed.Laws (typedArrayLaws) propertiesTests :: Effect Unit @@ -14,6 +15,7 @@ propertiesTests = do count <- Ref.new 0 log " - TypedArray Tests:" typedArrayTests count + typedArrayLaws count c <- Ref.read count log $ " - Verified " <> show c <> " properties, generating " <> show (c * 9 * 100) <> " test cases." diff --git a/test/Properties/DataView.purs b/test/Properties/DataView.purs index 3a13210..cee9459 100644 --- a/test/Properties/DataView.purs +++ b/test/Properties/DataView.purs @@ -47,7 +47,7 @@ type TestableViewF a name b n 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 count f = do - void (Ref.modify (\x -> x + 1) count) + void (Ref.modify (_ + 1) count) log " - Uint32" quickCheckGen $ let f' :: TestableViewF Uint32 "Uint32" D4 n UInt q diff --git a/test/Properties/Typed/Laws.purs b/test/Properties/Typed/Laws.purs new file mode 100644 index 0000000..8a6f02b --- /dev/null +++ b/test/Properties/Typed/Laws.purs @@ -0,0 +1,104 @@ +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.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.Gen (Gen) +import Test.QuickCheck.Laws.Data (checkEq, checkMonoid, checkOrd, checkSemigroup) +import Type.Prelude (Proxy(..)) + +newtype A a = A a + +foreign import data ArrayElt :: ArrayViewType -> Type -> Type + +class ArrayEl (a :: ArrayViewType) (t :: Type) where + arb :: Proxy (ArrayView a) -> Gen t + +instance arrayElUint8Clamped :: ArrayEl Uint8Clamped UInt where + arb _ = genUint8 +instance arrayElUint32 :: ArrayEl Uint32 UInt where + arb _ = genUint32 +instance arrayElUint16 :: ArrayEl Uint16 UInt where + arb _ = genUint16 +instance arrayElUint8 :: ArrayEl Uint8 UInt where + arb _ = genUint8 +instance arrayElInt32 :: ArrayEl Int32 Int where + arb _ = genInt32 +instance arrayElInt16 :: ArrayEl Int16 Int where + arb _ = genInt16 +instance arrayElInt8 :: ArrayEl Int8 Int where + arb _ = genInt8 +instance arrayElFloat32 :: ArrayEl Float32 F.Float32 where + arb _ = genFloat32 +instance arrayElFloat64 :: ArrayEl Float64 Number where + arb _ = genFloat64 + +instance arbitraryAAV :: (TypedArray a t, ArrayEl a t) => Arbitrary (A (AV a t)) where + arbitrary = (A <<< AV) <$> genTypedArray (arb (Proxy :: Proxy (ArrayView a))) + +derive newtype instance eqA :: Eq t => Eq (A t) +derive newtype instance ordA :: Ord t => Ord (A t) +derive newtype instance semigroupA :: Semigroup t => Semigroup (A t) +derive newtype instance monoidA :: Monoid t => Monoid (A t) + +typedArrayLaws :: Ref Int -> Effect Unit +typedArrayLaws count = do + do + let f = checkEq + void $ Ref.modify (_ + 1) count + f (Proxy :: Proxy (A (AV Float32 F.Float32))) + f (Proxy :: Proxy (A (AV Float64 Number))) + f (Proxy :: Proxy (A (AV Int16 Int))) + f (Proxy :: Proxy (A (AV Int32 Int))) + f (Proxy :: Proxy (A (AV Int8 Int))) + f (Proxy :: Proxy (A (AV Uint16 UInt))) + f (Proxy :: Proxy (A (AV Uint32 UInt))) + f (Proxy :: Proxy (A (AV Uint8 UInt))) + f (Proxy :: Proxy (A (AV Uint8Clamped UInt))) + + do + let f = checkOrd + void $ Ref.modify (_ + 1) count + f (Proxy :: Proxy (A (AV Float32 F.Float32))) + f (Proxy :: Proxy (A (AV Float64 Number))) + f (Proxy :: Proxy (A (AV Int16 Int))) + f (Proxy :: Proxy (A (AV Int32 Int))) + f (Proxy :: Proxy (A (AV Int8 Int))) + f (Proxy :: Proxy (A (AV Uint16 UInt))) + f (Proxy :: Proxy (A (AV Uint32 UInt))) + f (Proxy :: Proxy (A (AV Uint8 UInt))) + f (Proxy :: Proxy (A (AV Uint8Clamped UInt))) + + do + let f = checkSemigroup + void $ Ref.modify (_ + 1) count + f (Proxy :: Proxy (A (AV Float32 F.Float32))) + f (Proxy :: Proxy (A (AV Float64 Number))) + f (Proxy :: Proxy (A (AV Int16 Int))) + f (Proxy :: Proxy (A (AV Int32 Int))) + f (Proxy :: Proxy (A (AV Int8 Int))) + f (Proxy :: Proxy (A (AV Uint16 UInt))) + f (Proxy :: Proxy (A (AV Uint32 UInt))) + f (Proxy :: Proxy (A (AV Uint8 UInt))) + f (Proxy :: Proxy (A (AV Uint8Clamped UInt))) + + do + let f = checkMonoid + void $ Ref.modify (_ + 1) count + f (Proxy :: Proxy (A (AV Float32 F.Float32))) + f (Proxy :: Proxy (A (AV Float64 Number))) + f (Proxy :: Proxy (A (AV Int16 Int))) + f (Proxy :: Proxy (A (AV Int32 Int))) + f (Proxy :: Proxy (A (AV Int8 Int))) + f (Proxy :: Proxy (A (AV Uint16 UInt))) + f (Proxy :: Proxy (A (AV Uint32 UInt))) + f (Proxy :: Proxy (A (AV Uint8 UInt))) + f (Proxy :: Proxy (A (AV Uint8Clamped UInt))) From 87e3d4f248f2735fa9c8e722d68736fe677393e7 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Fri, 1 Feb 2019 14:38:32 +0100 Subject: [PATCH 33/79] Add travis script --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .travis.yml 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 From ebd2b1045a05ee59ccb7c6ed16521485b3e54886 Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Wed, 6 Feb 2019 17:59:47 -0700 Subject: [PATCH 34/79] no need to distinguish DataView class and BinaryValue class --- src/Data/ArrayBuffer/DataView.purs | 41 +++++--------------------- src/Data/ArrayBuffer/DataView/Gen.purs | 6 ++-- src/Data/ArrayBuffer/ValueMapping.purs | 13 ++++++++ 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/Data/ArrayBuffer/DataView.purs b/src/Data/ArrayBuffer/DataView.purs index 2637003..b88f344 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -7,8 +7,6 @@ module Data.ArrayBuffer.DataView , buffer , byteLength , byteOffset - , class DataView - , class ShowArrayViewType , get , getBE , getFloat32be @@ -48,8 +46,8 @@ module Data.ArrayBuffer.DataView , whole ) where -import Data.ArrayBuffer.Types (ArrayBuffer, ByteLength, ByteOffset, DataView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, Uint8Clamped, kind ArrayViewType) -import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerValue) +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.Float32 (Float32) as F import Data.Maybe (Maybe) import Data.Nullable (Nullable, toMaybe) @@ -96,29 +94,6 @@ instance eqEndian :: Eq Endian where eq BE BE = true eq _ _ = false -class BinaryValue a t <= DataView (a :: ArrayViewType) t | a -> t - -instance dataViewUint8Clamped :: DataView Uint8Clamped UInt -instance dataViewUint32 :: DataView Uint32 UInt -instance dataViewUint16 :: DataView Uint16 UInt -instance dataViewUint8 :: DataView Uint8 UInt -instance dataViewInt32 :: DataView Int32 Int -instance dataViewInt16 :: DataView Int16 Int -instance dataViewInt8 :: DataView Int8 Int -instance dataViewFloat32 :: DataView Float32 F.Float32 -instance dataViewFloat64 :: DataView 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" -instance showArrayViewTypeViewUint8 :: ShowArrayViewType Uint8 "Uint8" -instance showArrayViewTypeViewInt32 :: ShowArrayViewType Int32 "Int32" -instance showArrayViewTypeViewInt16 :: ShowArrayViewType Int16 "Int16" -instance showArrayViewTypeViewInt8 :: ShowArrayViewType Int8 "Int8" -instance showArrayViewTypeViewFloat32 :: ShowArrayViewType Float32 "Float32" -instance showArrayViewTypeViewFloat64 :: ShowArrayViewType Float64 "Float64" getter :: forall t. { functionName :: String @@ -141,7 +116,7 @@ foreign import getterImpl :: forall t get :: forall a name t b - . DataView a t + . BinaryValue a t => BytesPerValue a b => ShowArrayViewType a name => IsSymbol name @@ -157,7 +132,7 @@ get endian prx = } getBE :: forall a name t b - . DataView a t + . BinaryValue a t => BytesPerValue a b => ShowArrayViewType a name => IsSymbol name @@ -166,7 +141,7 @@ getBE :: forall a name t b getBE = get BE getLE :: forall a name t b - . DataView a t + . BinaryValue a t => BytesPerValue a b => ShowArrayViewType a name => IsSymbol name @@ -188,7 +163,7 @@ foreign import setterImpl :: forall t set :: forall a name t b - . DataView a t + . BinaryValue a t => BytesPerValue a b => ShowArrayViewType a name => IsSymbol name @@ -262,7 +237,7 @@ getFloat64le = getLE (AProxy :: AProxy Float64) -- | Store big-endian value at a certain index in a `DataView`. setBE :: forall a name t b - . DataView a t + . BinaryValue a t => BytesPerValue a b => ShowArrayViewType a name => IsSymbol name @@ -272,7 +247,7 @@ setBE = set BE -- | Store little-endian value at a certain index in a `DataView`. setLE :: forall a name t b - . DataView a t + . BinaryValue a t => BytesPerValue a b => ShowArrayViewType a name => IsSymbol name diff --git a/src/Data/ArrayBuffer/DataView/Gen.purs b/src/Data/ArrayBuffer/DataView/Gen.purs index 3423d5f..0d61948 100644 --- a/src/Data/ArrayBuffer/DataView/Gen.purs +++ b/src/Data/ArrayBuffer/DataView/Gen.purs @@ -6,9 +6,9 @@ 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, class DataView) +import Data.ArrayBuffer.DataView (whole, byteLength) import Data.ArrayBuffer.Types (DataView, ByteOffset, kind ArrayViewType) -import Data.ArrayBuffer.ValueMapping (class BytesPerValue) +import Data.ArrayBuffer.ValueMapping (class BytesPerValue, class BinaryValue) import Data.Maybe (Maybe(Just)) import Data.Typelevel.Num (class Nat, toInt') import Data.Unfoldable (replicateA) @@ -34,7 +34,7 @@ genWithOffsetAndValue :: forall m n a b t => MonadRec m => Nat n => BytesPerValue a b - => DataView a t + => BinaryValue a t => Nat b => m DataView -- ^ Assumes generated length is at least the minimum length of one value -> m t diff --git a/src/Data/ArrayBuffer/ValueMapping.purs b/src/Data/ArrayBuffer/ValueMapping.purs index c17d677..87bc256 100644 --- a/src/Data/ArrayBuffer/ValueMapping.purs +++ b/src/Data/ArrayBuffer/ValueMapping.purs @@ -35,3 +35,16 @@ instance binaryValueInt16 :: BinaryValue Int16 Int 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" +instance showArrayViewTypeViewUint16 :: ShowArrayViewType Uint16 "Uint16" +instance showArrayViewTypeViewUint8 :: ShowArrayViewType Uint8 "Uint8" +instance showArrayViewTypeViewInt32 :: ShowArrayViewType Int32 "Int32" +instance showArrayViewTypeViewInt16 :: ShowArrayViewType Int16 "Int16" +instance showArrayViewTypeViewInt8 :: ShowArrayViewType Int8 "Int8" +instance showArrayViewTypeViewFloat32 :: ShowArrayViewType Float32 "Float32" +instance showArrayViewTypeViewFloat64 :: ShowArrayViewType Float64 "Float64" From c99c202215668e0a113a730240d1306a792c3a8b Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Wed, 6 Feb 2019 18:07:54 -0700 Subject: [PATCH 35/79] fixing tests --- test/Properties/DataView.purs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Properties/DataView.purs b/test/Properties/DataView.purs index cee9459..a3e08b4 100644 --- a/test/Properties/DataView.purs +++ b/test/Properties/DataView.purs @@ -7,7 +7,7 @@ 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) +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) @@ -37,10 +37,10 @@ type TestableViewF a name b n t q = => Ord t => Semiring t => BytesPerValue a b - => DV.ShowArrayViewType a name + => BinaryValue a t + => ShowArrayViewType a name => IsSymbol name => Nat b - => DV.DataView a t => WithOffsetAndValue n a t -> q From b26e575c438dae5b241f94d2b60dad609443db80 Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Sat, 14 Sep 2019 21:18:32 -0700 Subject: [PATCH 36/79] upgrading deps - waiting on sized-vectors to get pulled --- bower.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bower.json b/bower.json index 56b7442..08731c0 100644 --- a/bower.json +++ b/bower.json @@ -14,19 +14,19 @@ "dependencies": { "purescript-functions": "^4.0.0", "purescript-arraybuffer-types": "^2.0.0", - "purescript-maybe": "^4.0.0", - "purescript-effect": "^2.0.0", - "purescript-nullable": "^4.1.0", - "purescript-typelevel": "^4.0.0", - "purescript-uint": "^5.1.0", - "purescript-sized-vectors": "^3.1.0", - "purescript-partial": "^2.0.0", + "purescript-maybe": "^4.0.1", + "purescript-effect": "^2.0.1", + "purescript-nullable": "^4.1.1", + "purescript-typelevel": "^6.0.0", + "purescript-uint": "^5.1.1", + "purescript-sized-vectors": "git://github.com/athanclark/purescript-sized-vectors.git#4fcf13f5ed949e95242b99bcace1648e29bbcbad", + "purescript-partial": "^2.0.1", "purescript-float32": "~0.1.1" }, "devDependencies": { "purescript-debug": "^4.0.0", - "purescript-quickcheck": "^5.0.0", - "purescript-quickcheck-combinators": "~0.1.0", - "purescript-quickcheck-laws": "^4.0.0" + "purescript-quickcheck": "^6.1.0", + "purescript-quickcheck-combinators": "~0.1.2", + "purescript-quickcheck-laws": "^5.0.1" } } From 9682a2519675296005a906db1da3857b4f93576f Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Sun, 15 Sep 2019 17:31:11 -0700 Subject: [PATCH 37/79] generic instance for AV --- src/Data/ArrayBuffer/Typed/Unsafe.purs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Data/ArrayBuffer/Typed/Unsafe.purs b/src/Data/ArrayBuffer/Typed/Unsafe.purs index b4714d9..3075d04 100644 --- a/src/Data/ArrayBuffer/Typed/Unsafe.purs +++ b/src/Data/ArrayBuffer/Typed/Unsafe.purs @@ -4,11 +4,14 @@ import Data.ArrayBuffer.Typed (class TypedArray, toString) import Data.ArrayBuffer.Typed as TA import Data.ArrayBuffer.Types (ArrayView) import Data.Maybe (Maybe(..)) +import Data.Generic.Rep (class Generic) import Effect.Unsafe (unsafePerformEffect) import Prelude (class Eq, class Monoid, class Ord, class Semigroup, class Show, bind, discard, pure, void, ($), (+), (<>)) 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 From 0adc84d8d33aaa1deda2828e68926d2d8b093f81 Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Sat, 5 Oct 2019 14:51:13 -0700 Subject: [PATCH 38/79] avoiding sized-vector dependency --- bower.json | 1 - src/Data/ArrayBuffer/DataView/Gen.purs | 12 +++--------- src/Data/ArrayBuffer/Typed/Gen.purs | 12 +++--------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/bower.json b/bower.json index 08731c0..b8bb3f5 100644 --- a/bower.json +++ b/bower.json @@ -19,7 +19,6 @@ "purescript-nullable": "^4.1.1", "purescript-typelevel": "^6.0.0", "purescript-uint": "^5.1.1", - "purescript-sized-vectors": "git://github.com/athanclark/purescript-sized-vectors.git#4fcf13f5ed949e95242b99bcace1648e29bbcbad", "purescript-partial": "^2.0.1", "purescript-float32": "~0.1.1" }, diff --git a/src/Data/ArrayBuffer/DataView/Gen.purs b/src/Data/ArrayBuffer/DataView/Gen.purs index 0d61948..441851a 100644 --- a/src/Data/ArrayBuffer/DataView/Gen.purs +++ b/src/Data/ArrayBuffer/DataView/Gen.purs @@ -1,6 +1,6 @@ module Data.ArrayBuffer.DataView.Gen where -import Prelude ((<$>), bind, ($), (<=), (-), pure) +import Prelude ((<$>), bind, (<=), (-), pure) import Control.Monad.Gen (suchThat) import Control.Monad.Gen.Class (class MonadGen, chooseInt) @@ -9,12 +9,8 @@ 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.Maybe (Maybe(Just)) import Data.Typelevel.Num (class Nat, toInt') import Data.Unfoldable (replicateA) -import Data.Vec (Vec) -import Data.Vec (fromArray) as Vec -import Partial.Unsafe (unsafePartial) import Type.Proxy (Proxy(..)) @@ -27,7 +23,7 @@ genDataView = whole <$> genArrayBuffer -- | For generating some set of offsets residing inside the generated array, with some computable value data WithOffsetAndValue n (a :: ArrayViewType) t = - WithOffsetAndValue (Vec n ByteOffset) t DataView + WithOffsetAndValue (Array ByteOffset) t DataView genWithOffsetAndValue :: forall m n a b t . MonadGen m @@ -44,8 +40,6 @@ genWithOffsetAndValue gen genT = do b = toInt' (Proxy :: Proxy b) xs <- gen `suchThat` \xs -> b <= byteLength xs let l = byteLength xs - mos <- replicateA n (chooseInt 0 (l - b)) - let os = unsafePartial $ case Vec.fromArray mos of - Just q -> q + os <- replicateA n (chooseInt 0 (l - b)) t <- genT pure (WithOffsetAndValue os t xs) diff --git a/src/Data/ArrayBuffer/Typed/Gen.purs b/src/Data/ArrayBuffer/Typed/Gen.purs index 913c880..380e28b 100644 --- a/src/Data/ArrayBuffer/Typed/Gen.purs +++ b/src/Data/ArrayBuffer/Typed/Gen.purs @@ -2,23 +2,19 @@ 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.Float32 (Float32, fromNumber') as F import Data.Generic.Rep (class Generic) -import Data.Maybe (Maybe(..)) 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 Data.Vec (Vec) -import Data.Vec (fromArray) as Vec import Effect.Unsafe (unsafePerformEffect) -import Partial.Unsafe (unsafePartial) -import Prelude ((<$>), bind, (/), (-), negate, ($), bottom, pure, top) import Type.Proxy (Proxy(..)) @@ -58,7 +54,7 @@ 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 (Vec n TA.Index) (ArrayView a) +data WithIndices n a = WithIndices (Array TA.Index) (ArrayView a) derive instance genericWithIndices :: Generic (ArrayView a) a' => Generic (WithIndices n a) _ genWithIndices :: forall m n a @@ -70,7 +66,5 @@ genWithIndices gen = do let n = toInt' (Proxy :: Proxy n) xs <- gen let l = TA.length xs - mos <- replicateA n (chooseInt 0 (l - 1)) - let os = unsafePartial $ case Vec.fromArray mos of - Just q -> q + os <- replicateA n (chooseInt 0 (l - 1)) pure (WithIndices os xs) From 525ca98350d8a9822bdede6bf19e429b92ba8281 Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Sat, 5 Oct 2019 15:13:25 -0700 Subject: [PATCH 39/79] fixed tests --- test/Properties/DataView.purs | 6 ++++-- test/Properties/TypedArray.purs | 38 +++++++++++++++++---------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/test/Properties/DataView.purs b/test/Properties/DataView.purs index a3e08b4..58cde67 100644 --- a/test/Properties/DataView.purs +++ b/test/Properties/DataView.purs @@ -3,6 +3,7 @@ module Test.Properties.DataView where import Prelude +import Data.Array.Partial (head) as Array import Data.ArrayBuffer.DataView as DV import Data.ArrayBuffer.DataView.Gen (genDataView, genWithOffsetAndValue, WithOffsetAndValue(..)) import Data.ArrayBuffer.Typed.Gen (genFloat32, genFloat64, genInt16, genInt32, genInt8, genUint16, genUint32, genUint8) @@ -12,7 +13,7 @@ import Data.Maybe (Maybe(..)) import Data.Typelevel.Num (class Nat, D1, D2, D4, D8) import Data.UInt (UInt) import Data.Float32 (Float32) as F -import Data.Vec (head) as Vec +-- import Data.Vec (head) as Vec import Data.Symbol (class IsSymbol) import Effect (Effect) import Effect.Console (log) @@ -20,6 +21,7 @@ import Effect.Ref (Ref) import Effect.Ref as Ref import Effect.Unsafe (unsafePerformEffect) import Test.QuickCheck (class Testable, quickCheckGen, Result, (===)) +import Partial.Unsafe (unsafePartial) @@ -102,7 +104,7 @@ placingAValueIsThereTests endian count = overAll count placingAValueIsThere where placingAValueIsThere :: forall a name b t. TestableViewF a name b D1 t Result placingAValueIsThere (WithOffsetAndValue os t xs) = - let o = Vec.head os + let o = unsafePartial $ Array.head os prx = DV.AProxy :: DV.AProxy a in unsafePerformEffect do _ <- DV.set endian prx xs o t diff --git a/test/Properties/TypedArray.purs b/test/Properties/TypedArray.purs index c9599a0..449f1a1 100644 --- a/test/Properties/TypedArray.purs +++ b/test/Properties/TypedArray.purs @@ -4,7 +4,8 @@ module Test.Properties.TypedArray where import Prelude import Control.Monad.Gen (suchThat) -import Data.Array as Array +import Data.Array (all, cons, drop, length, reverse, slice, snoc, sort, take, unsafeIndex) as Array +import Data.Array.Partial (head) as Array import Data.ArrayBuffer.Typed (class TypedArray) import Data.ArrayBuffer.Typed as TA import Data.ArrayBuffer.Typed.Gen (WithIndices(..), genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8, genWithIndices) @@ -12,13 +13,14 @@ import Data.ArrayBuffer.Types (ArrayView, Float32Array, Float64Array, Int16Array import Data.ArrayBuffer.ValueMapping (class BytesPerValue) import Data.Maybe (Maybe(..), fromMaybe, isJust) import Data.Traversable (traverse) -import Data.Typelevel.Num (class Nat, D0, D1, D2, D5, d0, d1, toInt') -import Data.Vec (head, index) as Vec +import Data.Typelevel.Num (class Nat, D0, D1, D2, D5, toInt') +-- import Data.Vec (head, index) as Vec import Effect (Effect) import Effect.Console (log) import Effect.Ref (Ref) import Effect.Ref as Ref import Effect.Unsafe (unsafePerformEffect) +import Partial.Unsafe (unsafePartial) import Test.QuickCheck (class Testable, Result(..), quickCheckGen, (/==), (), (===)) import Test.QuickCheck.Combinators ((==>), (|=|)) import Test.QuickCheck.Gen (Gen) @@ -155,8 +157,8 @@ subarrayBehavesLikeArraySliceTests count = overAll count f where f :: forall a b t. TestableArrayF a b D2 t Result f (WithIndices os xs) = do - let s = os `Vec.index` d0 - e = os `Vec.index` d1 + 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 @@ -167,8 +169,8 @@ sliceBehavesLikeArraySliceTests count = overAll count f where f :: forall a b t. TestableArrayF a b D2 t Result f (WithIndices os xs) = do - let s = os `Vec.index` d0 - e = os `Vec.index` d1 + 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 @@ -224,12 +226,12 @@ setSingletonIsEqTests count = overAll count setSingletonIsEq setSingletonIsEq (WithIndices os xs) = do e <- TA.at xs 0 case e of - Nothing -> pure Success - Just x -> do - let o = Vec.head os - _ <- TA.set xs (Just o) [x] - e' <- TA.at xs o - pure $ e' === Just x + 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 @@ -592,7 +594,7 @@ modifyingOriginalMutatesSubArrayPartTests count = overAll count modifyingOrigina where modifyingOriginalMutatesSubArrayPart :: forall a b t. TestableArrayF a b D1 t Result modifyingOriginalMutatesSubArrayPart (WithIndices os xs) = do - let o = Vec.head os + let o = unsafePartial $ Array.head os l = TA.length xs zsSub = TA.subArray 0 l xs zs <- TA.toArray zsSub @@ -628,7 +630,7 @@ modifyingOriginalDoesntMutateSlicePartTests count = overAll count modifyingOrigi modifyingOriginalDoesntMutateSlicePart (WithIndices os xs) = do let l = TA.length xs axs <- TA.toArray =<< TA.slice 0 l xs - let o = Vec.head os + let o = unsafePartial $ Array.head os e <- TA.at xs o if Array.all (eq zero) axs || e == Just zero then pure Success @@ -645,7 +647,7 @@ modifyingOriginalDoesntMutateSlicePart2Tests count = overAll count modifyingOrig where modifyingOriginalDoesntMutateSlicePart2 :: forall a b t. TestableArrayF a b D1 t Result modifyingOriginalDoesntMutateSlicePart2 (WithIndices os xs) = do - let o = Vec.head os + let o = unsafePartial $ Array.head os l = TA.length xs axs <- TA.toArray =<< TA.slice o l xs e <- TA.at xs o @@ -675,7 +677,7 @@ copyWithinIsSliceTests count = overAll count copyWithinIsSlice where copyWithinIsSlice :: forall a b t. TestableArrayF a b D1 t Result copyWithinIsSlice (WithIndices os xs) = do - let o = Vec.head os + let o = unsafePartial $ Array.head os l = TA.length xs ys <- TA.toArray =<< TA.slice o l xs TA.copyWithin xs 0 o Nothing @@ -689,7 +691,7 @@ copyWithinViaSetTypedTests count = overAll count copyWithinViaSetTyped where copyWithinViaSetTyped :: forall a b t. TestableArrayF a b D1 t Result copyWithinViaSetTyped (WithIndices os xs) = do - let o = Vec.head os + let o = unsafePartial $ Array.head os txs <- TA.toArray xs xs' <- TA.fromArray txs :: Effect (ArrayView a) let l = TA.length xs' From 7f90bc44247dcbeab70caef5d373833286468266 Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Sat, 12 Oct 2019 19:43:28 -0700 Subject: [PATCH 40/79] arbitrary instance for AV --- src/Data/ArrayBuffer/Typed/Unsafe.purs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Data/ArrayBuffer/Typed/Unsafe.purs b/src/Data/ArrayBuffer/Typed/Unsafe.purs index 3075d04..a536eee 100644 --- a/src/Data/ArrayBuffer/Typed/Unsafe.purs +++ b/src/Data/ArrayBuffer/Typed/Unsafe.purs @@ -6,7 +6,8 @@ import Data.ArrayBuffer.Types (ArrayView) import Data.Maybe (Maybe(..)) import Data.Generic.Rep (class Generic) import Effect.Unsafe (unsafePerformEffect) -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, class Show, bind, discard, pure, void, ($), (+), (<>), (<$>)) +import Test.QuickCheck (class Arbitrary, arbitrary) newtype AV a t = AV (ArrayView a) @@ -33,3 +34,8 @@ instance semigroupArrayView :: TypedArray a t => Semigroup (AV a t) where 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 From d073ea8596330b8ad205370668c017a2e9bd2d7a Mon Sep 17 00:00:00 2001 From: Athan Clark Date: Fri, 28 Feb 2020 15:23:11 -0800 Subject: [PATCH 41/79] fixes #27 --- src/Data/ArrayBuffer/Typed.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/ArrayBuffer/Typed.purs b/src/Data/ArrayBuffer/Typed.purs index aa14ef6..6d17ee1 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, empty, fromArray + , create, whole, remainder, part, part', empty, fromArray , fill, set, setTyped, copyWithin , map, traverse, traverse_, filter , mapWithIndex, traverseWithIndex, traverseWithIndex_, filterWithIndex From d09c77a2470788d0a3e2a05a27dc00fac3749a0c Mon Sep 17 00:00:00 2001 From: James Brock Date: Sun, 25 Apr 2021 23:25:08 +0900 Subject: [PATCH 42/79] bower upgrade deps --- bower.json | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/bower.json b/bower.json index b8bb3f5..9f5755a 100644 --- a/bower.json +++ b/bower.json @@ -12,20 +12,21 @@ "output" ], "dependencies": { - "purescript-functions": "^4.0.0", + "purescript-prelude": "^5.0.0", + "purescript-functions": "^5.0.0", "purescript-arraybuffer-types": "^2.0.0", - "purescript-maybe": "^4.0.1", - "purescript-effect": "^2.0.1", - "purescript-nullable": "^4.1.1", + "purescript-maybe": "^5.0.0", + "purescript-effect": "^3.0.0", + "purescript-nullable": "^5.0.0", "purescript-typelevel": "^6.0.0", - "purescript-uint": "^5.1.1", - "purescript-partial": "^2.0.1", - "purescript-float32": "~0.1.1" + "purescript-uint": "^5.1.4", + "purescript-partial": "^3.0.0", + "purescript-float32": "~0.2.0" }, "devDependencies": { - "purescript-debug": "^4.0.0", - "purescript-quickcheck": "^6.1.0", - "purescript-quickcheck-combinators": "~0.1.2", - "purescript-quickcheck-laws": "^5.0.1" + "purescript-debug": "^5.0.0", + "purescript-quickcheck": "^7.0.0", + "purescript-quickcheck-combinators": "~0.1.3", + "purescript-quickcheck-laws": "^6.0.0" } } From 2fd62973b23407b22446ee2361202f8946f63619 Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 26 Apr 2021 00:12:17 +0900 Subject: [PATCH 43/79] Add spago build for purescript v0.14.1 --- .gitignore | 1 + packages.dhall | 34 ++++++++++++++++++++++++++++++++++ spago.dhall | 27 +++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 packages.dhall create mode 100644 spago.dhall diff --git a/.gitignore b/.gitignore index e4de85d..9cb72c2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ node_modules/ yarn-error.log yarn.lock generated-docs/ +.spago/ diff --git a/packages.dhall b/packages.dhall new file mode 100644 index 0000000..cf30481 --- /dev/null +++ b/packages.dhall @@ -0,0 +1,34 @@ + +let upstream = + https://github.com/purescript/package-sets/releases/download/psc-0.14.1-20210419/packages.dhall sha256:d9a082ffb5c0fabf689574f0680e901ca6f924e01acdbece5eeedd951731375a + +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/zaquest/purescript-uint.git" + , version = "v5.1.4" + } + } + +in upstream // overrides // additions + diff --git a/spago.dhall b/spago.dhall new file mode 100644 index 0000000..ef25406 --- /dev/null +++ b/spago.dhall @@ -0,0 +1,27 @@ +{ name = "arraybuffer" +, dependencies = + [ "arraybuffer-types" + , "arrays" + , "console" + , "effect" + , "float32" + , "foldable-traversable" + , "functions" + , "gen" + , "maybe" + , "nullable" + , "partial" + , "prelude" + , "quickcheck" + , "quickcheck-combinators" + , "quickcheck-laws" + , "refs" + , "tailrec" + , "typelevel" + , "typelevel-prelude" + , "uint" + , "unfoldable" + ] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs", "test/**/*.purs" ] +} From 0a80132331463bd32c11443dcb9cc4c5b32d5bf1 Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 21 Jun 2021 12:46:33 +0900 Subject: [PATCH 44/79] 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 45/79] 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 46/79] 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 47/79] 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 48/79] '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 49/79] 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 50/79] 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 51/79] 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 52/79] 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 53/79] =?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 54/79] 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 55/79] 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 56/79] 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 57/79] 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 58/79] 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 59/79] 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 60/79] =?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 61/79] 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 62/79] =?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 63/79] 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 64/79] 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 65/79] =?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 66/79] 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 67/79] 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 68/79] 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 69/79] 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 70/79] 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 71/79] =?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 72/79] 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 73/79] =?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 74/79] 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 75/79] 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 76/79] 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 77/79] =?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 From 40982b41e4844f961583c3e8335a86e66a4e6a59 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Sun, 11 Oct 2026 08:44:52 -0400 Subject: [PATCH 78/79] Migrate to registry-backed Spago (#53) --- .github/workflows/ci.yml | 29 +- CHANGELOG.md | 2 + README.md | 2 +- bower.json | 30 - packages.dhall | 5 - spago-test.dhall | 13 - spago.dhall | 20 - spago.lock | 1309 ++++++++++++++++++++++++++++++++++++++ spago.yaml | 37 ++ 9 files changed, 1360 insertions(+), 87 deletions(-) delete mode 100644 bower.json delete mode 100644 packages.dhall delete mode 100644 spago-test.dhall delete mode 100644 spago.dhall create mode 100644 spago.lock create mode 100644 spago.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28243e2..fe9f2da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,18 +11,23 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 + + - uses: actions/setup-node@v7 + with: + node-version: 24 - name: Set up a PureScript toolchain uses: purescript-contrib/setup-purescript@main with: purescript: "unstable" + spago: "latest" purs-tidy: "latest" - name: Cache PureScript dependencies - uses: actions/cache@v2 + uses: actions/cache@v6 with: - key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }} + key: ${{ runner.os }}-spago-${{ hashFiles('spago.yaml', 'spago.lock') }} path: | .spago output @@ -30,23 +35,11 @@ jobs: - name: Install dependencies run: spago install - - 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: Build source and tests + run: spago build - name: Run tests - run: spago -x spago-test.dhall test --no-install + run: spago test - 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index fb92693..347f466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ Bugfixes: Other improvements: +- Migrate to registry-backed Spago and update CI tooling. + ## [v13.2.0](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.2.0) - 2023-02-13 Other improvements: diff --git a/README.md b/README.md index ee4c15d..ea4f39e 100644 --- a/README.md +++ b/README.md @@ -98,5 +98,5 @@ These are some other packages which provide more `ArrayBuffer` features. Run the tests with ```sh -spago -x spago-test.dhall test +spago test ``` diff --git a/bower.json b/bower.json deleted file mode 100644 index e0cb70c..0000000 --- a/bower.json +++ /dev/null @@ -1,30 +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.2.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" - } -} diff --git a/packages.dhall b/packages.dhall deleted file mode 100644 index 8af7890..0000000 --- a/packages.dhall +++ /dev/null @@ -1,5 +0,0 @@ -let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.15.7-20230211/packages.dhall - sha256:c44fcd5b1b7a1adf85bbd4ed2eeb08865c44996bd0c8b1e1fdcd3dea8cfab914 - -in upstream diff --git a/spago-test.dhall b/spago-test.dhall deleted file mode 100644 index 7037d90..0000000 --- a/spago-test.dhall +++ /dev/null @@ -1,13 +0,0 @@ -let conf = ./spago.dhall -in conf // { -, dependencies = conf.dependencies # - [ "console" - , "foldable-traversable" - , "partial" - , "refs" - , "tuples" - , "quickcheck" - , "quickcheck-laws" - ] -, sources = conf.sources # [ "test/**/*.purs" ] -} diff --git a/spago.dhall b/spago.dhall deleted file mode 100644 index 48fc095..0000000 --- a/spago.dhall +++ /dev/null @@ -1,20 +0,0 @@ -{ name = "arraybuffer" -, dependencies = - [ "arraybuffer-types" - , "arrays" - , "effect" - , "float32" - , "functions" - , "gen" - , "maybe" - , "nullable" - , "prelude" - , "tailrec" - , "uint" - , "unfoldable" - ] -, packages = ./packages.dhall -, sources = [ "src/**/*.purs" ] -, license = "MIT" -, repository = "https://github.com/purescript-contrib/purescript-arraybuffer" -} diff --git a/spago.lock b/spago.lock new file mode 100644 index 0000000..b2ce779 --- /dev/null +++ b/spago.lock @@ -0,0 +1,1309 @@ +{ + "workspace": { + "packages": { + "arraybuffer": { + "path": "./", + "core": { + "dependencies": [ + { + "arraybuffer-types": ">=3.0.2 <4.0.0" + }, + { + "arrays": ">=7.2.0 <8.0.0" + }, + { + "effect": ">=4.0.0 <5.0.0" + }, + { + "float32": ">=2.0.0 <3.0.0" + }, + { + "functions": ">=6.0.0 <7.0.0" + }, + { + "gen": ">=4.0.0 <5.0.0" + }, + { + "maybe": ">=6.0.0 <7.0.0" + }, + { + "nullable": ">=6.0.0 <7.0.0" + }, + { + "prelude": ">=6.0.1 <7.0.0" + }, + { + "tailrec": ">=6.1.0 <7.0.0" + }, + { + "uint": ">=7.0.0 <8.0.0" + }, + { + "unfoldable": ">=6.0.0 <7.0.0" + } + ] + }, + "test": { + "dependencies": [ + "console", + "foldable-traversable", + "partial", + "quickcheck", + "quickcheck-laws", + "refs", + "tuples" + ] + } + } + }, + "package_set": { + "address": { + "registry": "81.4.0" + }, + "compiler": ">=0.15.15 <0.16.0", + "content": { + "abc-parser": "2.1.0", + "ace": "9.1.0", + "address-rfc2821": "0.1.1", + "aff": "8.0.0", + "aff-bus": "6.0.0", + "aff-coroutines": "9.0.0", + "aff-promise": "4.0.0", + "aff-retry": "2.0.0", + "affjax": "13.0.0", + "affjax-node": "1.0.0", + "affjax-web": "1.0.0", + "ansi": "7.0.0", + "apexcharts": "0.5.0", + "applicative-phases": "1.0.0", + "argonaut": "9.0.0", + "argonaut-aeson-generic": "0.4.1", + "argonaut-codecs": "9.1.0", + "argonaut-core": "7.0.0", + "argonaut-generic": "8.0.0", + "argonaut-traversals": "10.0.0", + "argparse-basic": "2.0.0", + "array-builder": "0.1.2", + "array-search": "0.6.0", + "arraybuffer": "13.2.0", + "arraybuffer-builder": "3.1.0", + "arraybuffer-types": "3.0.2", + "arrays": "7.3.0", + "arrays-extra": "0.6.2", + "arrays-zipper": "2.0.1", + "ask": "1.0.0", + "assert": "6.0.0", + "assert-multiple": "0.4.0", + "avar": "5.0.1", + "axon": "0.0.3", + "b64": "0.0.9", + "barbies": "1.0.1", + "barlow-lens": "1.0.0", + "baskerville-core": "0.1.3", + "baskerville-mycroft": "0.1.0", + "benchlib": "0.0.4", + "bifunctors": "6.1.0", + "bigints": "7.0.1", + "blessed": "1.0.0", + "bolson": "0.3.9", + "bookhound": "0.1.7", + "bower-json": "3.0.0", + "bytestrings": "9.0.0", + "call-by-name": "4.0.1", + "canvas": "6.0.0", + "canvas-action": "9.0.0", + "cartesian": "1.0.6", + "catenable-lists": "7.0.0", + "cbor-stream": "1.3.0", + "chameleon": "1.0.0", + "chameleon-halogen": "1.0.3", + "chameleon-react-basic": "1.1.0", + "chameleon-styled": "2.5.0", + "chameleon-transformers": "1.0.0", + "channel": "1.0.0", + "chartjs": "0.2.0", + "chartjs-halogen": "0.2.0", + "checked-exceptions": "3.1.1", + "choku": "1.0.2", + "classless": "0.1.1", + "classless-arbitrary": "0.1.1", + "classless-decode-json": "0.1.1", + "classless-encode-json": "0.1.3", + "classnames": "2.0.0", + "codec": "6.1.0", + "codec-argonaut": "10.0.0", + "codec-json": "2.0.0", + "colors": "7.0.1", + "compile-fail": "0.4.0", + "concur-core": "0.5.0", + "concur-react": "0.5.0", + "concurrent-queues": "3.0.0", + "console": "6.1.0", + "const": "6.0.0", + "contravariant": "6.0.0", + "control": "6.0.0", + "convertable-options": "1.0.0", + "coroutines": "7.0.0", + "css": "6.0.0", + "css-class-name-extractor": "0.0.4", + "css-frameworks": "1.1.0", + "csv-stream": "2.3.0", + "currency": "0.1.0", + "data-mvc": "0.0.2", + "datetime": "6.1.0", + "datetime-parsing": "0.2.0", + "debounce": "0.1.2", + "debug": "6.0.2", + "decimals": "7.1.0", + "default-values": "1.0.1", + "deku": "0.9.24", + "deno": "0.0.5", + "dissect": "1.0.0", + "distributive": "6.0.0", + "dodo-printer": "2.2.3", + "dom-filereader": "7.0.0", + "dom-indexed": "13.0.0", + "dom-simple": "0.4.0", + "dotenv": "4.0.3", + "droplet": "0.6.0", + "dts": "1.0.0", + "dual-numbers": "1.0.3", + "dynamic-buffer": "3.0.1", + "echarts-simple": "0.0.1", + "effect": "4.0.0", + "either": "6.1.0", + "elmish": "0.16.0", + "elmish-enzyme": "0.1.1", + "elmish-hooks": "0.12.0", + "elmish-html": "0.14.0", + "elmish-testing-library": "0.5.0", + "email-validate": "7.0.0", + "encoding": "0.0.10", + "enums": "6.0.1", + "env-names": "0.4.0", + "environment": "2.0.0", + "error": "2.0.0", + "eta-conversion": "0.3.2", + "exceptions": "6.1.0", + "exists": "6.0.0", + "exitcodes": "4.0.0", + "expect-inferred": "3.0.0", + "express": "0.9.1", + "ezfetch": "1.1.1", + "fahrtwind": "2.0.0", + "faker-ffi": "0.1.1", + "fakerjs": "0.0.1", + "fallback": "0.1.0", + "fast-vect": "1.2.0", + "fetch": "4.1.0", + "fetch-argonaut": "1.0.1", + "fetch-core": "5.1.0", + "fetch-yoga-json": "1.1.0", + "ffi-simple": "0.5.1", + "fft": "0.3.0", + "fft-js": "0.1.0", + "filterable": "5.0.0", + "fix-functor": "0.1.0", + "fixed-points": "7.0.0", + "fixed-precision": "5.0.0", + "flame": "1.6.0", + "float32": "2.0.0", + "fmt": "0.2.1", + "foldable-traversable": "6.0.0", + "foldable-traversable-extra": "0.0.6", + "foreign": "7.0.0", + "foreign-object": "4.1.0", + "foreign-readwrite": "3.4.0", + "forgetmenot": "0.1.0", + "fork": "6.0.0", + "form-urlencoded": "7.0.0", + "formatters": "7.0.0", + "framer-motion": "3.1.0", + "free": "7.1.0", + "freeap": "7.0.0", + "freer-free": "0.0.1", + "freet": "7.0.0", + "functions": "6.0.0", + "functor1": "3.0.0", + "functors": "5.0.0", + "fuzzy": "0.4.0", + "gen": "4.0.0", + "generate-values": "1.0.1", + "generic-router": "0.0.1", + "geojson": "0.0.5", + "geometria": "2.2.0", + "gesso": "1.0.1", + "gojs": "0.1.1", + "golden-test": "0.1.0", + "golem-fetch": "0.1.0", + "grain": "3.0.0", + "grain-router": "3.0.0", + "grain-virtualized": "3.0.0", + "graphql-client": "10.1.1", + "graphs": "8.1.0", + "group": "4.1.1", + "halogen": "7.0.0", + "halogen-bootstrap5": "5.3.2", + "halogen-canvas": "1.0.0", + "halogen-css": "10.0.0", + "halogen-declarative-canvas": "0.0.8", + "halogen-echarts-simple": "0.0.4", + "halogen-formless": "4.0.3", + "halogen-helix": "1.1.0", + "halogen-hooks": "0.6.3", + "halogen-hooks-extra": "0.9.0", + "halogen-infinite-scroll": "1.1.0", + "halogen-store": "0.5.4", + "halogen-storybook": "2.0.0", + "halogen-subscriptions": "2.0.0", + "halogen-svg-elems": "8.0.0", + "halogen-typewriter": "1.0.4", + "halogen-use-trigger-hooks": "1.0.0", + "halogen-vdom": "8.0.0", + "halogen-vdom-string-renderer": "0.5.0", + "halogen-widgets": "0.3.1", + "halogen-xterm": "2.0.0", + "harmonia": "0.2.0", + "heckin": "2.0.1", + "heterogeneous": "0.7.0", + "homogeneous": "0.4.0", + "http-methods": "6.1.0", + "httpurple": "4.0.0", + "huffman": "0.4.0", + "humdrum": "0.0.1", + "hylograph-canvas": "0.1.0", + "hylograph-components": "0.1.0", + "hylograph-d3-kernel": "0.1.0", + "hylograph-graph": "0.3.0", + "hylograph-layout": "0.3.0", + "hylograph-music": "0.4.0", + "hylograph-optics": "0.1.0", + "hylograph-selection": "0.5.3", + "hylograph-simulation": "0.6.0", + "hylograph-simulation-core": "0.1.0", + "hylograph-simulation-halogen": "0.5.1", + "hylograph-transitions": "0.1.0", + "hylograph-wasm-kernel": "0.1.0", + "hyrule": "2.3.9", + "i18next": "0.1.0", + "idb": "0.2.0", + "identity": "6.0.0", + "identy": "4.0.1", + "indexed-db": "1.0.0", + "indexed-monad": "3.0.0", + "ink": "0.0.1", + "int64": "3.0.0", + "integers": "6.0.0", + "interpolate": "5.0.2", + "intersection-observer": "1.0.1", + "invariant": "6.0.0", + "jarilo": "1.0.1", + "jelly": "0.10.0", + "jelly-router": "0.3.0", + "jelly-signal": "0.4.0", + "jest": "1.0.0", + "js-abort-controller": "1.0.0", + "js-bigints": "2.2.1", + "js-date": "8.0.0", + "js-fetch": "0.2.1", + "js-fileio": "3.0.0", + "js-intl": "1.3.0", + "js-iterators": "0.1.1", + "js-maps": "0.1.2", + "js-promise": "1.0.0", + "js-promise-aff": "1.0.0", + "js-temporal": "3.0.0", + "js-timers": "6.1.0", + "js-uri": "3.1.0", + "jsdom": "1.0.0", + "jsinc": "0.5.1", + "json": "1.1.0", + "json-codecs": "5.0.0", + "justifill": "0.5.0", + "jwt": "0.0.9", + "labeled-data": "0.2.0", + "language-cst-parser": "0.14.1", + "lazy": "6.0.0", + "lazy-joe": "1.0.0", + "lcg": "4.0.0", + "leibniz": "5.0.0", + "leveldb": "1.0.1", + "liminal": "1.0.1", + "linalg": "6.0.0", + "linear": "0.1.0", + "lists": "7.0.0", + "literals": "1.0.2", + "logging": "3.0.0", + "logging-journald": "0.4.0", + "lumi-components": "18.0.0", + "machines": "7.0.0", + "maps-eager": "0.5.0", + "marionette": "1.0.0", + "marionette-react-basic-hooks": "0.1.1", + "markdown-it-js": "0.1.0", + "marked": "0.1.0", + "matrices": "5.0.1", + "matryoshka": "1.0.0", + "maybe": "6.0.0", + "media-types": "6.0.0", + "meowclient": "1.0.0", + "midi": "4.0.0", + "milkdown": "0.1.0", + "milkis": "9.0.0", + "mimetype": "0.0.1", + "minibench": "4.0.1", + "mmorph": "7.0.0", + "monad-control": "5.0.0", + "monad-logger": "1.3.1", + "monad-loops": "0.5.0", + "monad-unlift": "1.0.1", + "monoid-extras": "0.0.1", + "monoidal": "0.16.0", + "mote": "3.0.0", + "motion": "4.0.0", + "motsunabe": "2.0.0", + "mvc": "0.0.1", + "mycroft": "0.1.1", + "mycroft-z3-wasm": "0.1.0", + "mysql": "6.0.1", + "n3": "0.1.0", + "nano-id": "1.1.0", + "nanoid": "0.1.0", + "naturals": "3.0.0", + "nested-functor": "0.2.1", + "newtype": "5.0.0", + "next-purs-rsc": "0.1.0", + "nextjs": "0.1.1", + "nextui": "0.2.0", + "node-buffer": "9.0.0", + "node-child-process": "11.1.0", + "node-event-emitter": "3.0.0", + "node-execa": "5.0.0", + "node-fs": "9.2.0", + "node-glob-basic": "2.0.0", + "node-http": "9.1.0", + "node-http2": "1.1.1", + "node-human-signals": "1.0.0", + "node-net": "5.1.0", + "node-os": "5.1.0", + "node-path": "5.0.1", + "node-process": "11.2.0", + "node-readline": "8.1.1", + "node-sqlite": "0.2.0", + "node-sqlite3": "8.0.0", + "node-stream-pipes": "2.1.6", + "node-streams": "9.0.1", + "node-tls": "0.3.1", + "node-url": "7.0.1", + "node-workerbees": "0.3.1", + "node-zlib": "0.4.0", + "nonempty": "7.0.0", + "now": "6.0.0", + "npm-package-json": "2.0.0", + "nqueens": "0.1.4", + "nullable": "6.0.0", + "numberfield": "0.2.2", + "numbers": "9.0.1", + "oak": "3.1.1", + "oak-debug": "1.2.2", + "object-maps": "0.3.0", + "ocarina": "1.5.4", + "oooooooooorrrrrrrmm-lib": "0.0.1", + "open-colors-scales-and-schemes": "1.0.0", + "open-drawing": "6.0.4", + "open-folds": "6.4.0", + "open-foreign-generic": "11.0.3", + "open-memoize": "6.2.0", + "open-mkdirp-aff": "1.2.0", + "open-pairing": "6.2.0", + "open-smolder": "12.0.2", + "options": "7.0.0", + "optparse": "5.0.1", + "ordered-collections": "3.2.0", + "ordered-set": "0.5.2", + "orders": "6.0.0", + "org-doc": "0.1.0", + "owoify": "1.2.0", + "pairs": "9.0.1", + "parallel": "7.0.0", + "parsing": "11.0.0", + "parsing-dataview": "3.2.4", + "partial": "4.0.0", + "pathy": "9.0.0", + "pha": "0.13.0", + "phaser": "0.7.0", + "phylio": "1.1.2", + "pipes": "8.0.0", + "pirates-charm": "0.0.1", + "play": "1.0.0", + "pmock": "1.1.0", + "point-free": "1.0.0", + "pointed-list": "0.5.1", + "polymorphic-vectors": "4.0.0", + "posix-types": "6.0.0", + "postgresql": "2.0.21", + "precise": "6.0.0", + "precise-datetime": "7.0.0", + "prelude": "6.0.2", + "prettier-printer": "3.0.0", + "printf": "0.1.0", + "priority-queue": "0.1.2", + "profunctor": "6.0.1", + "profunctor-lenses": "8.0.0", + "prospero": "0.1.0", + "protobuf": "4.4.0", + "ps-spa": "0.7.1", + "psa-utils": "8.0.0", + "psci-support": "6.0.0", + "punycode": "1.0.0", + "pursfmt": "0.17.0", + "qualified-do": "2.2.0", + "quantities": "12.2.0", + "quickcheck": "8.0.1", + "quickcheck-combinators": "0.1.3", + "quickcheck-laws": "7.0.0", + "quickcheck-utf8": "0.0.0", + "random": "6.0.0", + "rationals": "6.0.0", + "rdf": "0.1.0", + "react": "11.0.0", + "react-aria": "0.2.0", + "react-basic": "17.0.0", + "react-basic-classic": "3.0.0", + "react-basic-dnd": "10.1.0", + "react-basic-dom": "7.0.0", + "react-basic-dom-beta": "0.1.1", + "react-basic-emotion": "7.1.0", + "react-basic-hooks": "9.1.1", + "react-basic-storybook": "2.0.0", + "react-dnd-kit": "0.6.0", + "react-dom": "8.0.0", + "react-halo": "3.0.0", + "react-icons": "1.1.6", + "react-markdown": "0.1.0", + "react-testing-library": "4.0.1", + "react-virtuoso": "1.0.0", + "reactix": "0.6.1", + "read": "1.0.1", + "recharts": "1.1.0", + "record": "4.0.0", + "record-extra": "5.0.1", + "record-extra-srghma": "0.2.8", + "record-ptional-fields": "0.1.2", + "record-studio": "1.0.4", + "ref-lifted": "0.0.2", + "refs": "6.0.0", + "remotedata": "5.0.1", + "repr": "0.5.0", + "resize-arrays": "0.0.1", + "resize-observer": "1.0.0", + "resource": "2.0.1", + "resourcet": "1.0.0", + "result": "1.0.3", + "return": "0.2.0", + "ring-modules": "5.0.1", + "rito": "0.3.4", + "roman": "0.4.0", + "rough-notation": "1.0.2", + "routing": "11.0.0", + "routing-duplex": "0.7.0", + "run": "5.0.0", + "safe-coerce": "2.0.0", + "safely": "4.0.1", + "school-of-music": "1.3.0", + "selection-foldable": "0.2.0", + "selective-functors": "1.0.1", + "semirings": "7.0.0", + "seowebchecker": "1.0.4", + "shuffle": "2.0.0", + "sigil": "0.3.0", + "sigil-hats": "0.3.0", + "signal": "13.0.0", + "simple-emitter": "3.0.1", + "simple-i18n": "2.0.1", + "simple-json": "9.0.0", + "simple-json-generics": "0.2.1", + "simple-ulid": "3.0.0", + "sized-matrices": "1.0.0", + "sized-vectors": "5.0.2", + "slug": "3.2.0", + "small-ffi": "4.0.1", + "soundfonts": "4.1.0", + "sparse-matrices": "2.0.1", + "sparse-polynomials": "3.0.1", + "spec": "8.1.2", + "spec-discovery": "8.4.1", + "spec-mocha": "5.1.1", + "spec-node": "0.0.3", + "spec-quickcheck": "5.0.2", + "spec-reporter-xunit": "0.7.1", + "splitmix": "2.1.0", + "ssrs": "1.0.0", + "st": "6.2.0", + "statistics": "0.3.2", + "strictlypositiveint": "1.0.1", + "string-parsers": "8.0.0", + "strings": "6.0.1", + "strings-extra": "4.0.0", + "stringutils": "0.0.13", + "structured-logging": "1.0.0", + "substitute": "0.2.3", + "supabase": "0.1.0", + "supply": "0.2.0", + "svg-parser": "3.0.0", + "systemd-journald": "0.3.0", + "tagged": "4.0.2", + "tailrec": "6.1.0", + "tanstack-query": "3.0.0", + "tecton": "0.2.1", + "tecton-halogen": "0.2.0", + "temporal": "0.2.0", + "test-unit": "17.0.0", + "text-formatting": "0.1.0", + "thermite": "6.3.1", + "thermite-dom": "0.3.1", + "these": "6.0.0", + "threading": "0.0.3", + "tidy": "0.11.1", + "tidy-codegen": "4.0.1", + "tldr": "0.0.0", + "toestand": "0.9.0", + "tramaj-halogen": "0.4.1", + "tramaj-purs": "0.4.1", + "transformation-matrix": "1.0.1", + "transformers": "6.1.0", + "transit": "1.0.0", + "tree-rose": "4.0.2", + "trivial-unfold": "0.5.0", + "ts-bridge": "4.0.0", + "tuples": "7.0.0", + "two-or-more": "1.0.0", + "type-equality": "4.0.1", + "typedenv": "2.0.1", + "typelevel": "6.0.0", + "typelevel-lists": "2.1.0", + "typelevel-peano": "1.0.1", + "typelevel-prelude": "7.0.0", + "typelevel-regex": "0.0.3", + "typelevel-rows": "0.1.0", + "typisch": "0.4.0", + "uint": "7.0.0", + "ulid": "3.0.1", + "uncurried-transformers": "1.1.0", + "undefined": "2.0.0", + "undefined-is-not-a-problem": "1.1.0", + "unfoldable": "6.0.0", + "unicode": "6.0.0", + "unique": "0.6.1", + "unlift": "1.0.1", + "unordered-collections": "3.1.0", + "unsafe-coerce": "6.0.0", + "unsafe-reference": "5.0.0", + "untagged-to-tagged": "0.1.4", + "untagged-union": "1.0.0", + "uri": "9.0.0", + "url-immutable": "1.0.0", + "url-regex-safe": "0.1.1", + "uuid": "9.0.0", + "uuidv4": "1.0.0", + "validation": "6.0.0", + "variant": "8.0.0", + "variant-encodings": "2.0.0", + "variant-gen": "1.0.0", + "vectorfield": "1.0.1", + "vectors": "2.1.0", + "versions": "7.0.0", + "visx": "0.0.2", + "vitest": "2.0.1", + "wasm-base": "0.2.0", + "web-chain": "1.0.1", + "web-clipboard": "6.0.0", + "web-cssom": "2.0.0", + "web-cssom-view": "0.1.0", + "web-dom": "6.0.0", + "web-dom-parser": "8.0.0", + "web-dom-xpath": "3.0.0", + "web-encoding": "3.0.0", + "web-events": "4.0.0", + "web-fetch": "4.0.1", + "web-file": "4.0.0", + "web-geometry": "0.1.0", + "web-html": "4.1.1", + "web-pointerevents": "2.0.0", + "web-proletarian": "1.0.0", + "web-promise": "3.2.0", + "web-resize-observer": "2.1.0", + "web-router": "1.0.0", + "web-socket": "4.0.0", + "web-storage": "5.0.0", + "web-streams": "4.0.0", + "web-touchevents": "4.0.0", + "web-uievents": "5.0.0", + "web-url": "2.0.0", + "web-workers": "2.0.0", + "web-xhr": "5.0.1", + "webb-aff-list": "0.0.2", + "webb-array": "0.0.2", + "webb-channel": "0.0.3", + "webb-commandline": "0.0.3", + "webb-directory": "0.0.7", + "webb-file": "0.0.1", + "webb-map": "0.0.1", + "webb-monad": "0.0.2", + "webb-mutex": "0.0.7", + "webb-parsing": "0.0.5", + "webb-random": "0.0.1", + "webb-refer": "0.0.3", + "webb-set": "0.0.1", + "webb-slot": "0.0.1", + "webb-stateful": "0.0.3", + "webb-string": "0.0.1", + "webb-test": "0.0.1", + "webb-thread": "0.0.2", + "webb-writer": "0.0.3", + "webextension-polyfill": "0.1.0", + "webgpu": "0.0.1", + "which": "2.0.0", + "whine-core": "0.0.34", + "xterm": "1.0.0", + "yaml-next": "3.1.1", + "yoga-acp-om": "0.1.1", + "yoga-better-auth": "0.2.2", + "yoga-bun-yoga": "0.2.1", + "yoga-config": "0.2.1", + "yoga-country": "3.0.0", + "yoga-docker-compose": "0.1.1", + "yoga-dynamodb": "0.1.1", + "yoga-elasticsearch": "0.1.1", + "yoga-fastify": "0.5.4", + "yoga-fastify-om": "0.4.7", + "yoga-fetch": "1.0.1", + "yoga-fetch-om": "0.8.0", + "yoga-format": "1.0.0", + "yoga-heroui": "2.0.3", + "yoga-http-api": "0.3.4", + "yoga-jaeger": "0.1.1", + "yoga-json": "5.2.1", + "yoga-language": "1.0.0", + "yoga-next-fastify": "0.2.0", + "yoga-om": "2.2.1", + "yoga-om-layer": "2.1.0", + "yoga-om-strom": "0.4.3", + "yoga-om-workerbees": "0.1.2", + "yoga-opentelemetry": "0.2.0", + "yoga-options": "0.1.1", + "yoga-pino": "0.1.1", + "yoga-postgres": "6.0.0", + "yoga-react": "1.0.2", + "yoga-react-dom": "2.0.1", + "yoga-react-native": "0.2.1", + "yoga-react-om": "0.2.0", + "yoga-redis": "0.1.1", + "yoga-scylladb": "0.1.1", + "yoga-shadcn": "1.0.5", + "yoga-sql-types": "0.2.0", + "yoga-sqlite": "0.3.4", + "yoga-sqlite-om": "0.3.0", + "yoga-sse": "0.1.1", + "yoga-subtlecrypto": "0.1.0", + "yoga-test-docker": "0.1.2", + "yoga-timezone": "1.0.0", + "yoga-tree": "1.0.0", + "yoga-tree-svg": "0.1.0", + "yoga-tree-utils": "1.0.0", + "z3": "0.0.2", + "zipperarray": "2.0.0" + } + }, + "extra_packages": {} + }, + "packages": { + "arraybuffer-types": { + "type": "registry", + "version": "3.0.2", + "integrity": "sha256-p05cJnSkyeoB7VHzMyc2Eb1RwUaB7Nl0sQSqEGNEUD8=", + "dependencies": [] + }, + "arrays": { + "type": "registry", + "version": "7.3.0", + "integrity": "sha256-GD4z7LCi9wzi7FCQqbWhvs8paoUK9NO+HwgXZ+KP8Rk=", + "dependencies": [ + "bifunctors", + "control", + "foldable-traversable", + "functions", + "maybe", + "nonempty", + "partial", + "prelude", + "safe-coerce", + "st", + "tailrec", + "tuples", + "unfoldable", + "unsafe-coerce" + ] + }, + "bifunctors": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-CvZRb8uI75eKIqiYntR+k05Wk6tKlMS5w8sCA2AFna0=", + "dependencies": [ + "const", + "either", + "newtype", + "prelude", + "tuples" + ] + }, + "console": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-3T5PPz1mATZmV0C4GzkCkpLlCa5xG7u8ZNgnLrrrI1Q=", + "dependencies": [ + "effect", + "prelude" + ] + }, + "const": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-S+m0lQsxnji0z1XRUmkn+3RFuWJ5CXWuIr1u3i8Bfoc=", + "dependencies": [ + "invariant", + "newtype", + "prelude" + ] + }, + "contravariant": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-nuckEWqL80NaPmR/l9AUyrfycNh18XcvlZV9PAamwqc=", + "dependencies": [ + "const", + "either", + "newtype", + "prelude", + "tuples" + ] + }, + "control": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-0vxyYh5FL+ilxgLo954w1LqCUC0RSIivNNlb9CaNUQg=", + "dependencies": [ + "newtype", + "prelude" + ] + }, + "distributive": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-netyJK4B32PDYHD0tF2AenKgo3urzbI770ycM0pArAo=", + "dependencies": [ + "identity", + "newtype", + "prelude", + "tuples", + "type-equality" + ] + }, + "effect": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-DdqU3bncRTjgMVPPRlAuGHVeajSPEcRaRhNuio7if6s=", + "dependencies": [ + "prelude" + ] + }, + "either": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-tBHx3PgtH4GZOApZCDkcM7szRTYJinrUrVGWazQCUUg=", + "dependencies": [ + "control", + "invariant", + "maybe", + "prelude" + ] + }, + "enums": { + "type": "registry", + "version": "6.0.1", + "integrity": "sha256-sdZOmLX5+5pASGpvVyT0vSD5BBYQjZiayjV5XiPutso=", + "dependencies": [ + "control", + "either", + "gen", + "maybe", + "newtype", + "nonempty", + "partial", + "prelude", + "tuples", + "unfoldable" + ] + }, + "exceptions": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-nRrr+N0wk0TUFOWLR7e1n1oxcXo/X345bQUtoY9lW6A=", + "dependencies": [ + "effect", + "either", + "maybe", + "prelude" + ] + }, + "exists": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-vtLbrWNaI+pzx/2fw2AQnCovoLtcosClIhjO26QKkh8=", + "dependencies": [ + "unsafe-coerce" + ] + }, + "float32": { + "type": "registry", + "version": "2.0.0", + "integrity": "sha256-lO8pshPBj5ExM+/ZjZ8nXVltb37XGJdRP8vakl0LBTE=", + "dependencies": [ + "gen", + "maybe", + "prelude" + ] + }, + "foldable-traversable": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-NGGWyCio/xjce6fPP7y3wwg7CheqllID6aJudDxbWhA=", + "dependencies": [ + "bifunctors", + "const", + "control", + "either", + "functors", + "identity", + "maybe", + "newtype", + "orders", + "prelude", + "tuples" + ] + }, + "functions": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-0jgtOr+SFO4UScKc40oA/9Vdcf2rLn3h3vZlY0KfqVo=", + "dependencies": [ + "prelude" + ] + }, + "functors": { + "type": "registry", + "version": "5.0.0", + "integrity": "sha256-W1o/4wcp6S3chodYL8uixlXK2mfr1L+SzM1R+whqUco=", + "dependencies": [ + "bifunctors", + "const", + "contravariant", + "control", + "distributive", + "either", + "invariant", + "maybe", + "newtype", + "prelude", + "profunctor", + "tuples", + "unsafe-coerce" + ] + }, + "gen": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-kyOateeOtQa07vfTMYeSuCKdelgKE1R65fwKkZ10wsY=", + "dependencies": [ + "either", + "foldable-traversable", + "identity", + "maybe", + "newtype", + "nonempty", + "prelude", + "tailrec", + "tuples", + "unfoldable" + ] + }, + "identity": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-RY/iXPpxpqvKHYfJeFVNI1J06kohB9rbtWYuha8t0LE=", + "dependencies": [ + "control", + "invariant", + "newtype", + "prelude" + ] + }, + "integers": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-Y8yozC1uHRLcruobEyv5/bMKzE1BoKJ/olHv6o+bgm8=", + "dependencies": [ + "maybe", + "numbers", + "prelude" + ] + }, + "invariant": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-HyoT1I5qIHRq8RSZji6zZDvqnpVjLw748utrKwZtqsw=", + "dependencies": [ + "control", + "prelude" + ] + }, + "lazy": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-MHRC+1Pc+AjortBp4b/e1e6KpEpsDwaJBNBB7TOL+1I=", + "dependencies": [ + "control", + "foldable-traversable", + "invariant", + "prelude" + ] + }, + "lcg": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-bUYyfXYmjTn7zSpj2hTiePywzsuD80fCjkonsrpdGOw=", + "dependencies": [ + "effect", + "integers", + "maybe", + "numbers", + "partial", + "prelude", + "random" + ] + }, + "lists": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-/mGd7wLoU+wsTcqii7SSUByxsvwvjnu2PjwAD47yYb4=", + "dependencies": [ + "bifunctors", + "control", + "foldable-traversable", + "lazy", + "maybe", + "newtype", + "nonempty", + "partial", + "prelude", + "tailrec", + "tuples", + "unfoldable" + ] + }, + "maybe": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-8X6XEgtZ5lqfkEuc1hWOofnL6mwhk8gSJTxwvbR/SbY=", + "dependencies": [ + "control", + "invariant", + "newtype", + "prelude" + ] + }, + "newtype": { + "type": "registry", + "version": "5.0.0", + "integrity": "sha256-dt6w0cty4OS+Pjt9fsh3iU6ottqSU83mdAZkaEEvo6c=", + "dependencies": [ + "prelude", + "safe-coerce" + ] + }, + "nonempty": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-Ctkq8/+KiGqCE53Y/LvibA/coy7ev9HtRZU+GYS7yfQ=", + "dependencies": [ + "control", + "foldable-traversable", + "maybe", + "prelude", + "tuples", + "unfoldable" + ] + }, + "nullable": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-CDAZk+L9Sc0GCFTkE8n+qdp4Ys8avvnkU+m2hVALt7M=", + "dependencies": [ + "functions", + "maybe", + "prelude" + ] + }, + "numbers": { + "type": "registry", + "version": "9.0.1", + "integrity": "sha256-ZydYckgwRAnRaFC7pu6fADhzdwX+UqHZrfJyet64zls=", + "dependencies": [ + "functions", + "maybe", + "prelude" + ] + }, + "orders": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-nSMxZK7wxyDULkjZqvMyB71mVo6b0AyLLHosDVbv1XM=", + "dependencies": [ + "newtype", + "prelude" + ] + }, + "partial": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-mdrlJBAgFMh79hNRW39uv7c+BwnnaOrAMmdh7+VhEhs=", + "dependencies": [] + }, + "prelude": { + "type": "registry", + "version": "6.0.2", + "integrity": "sha256-IqykrDRquGUD/LRSad7y75hZv3bUsGQ4knc8tdez8Qw=", + "dependencies": [] + }, + "profunctor": { + "type": "registry", + "version": "6.0.1", + "integrity": "sha256-Ow0mJC+PIIRq/a3mzCWY5vxuTgR/e+Ee68+mWeSRnWY=", + "dependencies": [ + "control", + "distributive", + "either", + "exists", + "invariant", + "newtype", + "prelude", + "tuples" + ] + }, + "quickcheck": { + "type": "registry", + "version": "8.0.1", + "integrity": "sha256-SfW+maesCt0jnnFhfrgJZGPcWLj8oFcGbcDIVklmdzc=", + "dependencies": [ + "arrays", + "console", + "control", + "effect", + "either", + "enums", + "exceptions", + "foldable-traversable", + "gen", + "identity", + "integers", + "lazy", + "lcg", + "lists", + "maybe", + "newtype", + "nonempty", + "numbers", + "partial", + "prelude", + "record", + "st", + "strings", + "tailrec", + "transformers", + "tuples" + ] + }, + "quickcheck-laws": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-hDd4Q99TNlEz9sU0Cssm7n6+BswAq69HL8KqNP5UKOU=", + "dependencies": [ + "arrays", + "console", + "control", + "effect", + "enums", + "foldable-traversable", + "maybe", + "newtype", + "prelude", + "quickcheck" + ] + }, + "random": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-7sZRo6P9UIiXDZ9s2QL9T8h3wlIwLdQrR4+oZKOijQw=", + "dependencies": [ + "effect", + "integers", + "prelude" + ] + }, + "record": { + "type": "registry", + "version": "4.0.0", + "integrity": "sha256-WQ8fqp4X1wTA70J4qUcPW4Z7DCwx6e5KJnT/EuTdWSc=", + "dependencies": [ + "functions", + "prelude", + "unsafe-coerce" + ] + }, + "refs": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-KKD5G9dR2SauuDGULUJsxjqDOEi1Jqm+2Sq5U2mY8YU=", + "dependencies": [ + "effect", + "prelude" + ] + }, + "safe-coerce": { + "type": "registry", + "version": "2.0.0", + "integrity": "sha256-EJrxtKt5xC7TYjBZrSBO/J7Aw3DmtilYjt4olpAXWVc=", + "dependencies": [ + "unsafe-coerce" + ] + }, + "st": { + "type": "registry", + "version": "6.2.0", + "integrity": "sha256-WI4MEkkwUd4pnwZQ3G8VKWgX5t1RSNJludm5e9boaRo=", + "dependencies": [ + "effect", + "partial", + "prelude", + "tailrec", + "unsafe-coerce" + ] + }, + "strings": { + "type": "registry", + "version": "6.0.1", + "integrity": "sha256-FNto2hoNW5Da6W6crIk77YXMagBvOGHZE1kO7eZ1vLM=", + "dependencies": [ + "arrays", + "control", + "either", + "enums", + "foldable-traversable", + "gen", + "integers", + "maybe", + "newtype", + "nonempty", + "partial", + "prelude", + "tailrec", + "tuples", + "unfoldable", + "unsafe-coerce" + ] + }, + "tailrec": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-xrorCfP0xV1wubs27idQCHQqdvSUuqmmL/am7Ji1wVU=", + "dependencies": [ + "bifunctors", + "effect", + "either", + "identity", + "maybe", + "partial", + "prelude", + "refs" + ] + }, + "transformers": { + "type": "registry", + "version": "6.1.0", + "integrity": "sha256-QJmgNT/y7ljPHSsXaW4zxF/982BFiQ90KNL1g/NtEOQ=", + "dependencies": [ + "control", + "distributive", + "effect", + "either", + "exceptions", + "foldable-traversable", + "identity", + "lazy", + "maybe", + "newtype", + "prelude", + "st", + "tailrec", + "tuples", + "unfoldable" + ] + }, + "tuples": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-BKy7EfK8S1KeTCwyWqyW1wwcpSAQuh3IsczSVgS6fzY=", + "dependencies": [ + "control", + "invariant", + "prelude" + ] + }, + "type-equality": { + "type": "registry", + "version": "4.0.1", + "integrity": "sha256-BBqYOSnAKmayRvR5mtZoCf4SlYs2ipatD/+5nQx73aw=", + "dependencies": [] + }, + "uint": { + "type": "registry", + "version": "7.0.0", + "integrity": "sha256-MCTYyDPFLoNLweSY1oEjKKo0xhqCGrAbiBQNdva1B3w=", + "dependencies": [ + "enums", + "gen", + "maybe", + "numbers", + "prelude" + ] + }, + "unfoldable": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-BK/6By1sKp/ztk+9CF3q43SV0QDTLVdsGqFerKHSmbg=", + "dependencies": [ + "foldable-traversable", + "maybe", + "partial", + "prelude", + "tuples" + ] + }, + "unsafe-coerce": { + "type": "registry", + "version": "6.0.0", + "integrity": "sha256-0L1QsaY20OILjfU5TV72d3U/tSjhmL9hJ32WMp857Lk=", + "dependencies": [] + } + } +} diff --git a/spago.yaml b/spago.yaml new file mode 100644 index 0000000..33e6321 --- /dev/null +++ b/spago.yaml @@ -0,0 +1,37 @@ +package: + name: arraybuffer + description: Bindings and implementation for mutable JavaScript ArrayBuffers + publish: + version: 13.2.1 + license: MIT + location: + githubOwner: purescript-contrib + githubRepo: purescript-arraybuffer + build: + strict: true + dependencies: + - arraybuffer-types: ">=3.0.2 <4.0.0" + - arrays: ">=7.2.0 <8.0.0" + - effect: ">=4.0.0 <5.0.0" + - float32: ">=2.0.0 <3.0.0" + - functions: ">=6.0.0 <7.0.0" + - gen: ">=4.0.0 <5.0.0" + - maybe: ">=6.0.0 <7.0.0" + - nullable: ">=6.0.0 <7.0.0" + - prelude: ">=6.0.1 <7.0.0" + - tailrec: ">=6.1.0 <7.0.0" + - uint: ">=7.0.0 <8.0.0" + - unfoldable: ">=6.0.0 <7.0.0" + test: + main: Test.Main + dependencies: + - console + - foldable-traversable + - partial + - refs + - tuples + - quickcheck + - quickcheck-laws +workspace: + packageSet: + registry: 81.4.0 From 53f565d08736f7b1a93ab82ccd0432fc7d5b6dbe Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Sun, 11 Oct 2026 12:46:07 +0000 Subject: [PATCH 79/79] Prepare v13.2.1 release --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 347f466..43930d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Bugfixes: Other improvements: +## [v13.2.1](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.2.1) - 2026-10-11 + +Other improvements: + - Migrate to registry-backed Spago and update CI tooling. ## [v13.2.0](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.2.0) - 2023-02-13