go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/pkg/model/gen/sort.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 "go.charczuk.com/sdk/iter" 13 ) 14 15 func SortForNode(graph *incr.Graph, n *types.Node) (output incr.INode, err error) { 16 switch n.Metadata.InputType { 17 case "int64": 18 switch n.Metadata.OutputType { 19 case "int64": 20 output = incrutil.MapN[int64](graph, funcs.Sort[int64]) 21 return 22 default: 23 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 24 return 25 } 26 27 case "float64": 28 switch n.Metadata.OutputType { 29 case "float64": 30 output = incrutil.MapN[float64](graph, funcs.Sort[float64]) 31 return 32 default: 33 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 34 return 35 } 36 37 case "string": 38 switch n.Metadata.OutputType { 39 case "string": 40 output = incrutil.MapN[string](graph, funcs.Sort[string]) 41 return 42 default: 43 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 44 return 45 } 46 47 case "timestamp": 48 switch n.Metadata.OutputType { 49 case "timestamp": 50 output = incrutil.MapN[time.Time](graph, funcs.SortComparer[time.Time](iter.SorterComparerFunc[time.Time](funcs.TimestampAsc))) 51 return 52 default: 53 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 54 return 55 } 56 57 case "duration": 58 switch n.Metadata.OutputType { 59 case "duration": 60 output = incrutil.MapN[time.Duration](graph, funcs.Sort[time.Duration]) 61 return 62 default: 63 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 64 return 65 } 66 67 case "[]int64": 68 switch n.Metadata.OutputType { 69 case "[]int64": 70 output = incrutil.MapN[[]int64](graph, funcs.SortMany[int64]) 71 return 72 default: 73 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 74 return 75 } 76 77 case "[]float64": 78 switch n.Metadata.OutputType { 79 case "[]float64": 80 output = incrutil.MapN[[]float64](graph, funcs.SortMany[float64]) 81 return 82 default: 83 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 84 return 85 } 86 87 case "[]string": 88 switch n.Metadata.OutputType { 89 case "[]string": 90 output = incrutil.MapN[[]string](graph, funcs.SortMany[string]) 91 return 92 default: 93 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 94 return 95 } 96 97 case "[]timestamp": 98 switch n.Metadata.OutputType { 99 case "[]timestamp": 100 output = incrutil.MapN[[]time.Time](graph, funcs.SortComparerMany[time.Time](iter.SorterComparerFunc[time.Time](funcs.TimestampAsc))) 101 return 102 default: 103 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 104 return 105 } 106 107 case "[]duration": 108 switch n.Metadata.OutputType { 109 case "[]duration": 110 output = incrutil.MapN[[]time.Duration](graph, funcs.SortMany[time.Duration]) 111 return 112 default: 113 err = fmt.Errorf("invalid sort output type %v for input type %v", n.Metadata.OutputType, n.Metadata.InputType) 114 return 115 } 116 117 default: 118 err = fmt.Errorf("invalid sort input type %v", n.Metadata.InputType) 119 return 120 } 121 }