Skip to content

Commit f57407e

Browse files
committed
toArray
1 parent 3b031f4 commit f57407e

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/Data/ArrayBuffer/Typed.purs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Data.ArrayBuffer.Types
1010
foreign import data ArrayView :: * -> *
1111

1212
type Int8Array = ArrayView Int8
13-
--type Uint8Array = ArrayView Uint8
13+
type Uint8Array = ArrayView Uint8
1414
--type Uint8ClampedArray = ArrayView Uint8Clamped
1515
--type Int16Array = ArrayView Int16
1616
--type Uint16Array = ArrayView Uint16
@@ -26,6 +26,13 @@ function asInt8Array(v) {
2626
}
2727
""":: DataView -> Int8Array
2828

29+
foreign import asUint8Array
30+
"""
31+
function asUint8Array(v) {
32+
return new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
33+
}
34+
""":: DataView -> Uint8Array
35+
2936
foreign import dataView
3037
"""
3138
function dataView(a) {
@@ -54,3 +61,14 @@ at a n = if a `hasIndex` n then
5461
Just $ unsafeAt a n
5562
else
5663
Nothing
64+
65+
66+
foreign import toArray
67+
"""
68+
function toArray(a) {
69+
var ret = [];
70+
for (var i = 0, l = a.length; i < l; i++)
71+
ret[i] = a[i];
72+
return ret;
73+
}
74+
""" :: forall a. ArrayView a -> [Number]

src/Data/ArrayBuffer/Types.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type ByteLength = Number
55

66

77
newtype Int8 = Int8 Number
8-
--newtype Uint8
8+
newtype Uint8 = Uint8 Number
99
--newtype Uint8Clamped
1010
newtype Int16 = Int16 Number
1111
--newtype Uint16

test/Main.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ main = do
122122
let i8 = TA.asInt8Array dv
123123
((Just 2) == i8 `TA.at` 1) && (Nothing == i8 `TA.at` 4) && (Nothing == i8 `TA.at` (-1))
124124

125+
assert $ [1,2,3] == (TA.toArray $ TA.asInt8Array $ DV.whole $ AB.fromArray [1,2,3])
126+
127+
128+
125129
quickCheck' 5000 serdes
126130

127131
serdes :: M4I8 -> M4I8 -> M4I8 -> M4I8 -> Boolean

0 commit comments

Comments
 (0)