We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
func get
1 parent 6072003 commit 7ff6663Copy full SHA for 7ff6663
src/Blob.mo
@@ -69,6 +69,21 @@ module {
69
/// ```
70
public func size(blob : Blob) : Nat = blob.size();
71
72
+ /// Returns the byte at index `index` as an option.
73
+ /// Returns `null` when `index >= size`. Indexing is zero-based.
74
+ ///
75
+ /// Example:
76
+ /// ```motoko include=import
77
+ /// let blob : Blob = "abcdefg\08";
78
+ /// assert Blob.get(blob, 8) == ?8;
79
+ /// assert Blob.get(blob, 10) == null;
80
+ /// ```
81
82
+ /// Runtime: `O(1)`
83
84
+ /// Space: `O(1)`
85
+ public func get(blob : Blob, index : Nat) : ?Nat8 = if (index < blob.size()) ?(blob.get index) else null;
86
+
87
/// Creates a `Blob` from an array of bytes (`[Nat8]`), by copying each element.
88
///
89
/// Example:
0 commit comments