Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with V Programming

You're reading from   Getting Started with V Programming An end-to-end guide to adopting the V language from basic variables and modules to advanced concurrency

Arrow left icon
Product type Paperback
Published in Dec 2021
Publisher Packt
ISBN-13 9781839213434
Length 408 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Navule Pavan Kumar Rao Navule Pavan Kumar Rao
Author Profile Icon Navule Pavan Kumar Rao
Navule Pavan Kumar Rao
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Section 1: Introduction to the V Programming Language
2. Chapter 1: Introduction to V Programming FREE CHAPTER 3. Chapter 2: Installing V Programming 4. Section 2: Basics of V Programming
5. Chapter 3: Variables, Constants, and Code Comments 6. Chapter 4: Primitive Data Types 7. Chapter 5: Arrays and Maps 8. Chapter 6: Conditionals and Iterative Statements 9. Chapter 7: Functions 10. Chapter 8: Structs 11. Chapter 9: Modules 12. Section 3: Advanced Concepts in V Programming
13. Chapter 10: Concurrency 14. Chapter 11: Channels – An Advanced Concurrency Pattern 15. Chapter 12: Testing 16. Chapter 13: Introduction to JSON and ORM 17. Chapter 14: Building a Microservice 18. Other Books You May Enjoy

Maps

A map is used to represent a collection of key-value pairs. The keys need to be of a primitive data type. A map is defined using the map keyword. By default, maps are immutable. We can define a mutable map using the mut keyword.

Maps are like dictionary types in other programming languages such as Dictionary in C#, HashMap in Java, and dict in Python. We will explore how to work with maps, including various ways in which to initialize maps. Then, we will look at how to add, update, or delete key-value pairs from the map.

The explicit initialization of a map

The following code presents the syntax to define a map in V:

mut MAP_NAME := map[KEY_TYPE]VALUE_TYPE{}

The preceding syntax shows the explicit initialization of an empty mutable map. Here, MAP_NAME is a variable name for the map that follows a standard variable naming convention. Then, to the right-hand side of :=, we have used the map keyword. KEY_TYPE must be a primitive data type such as string, rune, and...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime