Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created January 27, 2022 20:01
Show Gist options
  • Save percybolmer/88da7ed363298f94870949ac653d1c89 to your computer and use it in GitHub Desktop.
Save percybolmer/88da7ed363298f94870949ac653d1c89 to your computer and use it in GitHub Desktop.
// Move is a generic function that takes in a Moveable and moves it
// Subtractable is placed infront of Moveable instead
func Move[S Subtractable, V Moveable[S]](v V, distance S, meters S) S {
v.Move(meters)
return Subtract(distance, meters)
}
// You can now do this instead of having to define Person
newDistanceLeft := Move[float64](p, float64(distanceLeft), 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment