go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/pkg/model/edges_from_inode.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 model 9 10 import ( 11 "github.com/wcharczuk/go-incr" 12 "go.charczuk.com/projects/nodes/pkg/incrutil" 13 "go.charczuk.com/projects/nodes/pkg/types" 14 ) 15 16 // EdgesFromINode returns the edges to a given INode. 17 func EdgesFromINode(n incr.INode) []types.Edge { 18 if typed, ok := n.(incrutil.IInputs); ok { 19 var output []types.Edge 20 inputs := typed.Inputs() 21 for childInputName, parent := range inputs { 22 output = append(output, types.Edge{ 23 ParentID: parent.Node().ID(), 24 ChildID: n.Node().ID(), 25 ChildInputName: childInputName, 26 }) 27 } 28 return output 29 } 30 return nil 31 }