Module:UtilsTable/Documentation/Snippets

local p = {}

local utilsString = require("Module:UtilsString") local utilsTable = require("Module:UtilsTable")

function p.concat1 return utilsTable.concat({1}, 2, {3, 4},, {6, [10] = 10}) end

function p.keyBy1 local characters = { {			name = "Link", game = "TWW", age = 10, },		{			name = "Link", game = "TP", age = 17 },	}	return utilsTable.keyBy(characters, function(character)		return character.game .. " " .. character.name	end) end

function p.filter1 local args = {"foo", nil, "", "bar"} return utilsTable.filter(args, utilsString.notEmpty) end

function p.find1 local args = {"foo", "bar", "baz"} return utilsTable.find(args, utilsString._startsWith("b")) end

function p.find2 local args = {"foo", "quux", "quux"} return utilsTable.find(args, utilsString._startsWith("b")) end

function p.findIndex1 local args = {"foo", "bar", "baz"} return utilsTable.findIndex(args, utilsString._startsWith("b")) end

function p.findIndex2 local args = {"foo", "quux", "quux"} return utilsTable.findIndex(args, utilsString._startsWith("b")) end

function p.findLast1 local args = {"foo", "bar", "baz"} return utilsTable.findLast(args, utilsString._startsWith("b")) end

function p.findLast2 local args = {"foo", "quux", "quux"} return utilsTable.findLast(args, utilsString._startsWith("b")) end

function p.flatMap1 local function duplicate(n) return {n, n}	end return utilsTable.flatMap({1, 2}, duplicate) end

function p._flatMap1 local duplicate = utilsTable._flatMap(function(n)		return {n, n}	end) return duplicate({1, 2}) end

function p.groupBy1 return utilsTable.groupBy({6.1, 4.2, 6.3}, math.floor) end

function p.map1 local args = {true, false} return utilsTable.map(args, tostring) end

function p.mapValues1 local templateArgs = { arg1 = " foo ", arg2 = "bar\n", }	return utilsTable.mapValues(templateArgs, mw.text.trim) end

function p.merge1 local tbl = { flib = "flob", foo = { bar = {"flib", "flob"}, baz = {"quux", "quuz"}, },	}	utilsTable.merge(tbl, {		foo = {			bar = {"noot"},			baz = "noot",			wibble = "wobble",		},	}) return tbl end

return p