Иван обнови решението на 22.10.2018 21:11 (преди 10 месеца)
+package main
+
+func Repeater(s, sep string) func(int) string {
+ return func(i int) string {
+ if i <= 0 {
+ return ""
+
+ }
+ result := s
+ for j := 0; j < i-1; j++ {
+ result += sep + s
+ }
+ return result
+ }
+}
+
+func Generator(gen func(int) int, initial int) func() int {
+ return func() (result int) {
+ result = initial
+ initial = gen(initial)
+ return
+ }
+}
+
+func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
+ return func(args ...int) (result int) {
+ for _, v := range args {
+ result = reducer(result, mapper(v))
+ }
+
+ return
+ }
+}