Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
53c7b23
ripping out untrue functionality of arraybuffers
athanclark Dec 4, 2018
97a49c6
rename to stay true to implementation
athanclark Dec 4, 2018
d650148
converting to Effect.Uncurried, using exception catching, naming
athanclark Dec 4, 2018
a4c7cd0
module documentation
athanclark Dec 4, 2018
addf664
preparing for major redesign of typed interface - supporting all
athanclark Dec 4, 2018
5200641
polyfill
athanclark Dec 4, 2018
5d49921
module doc
athanclark Dec 4, 2018
75a91e6
using `new` as binder - also, remainder function
athanclark Dec 4, 2018
827b29e
copyWithin
athanclark Dec 4, 2018
7a3435f
all, any ~ every, some
athanclark Dec 4, 2018
ba3f089
fill semantics
athanclark Dec 4, 2018
b203cd9
toString
athanclark Dec 4, 2018
e2b70aa
subarray
athanclark Dec 4, 2018
16f384c
in-place sort
athanclark Dec 4, 2018
95a79cb
slice
athanclark Dec 4, 2018
b281b9d
moving `set` around a little
athanclark Dec 4, 2018
f8ae9ad
reverse in-place
athanclark Dec 4, 2018
be5e28b
typed map
athanclark Dec 4, 2018
f2be9a4
joining an array
athanclark Dec 4, 2018
fa53dca
filter
athanclark Dec 4, 2018
a3da940
toArray typed properly
athanclark Dec 4, 2018
588284d
folds
athanclark Dec 4, 2018
3b246b9
elem, need to do find and indexing
athanclark Dec 4, 2018
4759fe4
better arraybuffer slice, more stuff
athanclark Dec 4, 2018
aa789b7
the uint library stores values greater than 2^31 as a negative integer -
athanclark Dec 4, 2018
d0c4038
index of
athanclark Dec 6, 2018
2ffbb00
more instances
athanclark Dec 6, 2018
3c7066e
honestly I forgot about floating points
athanclark Dec 6, 2018
fd29b0b
the binary serialization of javascript Numbers for TypedArrays follows
athanclark Dec 6, 2018
ea66b5f
Remove text encoding dependency
AlexaDeWit Dec 6, 2018
00d4a2e
Remove show and update readme
AlexaDeWit Dec 6, 2018
71b5b08
generation functions - need to generate a bona-fide float32
athanclark Dec 6, 2018
4a83a72
arbitrary floating point values
athanclark Dec 6, 2018
3adab9e
more correct
athanclark Dec 6, 2018
e84aec7
more generators
athanclark Dec 6, 2018
350c48f
simple byteLength / bytesPerValue === length test
athanclark Dec 6, 2018
b848ecb
fromArray <<< toArray iso
athanclark Dec 6, 2018
f7b256e
better docs
athanclark Dec 8, 2018
875662e
cosmetic
athanclark Dec 8, 2018
89da71d
using uint
athanclark Dec 8, 2018
f939172
fill y xs => all (== y) xs
athanclark Dec 10, 2018
3b0f0ab
generic instance of `WithOffset` structure
athanclark Dec 11, 2018
cb63506
cosmetic, with offset
athanclark Dec 12, 2018
fa8d1b6
removed funky show module
athanclark Dec 12, 2018
bb4f0f3
set singleton is eq
athanclark Dec 12, 2018
d73a98c
all implies any
athanclark Dec 13, 2018
e8324a1
filter, all / any
athanclark Dec 13, 2018
9f09755
elem with unsafeAt
athanclark Dec 13, 2018
2d7e141
any implies find
athanclark Dec 13, 2018
097e8ad
findIndex implies at
athanclark Dec 13, 2018
ab5d578
indexOf implies at
athanclark Dec 13, 2018
2764959
lastIndexOf imples at
athanclark Dec 13, 2018
24ff499
quickcheck combinators
athanclark Dec 13, 2018
7fb380c
cosmetic
athanclark Dec 13, 2018
9415877
sort is idempotent, reverse tests
Dec 13, 2018
22326b1
sort is correct
Dec 13, 2018
1031fd2
toString
Dec 13, 2018
7482f4d
dual subArray and slice references
Dec 13, 2018
44cc05d
really weird test results - subArray isn't mutable when supplied with…
Dec 13, 2018
d585392
peculiar behavior of subArray
Dec 13, 2018
2233a4d
verifying the mutability of whole subArrays
Dec 13, 2018
1919471
better docs
Dec 13, 2018
e892216
misimplementation
Dec 13, 2018
75d5c6c
copy within self
Dec 13, 2018
ca0b7d3
copyWithin verified
Dec 14, 2018
8bd3651
more verification for copyWithin
Dec 14, 2018
b3c0a1f
gen arraybuffer and dataview
Dec 14, 2018
1a65829
more qualified imports
Dec 14, 2018
daa72e0
using inline ternary op
Dec 14, 2018
c909bd4
different gen paradigm
Dec 14, 2018
bcd0877
moving classes around - safe dataView modification
Dec 15, 2018
7148150
generating a data view with an offset, for a particular value
athanclark Dec 15, 2018
4f455d3
properly using uint
athanclark Dec 15, 2018
1dcde72
runners
athanclark Dec 15, 2018
2776488
using type-declared value sizes
athanclark Dec 15, 2018
5ce319b
verified data views
athanclark Dec 15, 2018
2fe5c9a
cosmetic
athanclark Dec 15, 2018
e4aed3a
better docs, noting how subArray / new use Data.ArrayBuffer.ArrayBuff…
Dec 15, 2018
d00e77b
reformatting arguments
Dec 15, 2018
2e5bf9f
final touch-ups
Dec 15, 2018
95bf30e
removing obsolete tests
Dec 15, 2018
e1689db
removed generated docs
Dec 19, 2018
29a14f8
omitting `try` in DataView.js
athanclark Jan 3, 2019
70e864b
Merge branch 'redesign' of github.com:athanclark/purescript-arraybuff…
athanclark Jan 3, 2019
289a9e9
better code re-use
athanclark Jan 3, 2019
9e8b567
fixing implementation
Jan 6, 2019
c5a1af4
reorganized setter
Jan 6, 2019
7f4819e
better design
Jan 6, 2019
f9f9d2b
omitting Arbitrary constraint
Jan 9, 2019
b066a6c
cosmetic
Jan 9, 2019
03469ac
Merge v9-redesign2
jacereda Jan 17, 2019
fdccca3
Some cosmetic changes and fixes.
jacereda Jan 17, 2019
6576b17
Sort includes
jacereda Jan 17, 2019
970351c
Sort includes
jacereda Jan 17, 2019
a880ebb
Still not happy with the names, renamed generators
jacereda Jan 17, 2019
2a2795b
toNullable Nothing -> null
jacereda Jan 17, 2019
316f099
toNullable . Just - > notNull
jacereda Jan 17, 2019
cfd98c5
Typo
jacereda Jan 17, 2019
83370eb
pure functions for filtering & querying
Jan 17, 2019
1b4aad4
Cherry-pick 83370eb9f96aa1638f1c532d0d4c10bdad295d1c, Uint32 instance…
Jan 17, 2019
d17d6c7
Fix the tests
jacereda Jan 18, 2019
eac7856
These share the implementation...
jacereda Jan 18, 2019
8ae9e7c
... and don't need to be part of the type class
jacereda Jan 18, 2019
c11a9c0
These can also be removed from the type class
jacereda Jan 18, 2019
be68a82
Simplify slice
jacereda Jan 18, 2019
ab94c97
Simplify subArray
jacereda Jan 18, 2019
120a692
Merge branch 'v9' of git://github.com/jacereda/purescript-arraybuffer…
Jan 18, 2019
48cff7a
unsafeAt should be like unsafeIndex in arrays
jacereda Jan 18, 2019
48d5826
Simplify fill
jacereda Jan 18, 2019
e08e284
Better name
jacereda Jan 18, 2019
17cf881
Use notNull
jacereda Jan 18, 2019
2b7b502
WIP, generate arrays with the size provided by QC, split functions th…
jacereda Jan 18, 2019
b4a9b19
Cleanup
jacereda Jan 18, 2019
a30e602
Fix set/setTyped
jacereda Jan 18, 2019
42f588f
Cleanup
jacereda Jan 18, 2019
8ee1263
Fix allImpliesAnyTests
jacereda Jan 18, 2019
7cde026
Use unsigned
jacereda Jan 19, 2019
95c4abc
Disable DataView tests
jacereda Jan 19, 2019
01c657e
Simplifying
jacereda Jan 19, 2019
491c92e
Introduce overAll1 to test over non-empty arrays
jacereda Jan 19, 2019
fa85219
using external float32 library
Jan 19, 2019
58cd006
WIP, making API more consistent with foldable-traversable methods
jacereda Jan 20, 2019
436819b
Merge master
jacereda Jan 22, 2019
07a501f
Enabled DataView tests
jacereda Jan 24, 2019
fde881b
Saturate arguments for runEffectFnX
jacereda Jan 24, 2019
4968226
Saturate arguments for run(Effect)FnX
jacereda Jan 24, 2019
23c5135
Make empty effectful
jacereda Jan 25, 2019
86fd6e8
Restore specific setters/getters in the API, changed implementation
jacereda Jan 25, 2019
e06a9a2
Merge branch 'v10' of git://github.com/jacereda/purescript-arraybuffe…
athanclark Jan 25, 2019
0fa0d7a
fixing tests
athanclark Jan 25, 2019
45f310a
restricted imports
athanclark Jan 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
elem, need to do find and indexing
  • Loading branch information
