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])) ) ]);