Йончо обнови решението на 21.10.2014 00:09 (преди над 3 години)
+package main
+
+//map function
+func Map(data []string, mapper func(string) string) []string {
+ array := []string{}
+ for _, val := range data {
+ array = append(array, mapper(val))
+ }
+ return array
+}
+
+//filter function
+func Filter(data []string, predicate func(string) bool) []string {
+ array := []string{}
+ for _, val := range data {
+ if predicate(val) {
+ array = append(array, val)
+ }
+ }
+ return array
+}
+
+//reduce function
+func Reduce(data []string, combinator func(string, string) string) string {
+ var result string = ""
+ for _, val := range data {
+ result = combinator(result, val)
+ }
+ return result
+}
+
+// anyfunction
+func Any(data []string, predicate func(string) bool) bool {
+ for _, val := range data {
+ if predicate(val) == true {
+ return true
+ }
+ }
+ return false
+}
+
+//
+func All(data []string, predicate func(string) bool) bool {
+ for _, val := range data {
+ if predicate(val) != true {
+ return false
+ }
+ }
+ return true
+}
+
+func main() {
+
+}