athanclark committed Dec 4, 2018
commit 3b246b9b964a1e066aae6e0f3e70b8cd2d690585
84 changes: 50 additions & 34 deletions src/Data/ArrayBuffer/Typed.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ exports.lengthImpl = function lemgthImpl (v) {

// Uint8Clamped

exports.newUint8ClampedArray = function newUint8ClampedArray (a) {
return new Uint8ClampedArray(a);
};
exports.newUint8ClampedArray2 = function newUint8ClampedArray2 (a,b) {
return new Uint8ClampedArray(a,b);
};
exports.newUint8ClampedArray3 = function newUint8ClampedArray3 (a,b,c) {
return new Uint8ClampedArray(a,b,c);
exports.newUint8ClampedArray = function newUint8ClampedArray (a,mb,mc) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something like:

function newArray(f, a, mb, mc) {
    return mc === null ? ( mb === null ? new f(a)
                                       : new f(a,mb)
                         )
                       : new f(a,mb,mc);
}

exports.newUint8ClampedArray = function newUint8ClampedArray (a,mb,mc) {
  return newArray(Uint8ClampedArray, a, mb, mc);
};

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh jeez, sorry. I thought JavaScript would be context-sensitive with new, and attempt to find a JS object constructor f or something... Shoot. Here let me fix this, one sec.

if (mc === null) {
if (mb === null) {
return new Uint8ClampedArray(a);
} else {
return new Uint8ClampedArray(a,mb);
}
} else {
return new Uint8ClampedArray(a,mb,mc);
}
};


Expand All @@ -56,14 +58,16 @@ exports.someImpl = function someImpl (a,p) {
};


exports.fillImpl = function fillImpl (a,x) {
return a.fill(x);
};
exports.fillImpl2 = function fillImpl2 (a,x,s) {
return a.fill(x,s);
};
exports.fillImpl3 = function fillImpl3 (a,x,s,e) {
return a.fill(x,s,e);
exports.fillImpl = function fillImpl (a,x,ms,me) {
if (me === null) {
if (ms === null) {
return a.fill(x);
} else {
return a.fill(x,ms);
}
} else {
return a.fill(x,ms,me);
}
};


Expand All @@ -79,6 +83,14 @@ exports.filterImpl = function filterImpl (a,p) {
return a.filter(p);
};

exports.includesImpl = function includesImpl (a,x,mo) {
if (mo === null) {
return a.includes(x);
} else {
return a.includes(x,mo);
}
};

exports.reduceImpl = function reduceImpl (a,f,i) {
return a.reduce(f,i);
};
Expand All @@ -93,11 +105,12 @@ exports.reduceRight1Impl = function reduceRight1Impl (a,f) {
};


exports.copyWithinImpl = function copyWithinImpl (a,t,s) {
a.copyWithin(t,s);
};
exports.copyWithinImpl3 = function copyWithinImpl (a,t,s,e) {
a.copyWithin(t,s,e);
exports.copyWithinImpl = function copyWithinImpl (a,t,s,me) {
if (me === null) {
a.copyWithin(t,s);
} else {
a.copyWithin(t,s,me);
}
};


Expand All @@ -115,14 +128,16 @@ exports.setImpl = function setImpl (a, off, b) {
};


exports.copy = function copy (a) {
return a.slice();
};
exports.sliceRemainderImpl = function sliceRemainderImpl (a,s) {
return a.slice(s);
};
exports.sliceImpl = function sliceImpl (a,s,e) {
return a.slice(s,e);
exports.sliceImpl = function sliceImpl (a,ms,me) {
if (me === null) {
if (ms === null) {
return a.slice();
} else {
return a.slice(ms);
}
} else {
return a.slice(s,e);
}
};


Expand All @@ -131,11 +146,12 @@ exports.sortImpl = function sortImpl (a) {
};


exports.subArrayImpl = function subArrayImpl (a,s) {
return a.subarray(s);
};
exports.subArrayImpl2 = function subArrayImpl2 (a,s,e) {
return a.subarray(s,e);
exports.subArrayImpl = function subArrayImpl (a,s,me) {
if (me === null) {
return a.subarray(s);
} else {
return a.subarray(s,me);
}
};


Expand Down
180 changes: 83 additions & 97 deletions src/Data/ArrayBuffer/Typed.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ module Data.ArrayBuffer.Typed
, bytesPerValue
, length
, class TypedArray
, whole, remainder, part, empty, fromArray, all, any, fill, fillRemainder, fillPart, set, set'
, map', traverse', traverse_', filter, foldlM', foldl', foldl1', foldrM', foldr', foldr1'
, copyWithin, copyWithinPart
, whole, remainder, part, empty, fromArray, all, any, fill, set
, map, traverse, traverse_, filter, elem, foldlM, foldl1M, foldl, foldl1, foldrM, foldr1M, foldr, foldr1
, copyWithin
, reverse
, setTyped, setTyped'
, copy, sliceRemainder, slice
, setTyped
, slice
, sort
, subArray, subArrayRemainder
, toString
, toString'
, unsafeAt
, hasIndex
, at
, subArray
, toString, toString'
, unsafeAt, hasIndex, at
, toArray
) where

Expand All @@ -33,8 +30,9 @@ import Effect (Effect)
import Effect.Uncurried
( EffectFn4, EffectFn3, EffectFn2, EffectFn1
, runEffectFn4, runEffectFn3, runEffectFn2, runEffectFn1
, mkEffectFn1, mkEffectFn2)
, mkEffectFn1, mkEffectFn2, mkEffectFn3)
import Effect.Unsafe (unsafePerformEffect)
import Data.Tuple (Tuple (..))
import Data.Nullable (Nullable, toNullable)
import Data.ArrayBuffer.Types
( ArrayView, kind ArrayViewType, ArrayBuffer, ByteOffset, ByteLength
Expand Down Expand Up @@ -86,27 +84,24 @@ length = lengthImpl

-- object creator implementations for each typed array

foreign import newUint8ClampedArray :: forall a. EffectFn1 a Uint8ClampedArray
foreign import newUint8ClampedArray2 :: EffectFn2 ArrayBuffer ByteOffset Uint8ClampedArray
foreign import newUint8ClampedArray3 :: EffectFn3 ArrayBuffer ByteOffset ByteLength Uint8ClampedArray
foreign import newUint8ClampedArray :: forall a. EffectFn3 a (Nullable ByteOffset) (Nullable ByteLength) Uint8ClampedArray


-- ----

foreign import everyImpl :: forall a b. Fn2 (ArrayView a) (b -> Boolean) Boolean
foreign import someImpl :: forall a b. Fn2 (ArrayView a) (b -> Boolean) Boolean
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 fillImpl :: forall a b. EffectFn2 (ArrayView a) b Unit
foreign import fillImpl2 :: forall a b. EffectFn3 (ArrayView a) b Offset Unit
foreign import fillImpl3 :: forall a b. EffectFn4 (ArrayView a) b Offset Offset Unit
foreign import fillImpl :: forall a b. EffectFn4 (ArrayView a) b (Nullable Offset) (Nullable Offset) Unit

foreign import mapImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn1 b b) (ArrayView a)
foreign import forEachImpl :: forall a b. EffectFn2 (ArrayView a) (EffectFn1 b Unit) Unit
foreign import filterImpl :: forall a b. Fn2 (ArrayView a) (b -> Boolean) (ArrayView a)
foreign import reduceImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn2 c b c) c c
foreign import reduce1Impl :: forall a b. Fn2 (ArrayView a) (Fn2 b b b) b
foreign import reduceRightImpl :: forall a b c. EffectFn3 (ArrayView a) (EffectFn2 c b c) c c
foreign import reduceRight1Impl :: forall a b. Fn2 (ArrayView a) (Fn2 b b b) b
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 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


-- | Value-oriented array offset
Expand All @@ -129,60 +124,58 @@ class TypedArray (a :: ArrayViewType) (t :: Type) | a -> t where
-- | Creates a typed array from an input array of values, to be binary serialized
fromArray :: Array t -> ArrayView a
-- | Test a predicate to pass on all values
all :: (t -> Boolean) -> ArrayView a -> Boolean
all :: (t -> Offset -> Effect Boolean) -> ArrayView a -> Effect Boolean
-- | Test a predicate to pass on any value
any :: (t -> Boolean) -> ArrayView a -> Boolean
any :: (t -> Offset -> Effect Boolean) -> ArrayView a -> Effect Boolean
-- | Fill the array with a value
fill :: ArrayView a -> t -> Effect Unit
-- | Fill the remainder of the array with a value
fillRemainder :: ArrayView a -> t -> Offset -> Effect Unit
-- | Fill part of the array with a value
fillPart :: ArrayView a -> t -> Offset -> Offset -> Effect Unit
fill :: ArrayView a -> t -> Maybe (Tuple Offset (Maybe Offset)) -> Effect Unit
-- | Stores multiple values into the typed array
set :: ArrayView a -> Array t -> Effect Unit
-- | Stores multiple values into the typed array, with offset
set' :: ArrayView a -> Offset -> Array t -> Effect Unit
set :: ArrayView a -> Maybe Offset -> Array t -> Effect Unit
-- | Maps a new value over the typed array, creating a new buffer and typed array as well.
map' :: (t -> t) -> ArrayView a -> ArrayView a
map :: (t -> Offset -> t) -> ArrayView a -> ArrayView a
-- | Traverses over each value, returning a new one
traverse' :: (t -> Effect t) -> ArrayView a -> Effect (ArrayView a)
traverse :: (t -> Offset -> Effect t) -> ArrayView a -> Effect (ArrayView a)
-- | Traverses over each value
traverse_' :: (t -> Effect Unit) -> ArrayView a -> Effect Unit
traverse_ :: (t -> Offset -> Effect Unit) -> ArrayView a -> Effect Unit
-- | Returns a new typed array with all values that pass the predicate
filter :: (t -> Boolean) -> ArrayView a -> ArrayView a
filter :: (t -> Offset -> Effect Boolean) -> ArrayView a -> Effect (ArrayView a)
-- | Tests if a value is an element of the typed array
elem :: t -> Maybe Offset -> ArrayView a -> Boolean
-- | Fetch element at index.
unsafeAt :: ArrayView a -> Offset -> Effect t
-- | Folding from the left
foldlM' :: forall b. ArrayView a -> (b -> t -> Effect b) -> b -> Effect b
foldlM :: forall b. ArrayView a -> (b -> t -> Offset -> Effect b) -> b -> Effect b
-- | Assumes the typed array is non-empty
foldl1' :: ArrayView a -> (t -> t -> t) -> t
foldl1M :: ArrayView a -> (t -> t -> Offset -> Effect t) -> Effect t
-- | Folding from the right
foldrM' :: forall b. ArrayView a -> (t -> b -> Effect b) -> b -> Effect b
foldrM :: forall b. ArrayView a -> (t -> b -> Offset -> Effect b) -> b -> Effect b
-- | Assumes the typed array is non-empty
foldr1' :: ArrayView a -> (t -> t -> t) -> t
foldr1M :: ArrayView a -> (t -> t -> Offset -> Effect t) -> Effect t

instance typedArrayUint8Clamped :: TypedArray Uint8Clamped Int where
whole a = unsafePerformEffect (runEffectFn1 newUint8ClampedArray a)
remainder = runEffectFn2 newUint8ClampedArray2
part = runEffectFn3 newUint8ClampedArray3
empty n = unsafePerformEffect (runEffectFn1 newUint8ClampedArray n)
fromArray a = unsafePerformEffect (runEffectFn1 newUint8ClampedArray a)
all p a = runFn2 everyImpl a p
any p a = runFn2 someImpl a p
fill = runEffectFn2 fillImpl
fillRemainder = runEffectFn3 fillImpl2
fillPart = runEffectFn4 fillImpl3
set a x = runEffectFn3 setImpl a (toNullable Nothing) x
set' a o x = runEffectFn3 setImpl a (toNullable (Just o)) x
map' f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn1 (pure <<< f)))
traverse' f a = runEffectFn2 mapImpl a (mkEffectFn1 f)
traverse_' f a = runEffectFn2 forEachImpl a (mkEffectFn1 f)
filter p a = runFn2 filterImpl a p
whole a = unsafePerformEffect (runEffectFn3 newUint8ClampedArray a (toNullable Nothing) (toNullable Nothing))
remainder a x = runEffectFn3 newUint8ClampedArray a (toNullable (Just x)) (toNullable Nothing)
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)
fill a x mz = case mz of
Nothing -> runEffectFn4 fillImpl a x (toNullable Nothing) (toNullable Nothing)
Just (Tuple s mq) -> case mq of
Nothing -> runEffectFn4 fillImpl a x (toNullable (Just s)) (toNullable Nothing)
Just e -> runEffectFn4 fillImpl a x (toNullable (Just s)) (toNullable (Just e))
set a mo x = runEffectFn3 setImpl a (toNullable mo) x
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)
elem x mo a = runFn3 includesImpl a x (toNullable mo)
unsafeAt = runEffectFn2 unsafeAtImpl
foldlM' a f = runEffectFn3 reduceImpl a (mkEffectFn2 f)
foldl1' a f = runFn2 reduce1Impl a (mkFn2 f)
foldrM' a f = runEffectFn3 reduceRightImpl a (mkEffectFn2 (flip f))
foldr1' a f = runFn2 reduceRight1Impl a (mkFn2 (flip f))
foldlM a f = runEffectFn3 reduceImpl a (mkEffectFn3 f)
foldl1M a f = runEffectFn2 reduce1Impl a (mkEffectFn3 f)
foldrM a f = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o))
foldr1M a f = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o))
-- instance typedArrayUint32 :: TypedArray Uint32 Number
-- instance typedArrayUint16 :: TypedArray Uint16 Int
-- instance typedArrayUint8 :: TypedArray Uint8 Int
Expand All @@ -191,21 +184,24 @@ instance typedArrayUint8Clamped :: TypedArray Uint8Clamped Int where
-- instance typedArrayInt8 :: TypedArray Int8 Int


