本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
3.2KB

  1. // Copyright (c) 2015, Emir Pasic. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package containers
  5. // EnumerableWithIndex provides functions for ordered containers whose values can be fetched by an index.
  6. type EnumerableWithIndex interface {
  7. // Each calls the given function once for each element, passing that element's index and value.
  8. Each(func(index int, value interface{}))
  9. // Map invokes the given function once for each element and returns a
  10. // container containing the values returned by the given function.
  11. // TODO would appreciate help on how to enforce this in containers (don't want to type assert when chaining)
  12. // Map(func(index int, value interface{}) interface{}) Container
  13. // Select returns a new container containing all elements for which the given function returns a true value.
  14. // TODO need help on how to enforce this in containers (don't want to type assert when chaining)
  15. // Select(func(index int, value interface{}) bool) Container
  16. // Any passes each element of the container to the given function and
  17. // returns true if the function ever returns true for any element.
  18. Any(func(index int, value interface{}) bool) bool
  19. // All passes each element of the container to the given function and
  20. // returns true if the function returns true for all elements.
  21. All(func(index int, value interface{}) bool) bool
  22. // Find passes each element of the container to the given function and returns
  23. // the first (index,value) for which the function is true or -1,nil otherwise
  24. // if no element matches the criteria.
  25. Find(func(index int, value interface{}) bool) (int, interface{})
  26. }
  27. // EnumerableWithKey provides functions for ordered containers whose values whose elements are key/value pairs.
  28. type EnumerableWithKey interface {
  29. // Each calls the given function once for each element, passing that element's key and value.
  30. Each(func(key interface{}, value interface{}))
  31. // Map invokes the given function once for each element and returns a container
  32. // containing the values returned by the given function as key/value pairs.
  33. // TODO need help on how to enforce this in containers (don't want to type assert when chaining)
  34. // Map(func(key interface{}, value interface{}) (interface{}, interface{})) Container
  35. // Select returns a new container containing all elements for which the given function returns a true value.
  36. // TODO need help on how to enforce this in containers (don't want to type assert when chaining)
  37. // Select(func(key interface{}, value interface{}) bool) Container
  38. // Any passes each element of the container to the given function and
  39. // returns true if the function ever returns true for any element.
  40. Any(func(key interface{}, value interface{}) bool) bool
  41. // All passes each element of the container to the given function and
  42. // returns true if the function returns true for all elements.
  43. All(func(key interface{}, value interface{}) bool) bool
  44. // Find passes each element of the container to the given function and returns
  45. // the first (key,value) for which the function is true or nil,nil otherwise if no element
  46. // matches the criteria.
  47. Find(func(key interface{}, value interface{}) bool) (interface{}, interface{})
  48. }
上海开阖软件有限公司 沪ICP备12045867号-1