Божин обнови решението на 18.10.2018 23:19 (преди 10 месеца)
+package main
+
+func Repeater(s, sep string) func(int) string {
+ return func(times int) string {
+ res := ""
+ for i := 0; i < times; i++ {
+ if i > 0 {
+ res += sep
+ }
+ res += s
+ }
+ return res
+ }
+}
+
+func Generator(next func(int) int, current int) func() int {
+ return func() (result int) {
+ result = current
+ current = next(current)
+ return
+ }
+}
+
+func MapReducer(
+ mapper func(int) int,
+ reducer func(int, int) int,
+ initial int) func(...int) int {
+
+ return func(args ...int) int {
+ result := initial
+
+ for _, val := range args {
+ result = reducer(result, mapper(val))
+ }
+
+ return result
+ }
+}