diff --git a/package-set.dhall b/package-set.dhall index 4efcd31..325bbc2 100644 --- a/package-set.dhall +++ b/package-set.dhall @@ -4,8 +4,8 @@ let Package = { name : Text, version : Text, repo : Text, dependencies : List Te let additions = [ { name = "io" , repo = "https://github.com/aviate-labs/io.mo" - , version = "v0.3.0" - , dependencies = ["base"] + , version = "v0.3.1" + , dependencies = [ "base" ] } ] : List Package diff --git a/src/LFSR.mo b/src/LFSR.mo index 22babe5..42d8609 100644 --- a/src/LFSR.mo +++ b/src/LFSR.mo @@ -1,4 +1,4 @@ -import Array "mo:base/Array"; +import Buffer "mo:base/Buffer"; import Int "mo:base/Int"; import IO "mo:io/IO"; import Iter "mo:base/Iter"; @@ -94,14 +94,14 @@ module { let lfsr = feed; var restarted = false; public func read(n : Nat) : IO.Result<[T]> { - var ts : [T] = []; + let ts = Buffer.Buffer(n); for (i in Iter.range(0, n-1)) { - if (restarted) return #eof(ts); + if (restarted) return #eof(ts.toArray()); let (v, r) = lfsr.next(); restarted := r; - ts := Array.append(ts, [v]); + ts.add(v); }; - #ok(ts); + #ok(ts.toArray()); }; }; diff --git a/src/XorShift.mo b/src/XorShift.mo index 7d5b901..089d7d1 100644 --- a/src/XorShift.mo +++ b/src/XorShift.mo @@ -1,4 +1,3 @@ -import Array "mo:base/Array"; import Binary "mo:encoding/Binary"; import Buffer "mo:base/Buffer"; import Int "mo:base/Int"; @@ -40,7 +39,7 @@ module { let xors = gen; let bs = Buffer.Buffer(8); public func read(n : Nat) : IO.Result<[Nat8]> { - var ts : [Nat8] = []; + let ts = Buffer.Buffer(n); for (_ in Iter.range(0, n-1)) { if (bs.size() == 0) { for (b in Binary.BigEndian.fromNat64(gen.next()).vals()) { @@ -49,12 +48,12 @@ module { }; switch (bs.removeLast()) { case (? v) { - ts := Array.append(ts, [v]); + ts.add(v); }; - case (null) return #eof(ts); + case (null) return #eof(ts.toArray()); }; }; - #ok(ts); + #ok(ts.toArray()); }; }; };