foldl' :: forall a b t. TypedArray a t => ArrayView a -> (b -> t -> b) -> b -> b
foldl' a f i = unsafePerformEffect (foldlM' a (\acc x -> pure (f acc x)) i)
foldl :: forall a b t. TypedArray a t => ArrayView a -> (b -> t -> Offset -> b) -> b -> b
foldl a f i = unsafePerformEffect (foldlM a (\acc x o -> pure (f acc x o)) i)

foldr' :: forall a b t. TypedArray a t => ArrayView a -> (t -> b -> b) -> b -> b
foldr' a f i = unsafePerformEffect (foldrM' a (\x acc -> pure (f x acc)) i)
foldr :: forall a b t. TypedArray a t => ArrayView a -> (t -> b -> Offset -> b) -> b -> b
foldr a f i = unsafePerformEffect (foldrM a (\x acc o -> pure (f x acc o)) i)

foldl1 :: forall a t. TypedArray a t => ArrayView a -> (t -> t -> Offset -> t) -> t
foldl1 a f = unsafePerformEffect (foldl1M a (\acc x o -> pure (f acc x o)))

foreign import copyWithinImpl :: forall a. EffectFn3 (ArrayView a) Offset Offset Unit
foreign import copyWithinImpl3 :: forall a. EffectFn4 (ArrayView a) Offset Offset Offset Unit
foldr1 :: forall a t. TypedArray a t => ArrayView a -> (t -> t -> Offset -> t) -> t
foldr1 a f = unsafePerformEffect (foldr1M a (\x acc o -> pure (f x acc o)))


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 -> Effect Unit
copyWithin = runEffectFn3 copyWithinImpl
copyWithinPart :: forall a. ArrayView a -> Offset -> Offset -> Offset -> Effect Unit
copyWithinPart = runEffectFn4 copyWithinImpl3
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

