Skip to content

Instantly share code, notes, and snippets.

@ridhoperdana
Created December 30, 2020 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ridhoperdana/9a2ebd3ca8c28997df9ae8afe19b30b3 to your computer and use it in GitHub Desktop.
Save ridhoperdana/9a2ebd3ca8c28997df9ae8afe19b30b3 to your computer and use it in GitHub Desktop.
example of single responsibility principle
package main
import (
"fmt"
)
func printEngineerName(names []string) {
for index, engineer := range names {
fmt.Printf("Some string at index %v with value %v", index, engineer)
}
}
func addNewEngineer(currentEngineer []string, newEngineer string) (updatedEngineers []string) {
updatedEngineers = append(currentEngineer, newEngineer)
return updatedEngineers
}
func main() {
engineers := []string{"John", "Doe", "Budi"}
engineers = addNewEngineer(engineers, "Agus")
printEngineerName(engineers)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment