go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/pkg/model/gen/median.go (about)

     1  // File generated by nodegen. DO NOT EDIT.
     2  package gen
     3  
     4  import (
     5  	"fmt"
     6  	"time"
     7  
     8  	"github.com/wcharczuk/go-incr"
     9  	"go.charczuk.com/projects/nodes/pkg/funcs"
    10  	"go.charczuk.com/projects/nodes/pkg/incrutil"
    11  	"go.charczuk.com/projects/nodes/pkg/types"
    12  )
    13  
    14  func MedianForNode(graph *incr.Graph, n *types.Node) (output incr.INode, err error) {
    15  	switch n.Metadata.InputType {
    16  	case "[]float64":
    17  		switch n.Metadata.OutputType {
    18  		case "float64":
    19  			output = incrutil.MapN(graph, funcs.MedianMany[float64])
    20  			return
    21  		default:
    22  			err = fmt.Errorf("invalid median output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType)
    23  			return
    24  		}
    25  
    26  	case "[]int64":
    27  		switch n.Metadata.OutputType {
    28  		case "int64":
    29  			output = incrutil.MapN(graph, funcs.MedianMany[int64])
    30  			return
    31  		default:
    32  			err = fmt.Errorf("invalid median output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType)
    33  			return
    34  		}
    35  
    36  	case "[]duration":
    37  		switch n.Metadata.OutputType {
    38  		case "duration":
    39  			output = incrutil.MapN(graph, funcs.MedianMany[time.Duration])
    40  			return
    41  		default:
    42  			err = fmt.Errorf("invalid median output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType)
    43  			return
    44  		}
    45  
    46  	default:
    47  		err = fmt.Errorf("invalid median input type %v", n.Metadata.InputType)
    48  		return
    49  	}
    50  }