Николай обнови решението на 17.10.2018 23:44 (преди 10 месеца)
+package main
+
+import (
+ "strings"
+)
+
+func Repeater(s, sep string) func(int) string {
+ return func(times int) string {
+ var buffer strings.Builder
+ for i := 0; i < times; i++ {
+ if i > 0 {
+ buffer.WriteString(sep)
+ }
+
+ buffer.WriteString(s)
+ }
+ return buffer.String()
+ }
+}
+
+func Generator(gen func(int) int, initial int) func() int {
+ accumulator := initial
+ return func() int {
+ result := accumulator
+ accumulator = gen(accumulator)
+ return result
+ }
+}
+
+func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
+ return func(args ...int) int {
+ accumulator := initial
+ for _, num := range args {
+ accumulator = reducer(accumulator, mapper(num))
+ }
+ return accumulator
+ }
+}