| 1 | struct Node[T] { |
| 2 | mut: |
| 3 | data T |
| 4 | next &Node[T] = unsafe { nil } |
| 5 | } |
| 6 | |
| 7 | struct SinglyLinkedList[T] { |
| 8 | mut: |
| 9 | first_node &Node[T] = unsafe { nil } |
| 10 | } |
| 11 | |
| 12 | fn init_singlylinkedlist[T](nodes ...Node[T]) SinglyLinkedList[T] { |
| 13 | mut current_node := &nodes[0] |
| 14 | |
| 15 | for i in 0 .. nodes.len - 1 { |
| 16 | current_node = &nodes[i] |
| 17 | current_node.next = &nodes[i + 1] |
| 18 | } |
| 19 | |
| 20 | return SinglyLinkedList[T]{&nodes[0]} |
| 21 | } |
| 22 | |
| 23 | fn test_generic_with_variadic_generic_args() { |
| 24 | sll := init_singlylinkedlist[int](Node[int]{ data: 1 }, Node[int]{ |
| 25 | data: 2 |
| 26 | }, Node[int]{ |
| 27 | data: 798 |
| 28 | }) |
| 29 | println(sll.first_node.next) |
| 30 | assert sll.first_node.next.data == 2 |
| 31 | } |
| 32 | |