aboutsummaryrefslogtreecommitdiffstats
path: root/util/util.go
blob: 5812ee1dd2395c53a66ffe82d477cbca1c35bebb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package util

import (
	"fmt"
	"os"

	"github.com/sam-anthony/volute/mass"
	"github.com/sam-anthony/volute/pressure"
	"github.com/sam-anthony/volute/temperature"
)

func Check(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func Insert[T int32 | float32 | temperature.Temperature | pressure.Pressure | mass.FlowRate](slice []T, elem T, i int) []T {
	return append(
		slice[:i],
		append(
			[]T{elem},
			slice[i:]...,
		)...,
	)
}

func Remove[T int32 | float32 | temperature.Temperature | pressure.Pressure | mass.FlowRate](slice []T, i int) []T {
	return append(slice[:i], slice[i+1:]...)
}