Created
December 5, 2014 16:52
-
-
Save jamesgarfield/4f967adcad71623a967b to your computer and use it in GitHub Desktop.
This file contains 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 | |
func (c Items) Len() int { | |
return len(c) | |
} | |
func (c Items) Swap(i, j int) { | |
c[i], c[j] = c[j], c[i] | |
} | |
func (c Items) All(fn func(*Item) bool) bool { | |
for _, v := range c { | |
if !fn(v) { | |
return false | |
} | |
} | |
return true | |
} | |
func (c Items) Any(fn func(*Item) bool) bool { | |
for _, v := range c { | |
if fn(v) { | |
return true | |
} | |
} | |
return false | |
} | |
func (c Items) Count(fn func(*Item) bool) int { | |
count := 0 | |
for _, v := range c { | |
if fn(v) { | |
count += 1 | |
} | |
} | |
return count | |
} | |
func (c Items) Each(fn func(*Item)) { | |
for _, v := range c { | |
fn(v) | |
} | |
} | |
func (c Items) First(fn func(*Item) bool) *Item { | |
for _, v := range c { | |
if fn(v) { | |
return v | |
} | |
} | |
return nil | |
} | |
func (c Items) Where(fn func(*Item) bool) (result Items) { | |
for _, v := range c { | |
if fn(v) { | |
result = append(result, v) | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment