Skip to content

Commit

Permalink
deploy: bf31596
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanasa committed Feb 6, 2025
1 parent 7d7ad53 commit c39e8bb
Show file tree
Hide file tree
Showing 45 changed files with 7,481 additions and 0 deletions.
383 changes: 383 additions & 0 deletions pull/133/Array.html

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions pull/133/Blob.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<!DOCTYPE html>
<html><head title="Doc"><meta charset="UTF-8"/><link href="styles.css" rel="stylesheet"/></head><body><nav class="sidebar"><h3>Modules</h3><ul><li><li><a href="Array.html">Array</a></li></li><li><li><a href="Blob.html">Blob</a></li></li><li><li><a href="Bool.html">Bool</a></li></li><li><li><a href="CertifiedData.html">CertifiedData</a></li></li><li><li><a href="Char.html">Char</a></li></li><li><li><a href="Cycles.html">Cycles</a></li></li><li><li><a href="Debug.html">Debug</a></li></li><li><li><a href="Error.html">Error</a></li></li><li><li><a href="Float.html">Float</a></li></li><li><li><a href="Func.html">Func</a></li></li><li><li><a href="Int.html">Int</a></li></li><li><li><a href="Int16.html">Int16</a></li></li><li><li><a href="Int32.html">Int32</a></li></li><li><li><a href="Int64.html">Int64</a></li></li><li><li><a href="Int8.html">Int8</a></li></li><li><li><a href="InternetComputer.html">InternetComputer</a></li></li><li><li><a href="Iter.html">Iter</a></li></li><li><li><a href="List.html">List</a></li></li><li><li><a href="Map.html">Map</a></li></li><li><li><a href="Nat.html">Nat</a></li></li><li><li><a href="Nat16.html">Nat16</a></li></li><li><li><a href="Nat32.html">Nat32</a></li></li><li><li><a href="Nat64.html">Nat64</a></li></li><li><li><a href="Nat8.html">Nat8</a></li></li><li><li><a href="Option.html">Option</a></li></li><li><li><a href="Order.html">Order</a></li></li><li><li><a href="Principal.html">Principal</a></li></li><li><li><a href="Queue.html">Queue</a></li></li><li><li><a href="Random.html">Random</a></li></li><li><li><a href="Region.html">Region</a></li></li><li><li><a href="Result.html">Result</a></li></li><li><li><a href="Runtime.html">Runtime</a></li></li><li><li><a href="Set.html">Set</a></li></li><li><li><a href="Stack.html">Stack</a></li></li><li><li><a href="Text.html">Text</a></li></li><li><li><a href="Time.html">Time</a></li></li><li><li><a href="Timer.html">Timer</a></li></li><li><li><a href="Types.html">Types</a></li></li><li><li><a href="VarArray.html">VarArray</a></li></li><li><li><a href="immutable/Map.html">immutable/Map</a></li></li><li><li><a href="immutable/Queue.html">immutable/Queue</a></li></li><li><li><a href="immutable/Set.html">immutable/Set</a></li></li><li><li><a href="immutable/Stack.html">immutable/Stack</a></li></li></ul><h3>Declarations</h3><ul><li><li><a href="#type.Blob">Blob</a></li></li><li><li><a href="#empty">empty</a></li></li><li><li><a href="#size">size</a></li></li><li><li><a href="#fromArray">fromArray</a></li></li><li><li><a href="#fromVarArray">fromVarArray</a></li></li><li><li><a href="#toArray">toArray</a></li></li><li><li><a href="#toVarArray">toVarArray</a></li></li><li><li><a href="#hash">hash</a></li></li><li><li><a href="#compare">compare</a></li></li><li><li><a href="#equal">equal</a></li></li><li><li><a href="#notEqual">notEqual</a></li></li><li><li><a href="#less">less</a></li></li><li><li><a href="#lessOrEqual">lessOrEqual</a></li></li><li><li><a href="#greater">greater</a></li></li><li><li><a href="#greaterOrEqual">greaterOrEqual</a></li></li></ul></nav><div class="documentation"><h1>Blob</h1><p>Module for working with Blobs (immutable sequences of bytes).</p>
<p>Blobs represent sequences of bytes. They are immutable, iterable, but not indexable and can be empty.</p>
<p>Byte sequences are also often represented as <code>[Nat8]</code>, i.e. an array of bytes, but this representation is currently much less compact than <code>Blob</code>, taking 4 physical bytes to represent each logical byte in the sequence.
If you would like to manipulate Blobs, it is recommended that you convert
Blobs to <code>[var Nat8]</code> or <code>Buffer&lt;Nat8&gt;</code>, do the manipulation, then convert back.</p>
<p>Import from the base library to use this module.</p>
<pre><code>motoko name=import
import Blob &quot;mo:base/Blob&quot;;</code></pre>

