From 0c858339a215a45a1be0167105b78d0be8063ae2 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:13:35 +0200 Subject: [PATCH] fix: correct map values type (from String to Int) --- pages/book/maps.mdx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pages/book/maps.mdx b/pages/book/maps.mdx index c7f48038..67a5350f 100644 --- a/pages/book/maps.mdx +++ b/pages/book/maps.mdx @@ -80,14 +80,14 @@ let fizz: map = 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... } @@ -304,11 +304,11 @@ contract Example { const MaxMapSize: Int = 42; // Persistent state variables - arr: map; // "array" of String values as a map - arrLength: Int = 0; // length of the "array", defaults to 0 + arr: map; // "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 {