Outils pour utilisateurs

Outils du site


tech:notes_go_lang_programmation_fonctionnelle
,

Notes go lang programmation fonctionnelle

map

Voir :

package main
 
import "fmt"
 
//type f_ii func(int) int
 
//func MapInt(f f_ii, l []int) [](int) {
func MapInt(f func(int) int, l []int) [](int) {
        ret := []int{}
        for _, v := range l {
                ret = append(ret, f(v))
        }
        return (ret)
}
 
func carre(i int) int {
        return i * i
}
 
func main() {
        liste := []int{1, 2, 3}
        fmt.Println(MapInt(carre, liste))
}

FIXME

tech/notes_go_lang_programmation_fonctionnelle.txt · Dernière modification : de Jean-Baptiste

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki