func.go 728 B

123456789101112131415161718192021222324252627282930313233
  1. package iter
  2. // Callback receives a value and returns true if another value should be
  3. // received or false to stop iteration.
  4. type Callback func(value interface{}) (more bool)
  5. // Func iterates by calling Callback for each of its values.
  6. type Func func(Callback)
  7. func All(cb Callback, fs ...Func) bool {
  8. for _, f := range fs {
  9. all := true
  10. f(func(v interface{}) bool {
  11. all = all && cb(v)
  12. return all
  13. })
  14. if !all {
  15. return false
  16. }
  17. }
  18. return true
  19. }
  20. // Calls `cb` with the first value yielded by `f` and then stops iteration. `ok` if `cb` was called
  21. // with a value.
  22. func First(cb func(value interface{}),f Func) (ok bool) {
  23. f(func(value interface{}) bool {
  24. ok = true
  25. cb(value)
  26. return false
  27. })
  28. return
  29. }