Пламен обнови решението на 22.10.2018 06:52 (преди 10 месеца)
+package main
+
+import "strings"
+
+func Repeater(s, sep string) func(int) string {
+ return func(count int) string {
+ if count <= 0 {
+ return ""
+ }
+
+ var builder strings.Builder
+ builder.WriteString(s)
+
+ for c := 0; c < count-1; c = c + 1 {
+ builder.WriteString(sep)
+ builder.WriteString(s)
+ }
+
+ return builder.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 _, arg := range args {
+ accumulator = reducer(accumulator, mapper(arg))
+ }
+
+ return accumulator
+ }
+}
+
+func main() {}