10 examples of 'foreach golang' in Go

Every line of 'foreach golang' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
888func (lq *LinqObj) ForEach(line string, scope *Scope, args ...Object) Object {
889 if len(args) != 1 {
890 return NewError(line, ARGUMENTERROR, "1", len(args))
891 }
892
893 block, ok := args[0].(*Function)
894 if !ok {
895 return NewError(line, PARAMTYPEERROR, "first", "forEach", "*Function", args[0].Type())
896 }
897
898 s := NewScope(scope, nil)
899
900 next := lq.Query.Iterate()
901
902 for item, ok := next(); ok.Bool; item, ok = next() {
903 s.Set(block.Literal.Parameters[0].(*ast.Identifier).Value, item)
904 Eval(block.Literal.Body, s)
905 }
906
907 return NIL
908}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

33func (*Headers) ForEach(callback func(keyId []byte, status *mediakeystatus.MediaKeyStatus)) {
34 macro.Rewrite("$_.forEach($1)", callback)
35}
306func (cnt *htmlContents) forEach(it func(i int, line *htmlLine)) {
307 for i, l := range cnt.lines {
308 // skip unsupported tags
309 if _, ok := cnt.htmlTagWeights[l.tag.String()]; !ok {
310 continue
311 }
312 it(i, l)
313 }
314}
76func (node *TrieNode) ForEach(callback func(*TrieNode)) {
77 callback(node)
78 for _, child := range node.children {
79 child.ForEach(callback)
80 }
81}
51func (p astPackage) ForEach(filter func(node Node) error) error {
52 for _, file := range p.Files {
53 node := astFile{file}
54 if err := filter(node); err == ErrBreak {
55 return err
56 }
57 }
58 return nil
59}
160func ForEach(in, fn interface{}) {
161 sliceForEach(
162 reflect.ValueOf(in),
163 reflect.ValueOf(fn),
164 )
165}
119func (p *pathObject) ForEach(call otto.FunctionCall) otto.Value {
120 it := p.buildIteratorTree()
121 it.Tagger().Add(TopResultTag)
122 limit := -1
123 if len(call.ArgumentList) == 0 {
124 return otto.NullValue()
125 }
126 callback := call.Argument(len(call.ArgumentList) - 1)
127 args := exportArgs(call.ArgumentList[:len(call.ArgumentList)-1])
128 if len(args) > 0 {
129 limit = toInt(args[0])
130 }
131 p.wk.runIteratorWithCallback(it, callback, call, limit)
132 return otto.NullValue()
133}
31func (l plugins) foreach(cb interface{}) {
32 cbV := reflect.ValueOf(cb)
33 cbT := cbV.Type()
34 if cbT.Kind() != reflect.Func || cbT.NumIn() != 1 {
35 panic("foreach() requires a function of the signature func(T)")
36 }
37 ty := cbT.In(0)
38 for _, p := range l {
39 pV := reflect.ValueOf(p)
40 if pV.Type().Implements(ty) {
41 cbV.Call([]reflect.Value{pV})
42 }
43 }
44}
62func (cli *hostIterator) ForEach(itemCallback func(item HostInterface) error) (err error) {
63 var item HostInterface
64 for {
65
66 item, err = cli.Next()
67 if nil != err {
68 if io.EOF == err {
69 err = nil
70 }
71 break
72 }
73
74 if nil == item {
75 break
76 }
77
78 err = itemCallback(item)
79 if nil != err {
80 break
81 }
82 }
83 cli.bufIdx = 0
84 return err
85}
368func (file File) ForEach(callback func(line, value int)) {
369 for iter := file.tree.Min(); !iter.Limit(); iter = iter.Next() {
370 item := iter.Item()
371 key := int(item.Key)
372 var value int
373 if item.Value == math.MaxUint32 {
374 value = -1
375 } else {
376 value = int(item.Value)
377 }
378 callback(key, value)
379 }
380}

Related snippets