What's the best way to create a parametrised List from a parametrised Type? The only way I can think of is:
listType := Str[]# list := listType.params["V"].emptyList.rw
Which leads me to my next question...
How do you create a parametrised Map from a parametrised Type?
mapType := Str:Int map := ...???
The obvious Str[]#.make or [Str:Int]#.make gives
Str[]#.make
[Str:Int]#.make
sys::Err: Type missing 'make' or 'defVal' slots: sys::Str[]
You mean like?
List.make(Str#, 10) Map.make(Str:Int#)
Yeah, like that!
: )
Cheers.
Following on, use Type.parameterize to create your map type.
Type.parameterize
static Obj:Obj makeMap(Type keyType, Type valType) { mapType := Map#.parameterize(["K":keyType, "V":valType]) return Map.make(mapType) }
BTW, simplest way to create list from type is Type.toListOf:
Type.toListOf
fansh> Str#.toListOf sys::Str[]
Login or Signup to reply.
SlimerDude Mon 1 Apr 2013
What's the best way to create a parametrised List from a parametrised Type? The only way I can think of is:
Which leads me to my next question...
How do you create a parametrised Map from a parametrised Type?
The obvious
Str[]#.make
or[Str:Int]#.make
givesandy Mon 1 Apr 2013
You mean like?
SlimerDude Mon 1 Apr 2013
Yeah, like that!
: )
Cheers.
SlimerDude Sat 11 May 2013
Following on, use
Type.parameterize
to create your map type.brian Sat 11 May 2013
BTW, simplest way to create list from type is
Type.toListOf
: