github.com/searKing/golang/go@v1.2.117/strings/generator.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package strings 6 7 // JoinGenerator supplies sep between strings step by step, with mapping if consists 8 // [r0,r1,r2] -> "r0'""sep""r1'""sep""r2'" 9 func JoinGenerator(sep string, mapping func(s string) string) func(r string) string { 10 var written bool 11 return func(s string) string { 12 if mapping != nil { 13 s = mapping(s) 14 } 15 if written { 16 s = sep + s 17 } 18 written = true 19 return s 20 } 21 }