File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,18 @@ module {
8484 // / Space: `O(1)`
8585 public func get(blob : Blob , index : Nat ) : ?Nat8 = if (index < blob. size()) ?(blob. get index) else null ;
8686
87+ // / Returns the byte at index `index`. Indexing is zero-based.
88+ // / Traps if `index >= size`, error message may not be descriptive.
89+ // /
90+ // / Example:
91+ // / ```motoko include=import
92+ // / let blob : Blob = "abcdefgh\08";
93+ // / assert Blob.get(blob, 8) == 8;
94+ // / ```
95+ // /
96+ // / Runtime: `O(1)`
97+ public func at(blob : Blob , index : Nat ) : Nat8 = blob. get index;
98+
8799 // / Creates a `Blob` from an array of bytes (`[Nat8]`), by copying each element.
88100 // /
89101 // / Example:
Original file line number Diff line number Diff line change 4949 {
5050 "name" : " Blob" ,
5151 "exports" : [
52+ " public func at(blob : Blob, index : Nat) : Nat8" ,
5253 " public type Blob" ,
5354 " public func compare(b1 : Blob, b2 : Blob) : Order.Order" ,
5455 " public func empty() : Blob" ,
You can’t perform that action at this time.
0 commit comments