RosettaCodeData/Task/Sort-an-array-of-composite-structures/Pluto/sort-an-array-of-composite-structures.pluto
2026-04-30 12:34:36 -04:00

20 lines
533 B
Text

class pair
function __construct(public name, public value) end
function __lt(other) return self.name < other.name end
function __tostring() return $"\{{self.name}, {self.value}}" end
end
local pairs = {
new pair("grass", "green"),
new pair("snow", "white"),
new pair("sky", "blue"),
new pair("cherry", "red")
}
print("Before sorting:")
print(" " .. pairs:mapped(|p| -> tostring(p)):concat("\n "))
pairs:sort()
print("\nAfter sorting:")
print(" " .. pairs:mapped(|p| -> tostring(p)):concat("\n "))