Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
fix: correct map values type (from String to Int)
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota committed Aug 23, 2024
1 parent 282f67f commit 0c85833
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pages/book/maps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ let fizz: map<Int, Int> = emptyMap();
fizz.set(68, 0);
// Getting the value by its key
let gotButUnsure: String? = fizz.get(68); // returns String or null, therefore the type is String?
let mustHaveGotOrErrored: String = fizz.get(68)!!; // explicitly asserting that the value must not be null,
// which may crush at runtime if the value is, in fact, null
let gotButUnsure: Int? = fizz.get(68); // returns Int or null, therefore the type is Int?
let mustHaveGotOrErrored: Int = fizz.get(68)!!; // explicitly asserting that the value must not be null,
// which may crush at runtime if the value is, in fact, null
// Alternatively, we can check for the key in the if statement
if (gotButUnsure != null) {
// Hooray, let's use !! without fear now and cast String? to String
let definitelyGotIt: String = fizz.get(68)!!;
// Hooray, let's use !! without fear now and cast Int? to Int
let definitelyGotIt: Int = fizz.get(68)!!;
} else {
// Do something else...
}
Expand Down Expand Up @@ -304,11 +304,11 @@ contract Example {
const MaxMapSize: Int = 42;
// Persistent state variables
arr: map<Int, Int>; // "array" of String values as a map
arrLength: Int = 0; // length of the "array", defaults to 0
arr: map<Int, Int>; // "array" of Int values as a map
arrLength: Int = 0; // length of the "array", defaults to 0
// Internal function for pushing an item to the end of the "array"
fun arrPush(item: String) {
fun arrPush(item: Int) {
if (self.arrLength >= self.MaxMapSize) {
// Do something, stop the operation, for example
} else {
Expand Down

0 comments on commit 0c85833

Please sign in to comment.