Posts

Showing posts from May, 2021

Callback Function -> Golang & NodeJS

Image
  Callback : P assing a Function as an Argument GoLang Example Supper Example 1: https://play.golang.org/p/AI8jKiYIKO6 Supper Example 2: Supper Example 3: package main import "fmt" func visit (numbers [] int , callback func ( int )) { for _ , n := range numbers { callback(n) } } func main () { visit ([] int { 1 , 2 , 3 , 4 } , func (n int ) { fmt . Println (n) }) } // callback: passing a func as an argument package main import "fmt" func filter (numbers [] int , callback func ( int ) bool ) [] int { var xs [] int for _ , n := range numbers { if callback(n) { xs = append (xs , n) } } return xs } func main () { xs := filter ([] int { 1 , 2 , 3 , 4 } , func (n int ) bool { return n > 1 }) fmt . Println (xs) // [2 3 4] } package main import ( "fmt" ) func main () { ii := [] int { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } s := sum (ii...) fmt . Println ...