package utils

func Map[T, V any](ts []T, fn func(T) V) []V {
	result := make([]V, len(ts))
	for i, t := range ts {
		result[i] = fn(t)
	}
	return result
}

func MapMap[J, K comparable, T, V any](ts map[J]T, fn func(J, T) (K, V)) map[K]V {
	result := make(map[K]V, len(ts))
	for i, t := range ts {
		rK, rV := fn(i, t)
		result[rK] = rV
	}
	return result
}

func Filter[T any](ts []T, fn func(T) bool) []T {
	result := make([]T, 0)
	for _, t := range ts {
		if fn(t) {
			result = append(result, t)
		}
	}
	return result
}
