Георги обнови решението на 19.10.2018 21:53 (преди 10 месеца)
+package main
+
+import (
+ "strings"
+)
+
+// Repeater accepts a string and a separator and returns a function
+// that repeats the string a given amount of times
+func Repeater(s, sep string) func(int) string {
+ return func(i int) string {
+ if i < 0 {
+ return ""
+ }
+
+ return strings.Trim(strings.Repeat(s+sep, i), sep)
Помислил ли си внимателно какво искаш да изтриеш?
+ }
+}
+
+// Generator take an initial value and generates numbers by
+// applying the generator function
+func Generator(gen func(int) int, initial int) func() int {
+ res := initial
+ return func() int {
+ prev := res
+ res = gen(res)
+ return prev
+ }
+}
+
+// MapReducer implements a composition of map and left fold
+// on the args passed to the returned func
+func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
+ res := initial
+ return func(args ...int) int {
+ for _, v := range args {
+ res = reducer(res, mapper(v))
+ }
+
+ return res
+ }
+}