/
ChanFsPathS.dot.go
311 lines (272 loc) · 8.57 KB
/
ChanFsPathS.dot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// Copyright 2017 Andreas Pannewitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fsc
// This file was generated with dotgo
// DO NOT EDIT - Improve the pattern!
import (
"github.com/GoLangsam/container/ccsafe/fs"
)
// MakeFsPathSChan returns a new open channel
// (simply a 'chan fs.FsPathS' that is).
//
// Note: No 'FsPathS-producer' is launched here yet! (as is in all the other functions).
//
// This is useful to easily create corresponding variables such as
//
// var myFsPathSPipelineStartsHere := MakeFsPathSChan()
// // ... lot's of code to design and build Your favourite "myFsPathSWorkflowPipeline"
// // ...
// // ... *before* You start pouring data into it, e.g. simply via:
// for drop := range water {
// myFsPathSPipelineStartsHere <- drop
// }
// close(myFsPathSPipelineStartsHere)
//
// Hint: especially helpful, if Your piping library operates on some hidden (non-exported) type
// (or on a type imported from elsewhere - and You don't want/need or should(!) have to care.)
//
// Note: as always (except for PipeFsPathSBuffer) the channel is unbuffered.
//
func MakeFsPathSChan() (out chan fs.FsPathS) {
return make(chan fs.FsPathS)
}
func sendFsPathS(out chan<- fs.FsPathS, inp ...fs.FsPathS) {
defer close(out)
for i := range inp {
out <- inp[i]
}
}
// ChanFsPathS returns a channel to receive all inputs before close.
func ChanFsPathS(inp ...fs.FsPathS) (out <-chan fs.FsPathS) {
cha := make(chan fs.FsPathS)
go sendFsPathS(cha, inp...)
return cha
}
func sendFsPathSSlice(out chan<- fs.FsPathS, inp ...[]fs.FsPathS) {
defer close(out)
for i := range inp {
for j := range inp[i] {
out <- inp[i][j]
}
}
}
// ChanFsPathSSlice returns a channel to receive all inputs before close.
func ChanFsPathSSlice(inp ...[]fs.FsPathS) (out <-chan fs.FsPathS) {
cha := make(chan fs.FsPathS)
go sendFsPathSSlice(cha, inp...)
return cha
}
func chanFsPathSFuncNil(out chan<- fs.FsPathS, act func() fs.FsPathS) {
defer close(out)
for {
res := act() // Apply action
if res == nil {
return
}
out <- res
}
}
// ChanFsPathSFuncNil returns a channel to receive all results of act until nil before close.
func ChanFsPathSFuncNil(act func() fs.FsPathS) (out <-chan fs.FsPathS) {
cha := make(chan fs.FsPathS)
go chanFsPathSFuncNil(cha, act)
return cha
}
func chanFsPathSFuncNok(out chan<- fs.FsPathS, act func() (fs.FsPathS, bool)) {
defer close(out)
for {
res, ok := act() // Apply action
if !ok {
return
}
out <- res
}
}
// ChanFsPathSFuncNok returns a channel to receive all results of act until nok before close.
func ChanFsPathSFuncNok(act func() (fs.FsPathS, bool)) (out <-chan fs.FsPathS) {
cha := make(chan fs.FsPathS)
go chanFsPathSFuncNok(cha, act)
return cha
}
func chanFsPathSFuncErr(out chan<- fs.FsPathS, act func() (fs.FsPathS, error)) {
defer close(out)
for {
res, err := act() // Apply action
if err != nil {
return
}
out <- res
}
}
// ChanFsPathSFuncErr returns a channel to receive all results of act until err != nil before close.
func ChanFsPathSFuncErr(act func() (fs.FsPathS, error)) (out <-chan fs.FsPathS) {
cha := make(chan fs.FsPathS)
go chanFsPathSFuncErr(cha, act)
return cha
}
func joinFsPathS(done chan<- struct{}, out chan<- fs.FsPathS, inp ...fs.FsPathS) {
defer close(done)
for i := range inp {
out <- inp[i]
}
done <- struct{}{}
}
// JoinFsPathS sends inputs on the given out channel and returns a done channel to receive one signal when inp has been drained
func JoinFsPathS(out chan<- fs.FsPathS, inp ...fs.FsPathS) (done <-chan struct{}) {
cha := make(chan struct{})
go joinFsPathS(cha, out, inp...)
return cha
}
func joinFsPathSSlice(done chan<- struct{}, out chan<- fs.FsPathS, inp ...[]fs.FsPathS) {
defer close(done)
for i := range inp {
for j := range inp[i] {
out <- inp[i][j]
}
}
done <- struct{}{}
}
// JoinFsPathSSlice sends inputs on the given out channel and returns a done channel to receive one signal when inp has been drained
func JoinFsPathSSlice(out chan<- fs.FsPathS, inp ...[]fs.FsPathS) (done <-chan struct{}) {
cha := make(chan struct{})
go joinFsPathSSlice(cha, out, inp...)
return cha
}
func joinFsPathSChan(done chan<- struct{}, out chan<- fs.FsPathS, inp <-chan fs.FsPathS) {
defer close(done)
for i := range inp {
out <- i
}
done <- struct{}{}
}
// JoinFsPathSChan sends inputs on the given out channel and returns a done channel to receive one signal when inp has been drained
func JoinFsPathSChan(out chan<- fs.FsPathS, inp <-chan fs.FsPathS) (done <-chan struct{}) {
cha := make(chan struct{})
go joinFsPathSChan(cha, out, inp)
return cha
}
func doitFsPathS(done chan<- struct{}, inp <-chan fs.FsPathS) {
defer close(done)
for i := range inp {
_ = i // Drain inp
}
done <- struct{}{}
}
// DoneFsPathS returns a channel to receive one signal before close after inp has been drained.
func DoneFsPathS(inp <-chan fs.FsPathS) (done <-chan struct{}) {
cha := make(chan struct{})
go doitFsPathS(cha, inp)
return cha
}
func doitFsPathSSlice(done chan<- ([]fs.FsPathS), inp <-chan fs.FsPathS) {
defer close(done)
FsPathSS := []fs.FsPathS{}
for i := range inp {
FsPathSS = append(FsPathSS, i)
}
done <- FsPathSS
}
// DoneFsPathSSlice returns a channel which will receive a slice
// of all the FsPathSs received on inp channel before close.
// Unlike DoneFsPathS, a full slice is sent once, not just an event.
func DoneFsPathSSlice(inp <-chan fs.FsPathS) (done <-chan ([]fs.FsPathS)) {
cha := make(chan ([]fs.FsPathS))
go doitFsPathSSlice(cha, inp)
return cha
}
func doitFsPathSFunc(done chan<- struct{}, inp <-chan fs.FsPathS, act func(a fs.FsPathS)) {
defer close(done)
for i := range inp {
act(i) // Apply action
}
done <- struct{}{}
}
// DoneFsPathSFunc returns a channel to receive one signal before close after act has been applied to all inp.
func DoneFsPathSFunc(inp <-chan fs.FsPathS, act func(a fs.FsPathS)) (out <-chan struct{}) {
cha := make(chan struct{})
if act == nil {
act = func(a fs.FsPathS) { return }
}
go doitFsPathSFunc(cha, inp, act)
return cha
}
func pipeFsPathSBuffer(out chan<- fs.FsPathS, inp <-chan fs.FsPathS) {
defer close(out)
for i := range inp {
out <- i
}
}
// PipeFsPathSBuffer returns a buffered channel with capacity cap to receive all inp before close.
func PipeFsPathSBuffer(inp <-chan fs.FsPathS, cap int) (out <-chan fs.FsPathS) {
cha := make(chan fs.FsPathS, cap)
go pipeFsPathSBuffer(cha, inp)
return cha
}
func pipeFsPathSFunc(out chan<- fs.FsPathS, inp <-chan fs.FsPathS, act func(a fs.FsPathS) fs.FsPathS) {
defer close(out)
for i := range inp {
out <- act(i)
}
}
// PipeFsPathSFunc returns a channel to receive every result of act applied to inp before close.
// Note: it 'could' be PipeFsPathSMap for functional people,
// but 'map' has a very different meaning in go lang.
func PipeFsPathSFunc(inp <-chan fs.FsPathS, act func(a fs.FsPathS) fs.FsPathS) (out <-chan fs.FsPathS) {
cha := make(chan fs.FsPathS)
if act == nil {
act = func(a fs.FsPathS) fs.FsPathS { return a }
}
go pipeFsPathSFunc(cha, inp, act)
return cha
}
func pipeFsPathSFork(out1, out2 chan<- fs.FsPathS, inp <-chan fs.FsPathS) {
defer close(out1)
defer close(out2)
for i := range inp {
out1 <- i
out2 <- i
}
}
// PipeFsPathSFork returns two channels to receive every result of inp before close.
// Note: Yes, it is a VERY simple fanout - but sometimes all You need.
func PipeFsPathSFork(inp <-chan fs.FsPathS) (out1, out2 <-chan fs.FsPathS) {
cha1 := make(chan fs.FsPathS)
cha2 := make(chan fs.FsPathS)
go pipeFsPathSFork(cha1, cha2, inp)
return cha1, cha2
}
// FsPathSTube is the signature for a pipe function.
type FsPathSTube func(inp <-chan fs.FsPathS, out <-chan fs.FsPathS)
// FsPathSDaisy returns a channel to receive all inp after having passed thru tube.
func FsPathSDaisy(inp <-chan fs.FsPathS, tube FsPathSTube) (out <-chan fs.FsPathS) {
cha := make(chan fs.FsPathS)
go tube(inp, cha)
return cha
}
// FsPathSDaisyChain returns a channel to receive all inp after having passed thru all tubes.
func FsPathSDaisyChain(inp <-chan fs.FsPathS, tubes ...FsPathSTube) (out <-chan fs.FsPathS) {
cha := inp
for i := range tubes {
cha = FsPathSDaisy(cha, tubes[i])
}
return cha
}
/*
func sendOneInto(snd chan<- int) {
defer close(snd)
snd <- 1 // send a 1
}
func sendTwoInto(snd chan<- int) {
defer close(snd)
snd <- 1 // send a 1
snd <- 2 // send a 2
}
var fun = func(left chan<- int, right <-chan int) { left <- 1 + <-right }
func main() {
leftmost := make(chan int)
right := daisyChain(leftmost, fun, 10000) // the chain - right to left!
go sendTwoInto(right)
fmt.Println(<-leftmost)
}
*/