Иван обнови решението на 17.10.2014 13:26 (преди над 3 години)
+package main
+
+func Map(data []string, mapper func(string) string) []string {
+ mapped := make([]string, len(data))
+ for i, str := range data {
+ mapped[i] = mapper(str)
+ }
+ return mapped
+}
+
+func Filter(data []string, predicate func(string) bool) []string {
+ filtered := make([]string, 0)
+ for _, str := range data {
+ if predicate(str) {
+ filtered = append(filtered, str)
+ }
+ }
+ return filtered
+}
+
+func Reduce(data []string, combinator func(string, string) string) (result string) {
+ for _, str := range data {
+ result = combinator(result, str)
+ }
+ return
+}
+
+func All(data []string, predicate func(string) bool) bool {
+ result := true
+ for _, str := range data {
+ result = result && predicate(str)
+ }
+ return result
+}
+
+func Any(data []string, predicate func(string) bool) bool {
+ result := false
+ for _, str := range data {
+ result = result || predicate(str)
+ }
+ return result
+}