rokucommunity / brighterscript

A superset of Roku's BrightScript language
MIT License
152 stars 47 forks source link

Add generics support in the type system #441

Open TwitchBronBron opened 2 years ago

TwitchBronBron commented 2 years ago

Other languages (like TypeScript) have generics support. The BrighterScript type system should support them as well. For example:

function GetFirstItem<ListType>(list as List<ListType>)
    firstItem = list.First() as ListType
    return firstItem
end function
markwpearce commented 2 years ago

❤️

markwpearce commented 2 years ago

I assume class syntax would be similar?


class Queue<T>

  private data as T[] = []

  sub push(item as T)
    m.data.push(item)
  end sub

  function pop() as T
    return m.data.shift()
  end function

end class
TwitchBronBron commented 2 years ago

Yep I think that makes sense.