Иван обнови решението на 24.10.2018 13:01 (преди 10 месеца)
+package main
+
+func Repeater(s, sep string) func(int) string {
+ return func(a int) string {
+ var result string
+ for i := 0; i < a-1; i++ {
+ result += s
+ result += sep
+ }
+ result += s
+ return result
+ }
+}
+
+func Generator(gen func(int) int, initial int) func() int {
+ return func() int {
+ var result int = initial
+ initial = gen(result)
+ return result
+ }
+}
+
+func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
+ var result int = initial
+ return func(a ...int) int {
+ for _, num := range a {
+ result = reducer(result, mapper(num))
+ }
+ return result
+ }
+}