Йордан обнови решението на 19.10.2014 21:11 (преди над 3 години)
+package main
+
+func Map(data []string, mapper func(string) string) []string {
+ //mapped := [len(data)]string{}
+ mapped := make([]string, len(data))
+ for i, v := range data {
+ mapped[i] = mapper(v)
+ }
+ return mapped
+}
+
+func Filter(data []string, predicate func(string) bool) []string {
+ //filtered := [len(data)]string{}
+ filtered := make([]string, len(data))
+ for _, value := range data {
+ if predicate(value) {
+ filtered = append(filtered, value)
+ }
+ }
+ return filtered
+}
+
+func Any(data []string, predicate func(string) bool) bool {
+ for _, value := range data {
+ if predicate(value) {
+ return true
+ }
+ }
+ return false
+}
+
+func All(data []string, predicate func(string) bool) bool {
+ for _, value := range data {
+ if !predicate(value) {
+ return false
+ }
+ }
+ return true
+}
+
+// TO BE CONTINUED WITH REDUCE