You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "diamondburned (via GitHub)" <gi...@apache.org> on 2023/07/18 00:17:50 UTC

[GitHub] [beam] diamondburned commented on issue #21929: [Feature Request]: GoSDK: Generics API for beam

diamondburned commented on issue #21929:
URL: https://github.com/apache/beam/issues/21929#issuecomment-1639070206

   To slightly contribute to the wrapper library, this function adds a bit more runtime type safety for converting `beam.PCollection`s:
   
   ```go
   
   // CollectionOf returns a typed PCollection converted from the given
   // beam.PCollection. It exists for documenting purposes. If T doesn't match
   // with what is actually in pc, the function panics.
   func CollectionOf[T any](pc beam.PCollection) PCollection[T] {
   	var z T
   	if reflect.TypeOf(z) != pc.Type().Type() {
   		panic(fmt.Sprintf(
   			"CollectionOf given unexpected PCollection type: expected %v, got %v",
   			reflect.TypeOf(z), pc.Type().Type()))
   	}
   	return PCollection[T](pc)
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org