Димитър обнови решението на 20.10.2018 16:12 (преди 10 месеца)
+package main
+
+func Repeater(s, sep string) func(int) string {
+ return func(n int) string {
+ result := ""
+ for i := 0; i < n-1; i++ {
+ result += s
+ result += sep
+ }
+ return result + s
+ }
+}
+
+func Generator(gen func(int) int, initial int) func() int {
+ last := initial
+ return func() int {
+ defer func() { last = gen(last) }()
+ return last
+ }
+}
+
+func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
+ return func(args ...int) int {
+ for i, v := range args {
+ args[i] = mapper(v)
+ }
+ result := initial
+ for _, v := range args {
+ result = reducer(result, v)
+ }
+ return result
+ }
+}