Created
December 19, 2017 04:41
-
-
Save xavivars/78f2ae61aacdfbf91341456c57dd9f3f to your computer and use it in GitHub Desktop.
Discard header and footer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func filter(s []int, c chan int, header int, footer int) { | |
var b []int | |
var e int | |
fmt.Println("test print in routing") | |
fmt.Printf("Initial elemements: %d\n", len(s)) | |
for _, v := range s { | |
//fmt.Printf("Iteration: %d\n", k) | |
if header > 0 { | |
fmt.Printf("Discarded as header: %d\n", v) | |
header-- | |
continue | |
} | |
if len(b) >= footer { | |
e, b = b[0], b[1:] | |
c <- e | |
} else { | |
//fmt.Printf("Size: %d\n", len(b)) | |
} | |
b = append(b, v) | |
} | |
close(c) | |
fmt.Printf("Discarded as footer: %v\n", b) | |
} | |
func main() { | |
fmt.Print("before\n") | |
s := []int{7, 2, 8, -9, 4, 0} | |
c := make(chan int) | |
go filter(s, c, 1, 2) | |
for i := range c { | |
fmt.Println(i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment