github.com/searKing/golang/go@v1.2.74/container/stream/op/terminal/op.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/error/exception"
    11  	"github.com/searKing/golang/go/util/class"
    12  	"github.com/searKing/golang/go/util/optional"
    13  	"github.com/searKing/golang/go/util/spliterator"
    14  )
    15  
    16  /**
    17   * An operation in a stream pipeline that takes a stream as input and produces
    18   * a result or side-effect.  A {@code Op} has an input type and stream
    19   * shape, and a result type.  A {@code Op} also has a set of
    20   * <em>operation flags</em> that describes how the operation processes elements
    21   * of the stream (such as short-circuiting or respecting encounter order; see
    22   * {@link StreamOpFlag}).
    23   *
    24   * <p>A {@code Op} must provide a sequential and parallel implementation
    25   * of the operation relative to a given stream source and set of intermediate
    26   * operations.
    27   *
    28   * @param <E_IN> the type of input elements
    29   * @param <R>    the type of the result
    30   * @since 1.8
    31   */
    32  type Operation interface {
    33  	/**
    34  	 * Gets the stream flags of the operation.  Terminal operations may set a
    35  	 * limited subset of the stream flags defined in {@link StreamOpFlag}, and
    36  	 * these flags are combined with the previously combined stream and
    37  	 * intermediate operation flags for the pipeline.
    38  	 *
    39  	 * @implSpec The default implementation returns zero.
    40  	 *
    41  	 * @return the stream flags for this operation
    42  	 * @see StreamOpFlag
    43  	 */
    44  	GetOpFlags() int
    45  
    46  	/**
    47  	 * Performs a parallel evaluation of the operation using the specified
    48  	 * {@code PipelineHelper}, which describes the upstream intermediate
    49  	 * operations.
    50  	 *
    51  	 * @implSpec The default performs a sequential evaluation of the operation
    52  	 * using the specified {@code PipelineHelper}.
    53  	 *
    54  	 * @param helper the pipeline helper
    55  	 * @param spliterator the source spliterator
    56  	 * @return the result of the evaluation
    57  	 */
    58  	EvaluateParallel(ctx context.Context, spliterator spliterator.Spliterator) optional.Optional
    59  
    60  	/**
    61  	 * Performs a sequential evaluation of the operation using the specified
    62  	 * {@code PipelineHelper}, which describes the upstream intermediate
    63  	 * operations.
    64  	 *
    65  	 * @param helper the pipeline helper
    66  	 * @param spliterator the source spliterator
    67  	 * @return the result of the evaluation
    68  	 */
    69  	EvaluateSequential(ctx context.Context, spliterator spliterator.Spliterator) optional.Optional
    70  }
    71  
    72  type TODOOperation struct {
    73  	class.Class
    74  }
    75  
    76  func (op *TODOOperation) GetOpFlags() int {
    77  	return 0
    78  }
    79  
    80  func (op *TODOOperation) EvaluateParallel(ctx context.Context, spliterator spliterator.Spliterator) optional.Optional {
    81  	c := op.GetDerivedElse(op).(Operation)
    82  	return c.EvaluateSequential(ctx, spliterator)
    83  }
    84  
    85  func (op *TODOOperation) EvaluateSequential(ctx context.Context, spliterator spliterator.Spliterator) optional.Optional {
    86  	panic(exception.NewIllegalStateException())
    87  }