go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/pkg/funcs/sum.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package funcs
     9  
    10  import (
    11  	"cmp"
    12  	"context"
    13  
    14  	"go.charczuk.com/projects/nodes/pkg/incrutil"
    15  )
    16  
    17  func Sum[T cmp.Ordered](ctx context.Context, inputValues *incrutil.Inputs[T]) (output T, _ error) {
    18  	for _, i := range inputValues.Values() {
    19  		output += i
    20  	}
    21  	return
    22  }
    23  
    24  func SumMany[T cmp.Ordered](ctx context.Context, inputValues *incrutil.Inputs[[]T]) (output T, _ error) {
    25  	inputs := inputValues.Values()
    26  	for _, values := range inputs {
    27  		for _, i := range values {
    28  			output += i
    29  		}
    30  	}
    31  	return
    32  }