Ива обнови решението на 23.10.2018 22:37 (преди 10 месеца)
+package main
+
+func Repeater(s, sep string) func(int) string {
+
+ return func(num int) string {
+ result := s
+ for i := 0; i < num; i++ {
+
+ if i != num-2 {
+ result += sep + s
+ }
+
+ }
+ return result
+ }
+}
+
+func Generator(gen func(int) int, initial int) func() int {
+ return func() int {
+ defer func() { initial = gen(initial) }()
+ return initial
+ }
+}
+
+func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
+
+ return func(arr ...int) int {
+ for _, num := range arr {
+ initial = reducer(mapper(num), initial)
+
+ }
+ return initial
+ }
+
+}
Много ми харесва как е използван defer
в Generator
:)