Слави обнови решението на 20.10.2018 23:33 (преди 10 месеца)
+package main
+
+func Repeater(
+ toRepeate string,
+ separator string,
+) func(int) string {
+ return func(times int) (result string) {
+ if times > 0 {
+ for i := 1; i < times; i++ {
+ result += toRepeate + separator
+ }
+ result += toRepeate
+ }
+ return
+ }
+}
+
+func Generator(
+ genFunction func(int) int,
+ current int,
+) func() int {
+ return func() (result int) {
+ result = current
+ current = genFunction(current)
+ return
+ }
+}
+
+func MapReducer(
+ mapper func(int) int,
+ reducer func(int, int) int,
+ initial int,
+) func(...int) int {
+ return func(values ...int) (result int) {
+ result = initial
+ for _, value := range values {
+ result = reducer(result, mapper(value))
+ }
+ return
+ }
+}