Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func Map(f func(*), s ...) [] {
- for i := range s {
- f(&s[i])
- }
- return s
- }
- func squareInt(n *int) {
- *n = (*n) * (*n)
- }
- func squareFloat(n *float64) {
- *n = (*n) * (*n)
- }
- func dupliString(s *string) {
- *s = (*s) + (*s)
- }
- func main(){
- fmt.Println(Map(squareInt, 1, 2, 3, 4))
- fmt.Println(Map(squareFloat, 1.0, 2.0, 3.0, 4.0))
- fmt.Println(Map(dupliString, "Hello", "world"))
- }
Add Comment
Please, Sign In to add comment