Module:UtilsTable/Documentation/Snippets

local p = {}

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

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.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