github.com/searKing/golang/go@v1.2.74/container/stream/op/terminal/pipeline.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 terminal
     6  
     7  import (
     8  	"context"
     9  
    10  	"github.com/searKing/golang/go/util/object"
    11  	"github.com/searKing/golang/go/util/spliterator"
    12  )
    13  
    14  /**
    15   * Applies the pipeline stages described by this {@code PipelineHelper} to
    16   * the provided {@code Spliterator} and send the results to the provided
    17   * {@code Sink}.
    18   *
    19   * @implSpec
    20   * The implementation behaves as if:
    21   * <pre>{@code
    22   *     copyInto(wrapSink(sink), spliterator);
    23   * }</pre>
    24   *
    25   * @param sink the {@code Sink} to receive the results
    26   * @param spliterator the spliterator describing the source input to process
    27   */
    28  func WrapAndCopyInto(ctx context.Context, sink Sink, spliterator spliterator.Spliterator) Sink {
    29  	CopyInto(ctx, object.RequireNonNull(sink).(Sink), spliterator)
    30  	return sink
    31  }
    32  
    33  func CopyInto(ctx context.Context, wrappedSink Sink, spliterator spliterator.Spliterator) {
    34  	object.RequireNonNil(wrappedSink)
    35  	wrappedSink.Begin(spliterator.GetExactSizeIfKnown())
    36  	spliterator.ForEachRemaining(ctx, wrappedSink)
    37  	wrappedSink.End()
    38  }