From a9a853ec3a9646d292b83eaeca3c1efeeac36c56 Mon Sep 17 00:00:00 2001 From: Matthew Hammer Date: Mon, 13 Jun 2022 08:51:51 -0600 Subject: [PATCH 1/3] array to buffer. --- src/Array.mo | 8 ++++++++ test/arrayTest.mo | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/Array.mo b/src/Array.mo index 5e5220c6..b6ba5001 100644 --- a/src/Array.mo +++ b/src/Array.mo @@ -296,4 +296,12 @@ module { xs[size - 1 - n]; }); }; + + public func buffer(xs : [A]) : Buffer.Buffer { + let buff = Buffer.Buffer(xs.size()); + for (x in xs.vals()) { + buff.add(x) + }; + buff + }; } diff --git a/test/arrayTest.mo b/test/arrayTest.mo index 7690eef0..1c7a8982 100644 --- a/test/arrayTest.mo +++ b/test/arrayTest.mo @@ -216,6 +216,11 @@ let suite = Suite.suite("Array", [ "reverse", Array.reverse([0, 1, 2, 3]), M.equals(T.array(T.natTestable, [3, 2, 1, 0])) + ), + Suite.test( + "buffer", + Array.buffer([0, 1, 2, 3]).toArray(), + M.equals(T.array(T.natTestable, [0, 1, 2, 3])) ) ]); From 7e8624250aa15fa50f7dba7a05538d08cbda6474 Mon Sep 17 00:00:00 2001 From: Matthew Hammer Date: Mon, 13 Jun 2022 16:05:46 -0600 Subject: [PATCH 2/3] experiment. --- test/arrayTest.mo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/arrayTest.mo b/test/arrayTest.mo index 1c7a8982..9aa2495b 100644 --- a/test/arrayTest.mo +++ b/test/arrayTest.mo @@ -219,8 +219,8 @@ let suite = Suite.suite("Array", [ ), Suite.test( "buffer", - Array.buffer([0, 1, 2, 3]).toArray(), - M.equals(T.array(T.natTestable, [0, 1, 2, 3])) + Array.buffer([0, 1, 2, 3]).toArray(), + M.equals(T.array(T.natTestable, [0, 1, 2, 3])) ) ]); From 17ca208b826aac9044bc94a215ec001ac395ed28 Mon Sep 17 00:00:00 2001 From: Matthew Hammer Date: Mon, 13 Jun 2022 16:10:32 -0600 Subject: [PATCH 3/3] experiment concluded. --- test/arrayTest.mo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/arrayTest.mo b/test/arrayTest.mo index 9aa2495b..1c7a8982 100644 --- a/test/arrayTest.mo +++ b/test/arrayTest.mo @@ -219,8 +219,8 @@ let suite = Suite.suite("Array", [ ), Suite.test( "buffer", - Array.buffer([0, 1, 2, 3]).toArray(), - M.equals(T.array(T.natTestable, [0, 1, 2, 3])) + Array.buffer([0, 1, 2, 3]).toArray(), + M.equals(T.array(T.natTestable, [0, 1, 2, 3])) ) ]);