medmond919 icon

Go Example #3

medmond919 | PRO | 03/26/18 04:32:54 PM UTC | 0 ⭐ | 234 👁️ | Never ⏰ | []
Go |

440 B

|

None

|

0 👍

/

0 👎

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"))
 
 
 
}

Comments