Expand All @@ -217,25 +213,20 @@ foreign import setImpl :: forall a b. EffectFn3 (ArrayView a) (Nullable Offset)


-- | Stores multiple values in the typed array, reading input values from the second typed array.
setTyped :: forall a. ArrayView a -> ArrayView a -> Effect Unit
setTyped a x = runEffectFn3 setImpl a (toNullable Nothing) x

-- | Stores multiple values in the typed array, reading input values from the second typed array, with offset.
setTyped' :: forall a. ArrayView a -> Offset -> ArrayView a -> Effect Unit
setTyped' a o x = runEffectFn3 setImpl a (toNullable (Just o)) x
setTyped :: forall a. ArrayView a -> Maybe Offset -> ArrayView a -> Effect Unit
setTyped a mo x = runEffectFn3 setImpl a (toNullable mo) x


-- | Copy the entire contents of the typed array into a new buffer.
foreign import copy :: forall a. ArrayView a -> ArrayView a
foreign import sliceRemainderImpl :: forall a. Fn2 (ArrayView a) Offset (ArrayView a)
foreign import sliceImpl :: forall a. Fn3 (ArrayView a) Offset Offset (ArrayView a)
foreign import sliceImpl :: forall a. Fn3 (ArrayView a) (Nullable Offset) (Nullable Offset) (ArrayView a)

