#2601 Type.emptyMap() ?

SlimerDude Fri 14 Apr

I use Type.emptyList() quite a lot:

Int#.emptyList

Any chance of it getting a companion Type.emptyMap()?

[Str:Int]#.emptyMap

I know it's not quite the same (as emptyList() takes an item type, not the list type), but I do miss a empty Map singleton. I'd even settle for Map.defVal.

brian Wed 23 Aug

The reason emptyList makes sense is because the base type is a singleton and you can cache things. It wouldn't make sense for map types because they are created on the fly - so you wouldn't get the same cacheing performance. This would be probably as close as you could get:

Map(Str:Int#).toImmutable

Login or Signup to reply.