<p>Some built in features not listed in this module:</p>
<ul><li>You can create a <code>Blob</code> literal from a <code>Text</code> literal, provided the context expects an expression of type <code>Blob</code>.</li><li><code>b.size() : Nat</code> returns the number of bytes in the blob <code>b</code>;</li><li><code>b.values() : Iter.Iter&lt;Nat8&gt;</code> returns an iterator to enumerate the bytes of the blob <code>b</code>.</li></ul>

<p>For example:</p>
<pre><code>motoko include=import
import Debug &quot;mo:base/Debug&quot;;
import Nat8 &quot;mo:base/Nat8&quot;;

let blob = &quot;\00\00\00\ff&quot; : Blob; // blob literals, where each byte is delimited by a back-slash and represented in hex
let blob2 = &quot;charsもあり&quot; : Blob; // you can also use characters in the literals
let numBytes = blob.size(); // =&gt; 4 (returns the number of bytes in the Blob)
for (byte : Nat8 in blob.values()) { // iterator over the Blob
Debug.print(Nat8.toText(byte))
}</code></pre><div class="declaration"><h4 class="type-declaration" id="type.Blob"><span class="keyword">type </span><span class="type">Blob</span> = <span class="type">Prim.Types.Blob</span></h4><p></p></div><div class="declaration"><h4 class="function" id="empty"><code><span class="keyword">public func </span><span class="fnname">empty</span>() : <a href="#type.Blob"><span class="type">Blob</span></a></code></h4><p><p>Returns an empty <code>Blob</code> (equivalent to <code>&quot;&quot;</code>).</p>
</p></div><div class="declaration"><h4 class="function" id="size"><code><span class="keyword">public func </span><span class="fnname">size</span>(<span class="parameter">blob</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Nat</span></code></h4><p></p></div><div class="declaration"><h4 class="function" id="fromArray"><code><span class="keyword">public func </span><span class="fnname">fromArray</span>(<span class="parameter">bytes</span> : [<span class="type">Nat8</span>]) : <a href="#type.Blob"><span class="type">Blob</span></a></code></h4><p><p>Creates a <code>Blob</code> from an array of bytes (<code>[Nat8]</code>), by copying each element.</p>
<p>Example:</p>
<pre><code>motoko include=import
let bytes : [Nat8] = [0, 255, 0];
let blob = Blob.fromArray(bytes); // =&gt; &quot;\00\FF\00&quot;</code></pre></p></div><div class="declaration"><h4 class="function" id="fromVarArray"><code><span class="keyword">public func </span><span class="fnname">fromVarArray</span>(<span class="parameter">bytes</span> : [<span class="keyword">var </span><span class="type">Nat8</span>]) : <a href="#type.Blob"><span class="type">Blob</span></a></code></h4><p><p>Creates a <code>Blob</code> from a mutable array of bytes (<code>[var Nat8]</code>), by copying each element.</p>
<p>Example:</p>
<pre><code>motoko include=import
let bytes : [var Nat8] = [var 0, 255, 0];
let blob = Blob.fromVarArray(bytes); // =&gt; &quot;\00\FF\00&quot;</code></pre></p></div><div class="declaration"><h4 class="function" id="toArray"><code><span class="keyword">public func </span><span class="fnname">toArray</span>(<span class="parameter">blob</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : [<span class="type">Nat8</span>]</code></h4><p><p>Converts a <code>Blob</code> to an array of bytes (<code>[Nat8]</code>), by copying each element.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob = &quot;\00\FF\00&quot; : Blob;
let bytes = Blob.toArray(blob); // =&gt; [0, 255, 0]</code></pre></p></div><div class="declaration"><h4 class="function" id="toVarArray"><code><span class="keyword">public func </span><span class="fnname">toVarArray</span>(<span class="parameter">blob</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : [<span class="keyword">var </span><span class="type">Nat8</span>]</code></h4><p><p>Converts a <code>Blob</code> to a mutable array of bytes (<code>[var Nat8]</code>), by copying each element.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob = &quot;\00\FF\00&quot; : Blob;
let bytes = Blob.toVarArray(blob); // =&gt; [var 0, 255, 0]</code></pre></p></div><div class="declaration"><h4 class="function" id="hash"><code><span class="keyword">public func </span><span class="fnname">hash</span>(<span class="parameter">blob</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <a href="Types.html#type.Hash"><span class="type">Types.Hash</span></a></code></h4><p><p>Returns the (non-cryptographic) hash of <code>blob</code>.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob = &quot;\00\FF\00&quot; : Blob;
Blob.hash(blob) // =&gt; 1_818_567_776</code></pre></p></div><div class="declaration"><h4 class="function" id="compare"><code><span class="keyword">public func </span><span class="fnname">compare</span>(<span class="parameter">b1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">b2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : {#less; #equal; #greater}</code></h4><p><p>General purpose comparison function for <code>Blob</code> by comparing the value of
the bytes. Returns the <code>Order</code> (either <code>#less</code>, <code>#equal</code>, or <code>#greater</code>)
by comparing <code>blob1</code> with <code>blob2</code>.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob1 = &quot;\00\00\00&quot; : Blob;
let blob2 = &quot;\00\FF\00&quot; : Blob;
Blob.compare(blob1, blob2) // =&gt; #less</code></pre></p></div><div class="declaration"><h4 class="function" id="equal"><code><span class="keyword">public func </span><span class="fnname">equal</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>Equality function for <code>Blob</code> types.
This is equivalent to <code>blob1 == blob2</code>.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob1 = &quot;\00\FF\00&quot; : Blob;
let blob2 = &quot;\00\FF\00&quot; : Blob;
ignore Blob.equal(blob1, blob2);
blob1 == blob2 // =&gt; true</code></pre>

<p>Note: The reason why this function is defined in this library (in addition
to the existing <code>==</code> operator) is so that you can use it as a function value
to pass to a higher order function.</p>
<p>Example:</p>
<pre><code>motoko include=import
import Buffer &quot;mo:base/Buffer&quot;;

let buffer1 = Buffer.Buffer&lt;Blob&gt;(3);
let buffer2 = Buffer.Buffer&lt;Blob&gt;(3);
Buffer.equal(buffer1, buffer2, Blob.equal) // =&gt; true</code></pre></p></div><div class="declaration"><h4 class="function" id="notEqual"><code><span class="keyword">public func </span><span class="fnname">notEqual</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>Inequality function for <code>Blob</code> types.
This is equivalent to <code>blob1 != blob2</code>.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob1 = &quot;\00\AA\AA&quot; : Blob;
let blob2 = &quot;\00\FF\00&quot; : Blob;
ignore Blob.notEqual(blob1, blob2);
blob1 != blob2 // =&gt; true</code></pre>

<p>Note: The reason why this function is defined in this library (in addition
to the existing <code>!=</code> operator) is so that you can use it as a function value
to pass to a higher order function.</p>
</p></div><div class="declaration"><h4 class="function" id="less"><code><span class="keyword">public func </span><span class="fnname">less</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>&quot;Less than&quot; function for <code>Blob</code> types.
This is equivalent to <code>blob1 &lt; blob2</code>.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob1 = &quot;\00\AA\AA&quot; : Blob;
let blob2 = &quot;\00\FF\00&quot; : Blob;
ignore Blob.less(blob1, blob2);
blob1 &lt; blob2 // =&gt; true</code></pre>

<p>Note: The reason why this function is defined in this library (in addition
to the existing <code>&lt;</code> operator) is so that you can use it as a function value
to pass to a higher order function.</p>
</p></div><div class="declaration"><h4 class="function" id="lessOrEqual"><code><span class="keyword">public func </span><span class="fnname">lessOrEqual</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>&quot;Less than or equal to&quot; function for <code>Blob</code> types.
This is equivalent to <code>blob1 &lt;= blob2</code>.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob1 = &quot;\00\AA\AA&quot; : Blob;
let blob2 = &quot;\00\FF\00&quot; : Blob;
ignore Blob.lessOrEqual(blob1, blob2);
blob1 &lt;= blob2 // =&gt; true</code></pre>

<p>Note: The reason why this function is defined in this library (in addition
to the existing <code>&lt;=</code> operator) is so that you can use it as a function value
to pass to a higher order function.</p>
</p></div><div class="declaration"><h4 class="function" id="greater"><code><span class="keyword">public func </span><span class="fnname">greater</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>&quot;Greater than&quot; function for <code>Blob</code> types.
This is equivalent to <code>blob1 &gt; blob2</code>.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob1 = &quot;\BB\AA\AA&quot; : Blob;
let blob2 = &quot;\00\00\00&quot; : Blob;
ignore Blob.greater(blob1, blob2);
blob1 &gt; blob2 // =&gt; true</code></pre>

<p>Note: The reason why this function is defined in this library (in addition
to the existing <code>&gt;</code> operator) is so that you can use it as a function value
to pass to a higher order function.</p>
</p></div><div class="declaration"><h4 class="function" id="greaterOrEqual"><code><span class="keyword">public func </span><span class="fnname">greaterOrEqual</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>&quot;Greater than or equal to&quot; function for <code>Blob</code> types.
This is equivalent to <code>blob1 &gt;= blob2</code>.</p>
<p>Example:</p>
<pre><code>motoko include=import
let blob1 = &quot;\BB\AA\AA&quot; : Blob;
let blob2 = &quot;\00\00\00&quot; : Blob;
ignore Blob.greaterOrEqual(blob1, blob2);
blob1 &gt;= blob2 // =&gt; true</code></pre>

<p>Note: The reason why this function is defined in this library (in addition
to the existing <code>&gt;=</code> operator) is so that you can use it as a function value
to pass to a higher order function.</p>
</p></div></div></body></html>
Loading

0 comments on commit c39e8bb

Please sign in to comment.