github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/dataflow/pointer/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "math" 6 ) 7 8 type Node interface { 9 Process() 10 } 11 12 type Parameter[T any] struct { 13 Name string 14 Value T 15 DefaultValue T 16 } 17 18 func (p *Parameter[T]) Process() {} 19 20 type SinCos struct { 21 In *float64 22 23 Sin float64 24 Cos float64 25 } 26 27 func (sincos *SinCos) Process() { 28 sincos.Sin, sincos.Cos = math.Sincos(*sincos.In) 29 } 30 31 type Probe[T any] struct { 32 In *T 33 } 34 35 func (probe Probe[T]) Process() { 36 fmt.Println(*probe.In) 37 } 38 39 func main() { 40 hello := &Parameter[float64]{ 41 Name: "Hello", 42 Value: 10, 43 DefaultValue: 5, 44 } 45 46 sincos := &SinCos{In: &hello.Value} 47 48 probeSin := Probe[float64]{In: &sincos.Sin} 49 probeCos := Probe[float64]{In: &sincos.Cos} 50 51 nodes := []Node{ 52 hello, 53 sincos, 54 probeSin, 55 probeCos, 56 } 57 58 for _, n := range nodes { 59 n.Process() 60 } 61 }