Красена обнови решението на 20.10.2018 16:39 (преди 10 месеца)
+package main
+
+func Repeater(s, sep string) func(int) string {
+ return func(x int) string {
+ res := ""
+ if x <= 0 {
+ return res
+ }
+ for i := 0; i < x-1; i++ {
+ res = res + s + sep
+ }
+ res = res + s
+ return res
+ }
+}
+
+func Generator(gen func(int) int, initial int) func() int {
+ return func() int {
+ next := initial
+ initial = gen(next)
+ return next
+ }
+}
+
+func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
+ return func(arr ...int) int {
+ res := initial
+ for _, val := range arr {
+ res = reducer(res, mapper(val))
+ }
+ return res
+ }
+}