-- | Copy the remainder of contents of the typed array into a new buffer, after some start index.
sliceRemainder :: forall a. ArrayView a -> Offset -> ArrayView a
sliceRemainder = runFn2 sliceRemainderImpl
-- | Copy part of the contents of a typed array into a new buffer, between some start and end indices.
slice :: forall a. ArrayView a -> Offset -> Offset -> ArrayView a
slice = runFn3 sliceImpl
slice :: forall a. ArrayView a -> Maybe (Tuple Offset (Maybe Offset)) -> ArrayView a
slice a mz = case mz of
Nothing -> runFn3 sliceImpl a (toNullable Nothing) (toNullable Nothing)
Just (Tuple s me) -> case me of
Nothing -> runFn3 sliceImpl a (toNullable (Just s)) (toNullable Nothing)
Just e -> runFn3 sliceImpl a (toNullable (Just s)) (toNullable (Just e))


foreign import sortImpl :: forall a. EffectFn1 (ArrayView a) Unit
Expand All @@ -245,16 +236,11 @@ sort :: forall a. ArrayView a -> Effect Unit
sort = runEffectFn1 sortImpl


foreign import subArrayImpl :: forall a. Fn2 (ArrayView a) Offset (ArrayView a)
foreign import subArrayImpl2 :: forall a. Fn3 (ArrayView a) Offset Offset (ArrayView a)

foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) Offset (Nullable Offset) (ArrayView a)

-- | Returns a new typed array view of the same buffer, beginning at the index and ending at the second.
subArray :: forall a. ArrayView a -> Offset -> Offset -> ArrayView a
subArray = runFn3 subArrayImpl2
-- | Returns a new typed array view of the same buffer, beginning at the index
subArrayRemainder :: forall a. ArrayView a -> Offset -> ArrayView a
subArrayRemainder = runFn2 subArrayImpl
subArray :: forall a. ArrayView a -> Offset -> Maybe Offset -> ArrayView a
subArray a o mo = runFn3 subArrayImpl a o (toNullable mo)


-- | 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.
Expand Down