Diff

util/array.lua @ 10895:5777968301e8

util.array: pluck: Support default value to avoid holes
author Matthew Wild <mwild1@gmail.com>
date Thu, 04 Jun 2020 10:39:12 +0100
parent 10592:9918b4b0cd58
child 11787:3ae6fa901a8b
line wrap: on
line diff
--- a/util/array.lua	Wed Jun 03 22:58:29 2020 +0100
+++ b/util/array.lua	Thu Jun 04 10:39:12 2020 +0100
@@ -134,9 +134,13 @@
 	end);
 end
 
-function array_base.pluck(outa, ina, key)
+function array_base.pluck(outa, ina, key, default)
 	for i = 1, #ina do
-		outa[i] = ina[i][key];
+		local v = ina[i][key];
+		if v == nil then
+			v = default;
+		end
+		outa[i] = v;
 	end
 	return outa;
 end