Files
obitools4/pkg/obiiter/pipe.go

45 lines
811 B
Go
Raw Normal View History

package obiiter
2023-01-22 22:04:17 +01:00
type Pipeable func(input IBioSequence) IBioSequence
2023-01-22 22:04:17 +01:00
func Pipeline(start Pipeable, parts ...Pipeable) Pipeable {
p := func(input IBioSequence) IBioSequence {
data := start(input)
2023-01-22 22:04:17 +01:00
for _, part := range parts {
data = part(data)
}
return data
}
return p
}
2023-01-22 22:04:17 +01:00
func (input IBioSequence) Pipe(start Pipeable, parts ...Pipeable) IBioSequence {
p := Pipeline(start, parts...)
return p(input)
}
2023-01-22 22:04:17 +01:00
type Teeable func(input IBioSequence) (IBioSequence, IBioSequence)
2023-01-22 22:04:17 +01:00
func (input IBioSequence) CopyTee() (IBioSequence, IBioSequence) {
first := MakeIBioSequence()
second := MakeIBioSequence()
first.Add(1)
go func() {
first.WaitAndClose()
second.Close()
}()
go func() {
for input.Next() {
2023-01-22 22:04:17 +01:00
b := input.Get()
first.Push(b)
second.Push(b)
}
}()
2023-01-22 22:04:17 +01:00
return first, second
}