caioreix
(caioreix)
1
I read in verse language reference that maps can use as key some different types like:
- A class, if it’s comparable
- An option, if the element type is comparable
- An array, if the element type is comparable
- A map if both the key and the value types are comparable
- A tuple if all elements in the tuple are comparable
But I’m not achieving success with my attempts. If someone could provide me with an example of each type, I would appreciate it!
1 Like
Did you add the comparable type to the values you want to use in your map?
Can you add your code example?
1 Like
My results:
maps := class():
ClassMap : [unique_class]string = map{}
OptionMap : [?int]string = map{}
ArrayMap : [[]unique_class]string = map{} # SAYS IT IS NOT IMPLEMENTED YET
MapMap : [[unique_class]unique_class]string = map{} # SAYS IT IS NOT IMPLEMENTED YET
TupleMap : [tuple(unique_class, unique_class)]string = map{} # SAYS IT IS NOT IMPLEMENTED YET
unique_class := class<unique>():
4 Likes
Just wanted to confirm that this is correct. Arrays, maps, and tuples are comparable, but we do not yet implement using them as map keys.
2 Likes