Skip to main content
distinct(list) returns a new list with duplicate values removed. The first occurrence of each value is kept.

Signature

distinct(list list) list

Example

Combine package lists from multiple variables and ensure no package appears twice before passing the list to a build command:
variable "base_packages" {
  type    = list(string)
  default = ["./cmd/api", "./cmd/worker"]
}

variable "extra_packages" {
  type    = list(string)
  default = ["./cmd/worker", "./cmd/scheduler"]
}

computed "packages" {
  description = "Deduplicated list of packages to build"
  expression  = distinct(concat(var.base_packages, var.extra_packages))
}

task "build" {
  description = "Build all unique packages"
  commands    = ["go build ${join(" ", computed.packages)}"]
}
["./cmd/api", "./cmd/worker", "./cmd/scheduler"] is the result, with the duplicate ./cmd/worker removed.

Notes

  • Order is preserved based on first occurrence.
  • distinct works on lists of any comparable element type.