Skip to content

Instantly share code, notes, and snippets.

@thewisenerd
Created April 24, 2024 17:30
Show Gist options
  • Save thewisenerd/728dadad82e8e932d8da88f4f96a28be to your computer and use it in GitHub Desktop.
Save thewisenerd/728dadad82e8e932d8da88f4f96a28be to your computer and use it in GitHub Desktop.
{
local id = function(x) x,
local keySet = function(a, keyF=id)
{ [k]: true for k in std.map(keyF, a) if k != null },
arrUnion(a, b, keyF=id)::
local aSet = keySet(a, keyF);
local bSet = keySet(b, keyF);
a + std.foldl(function(acc, e) acc + (
local key = keyF(e);
if (key != null && std.objectHas(aSet, key)) then [] else [e]
), b, []),
arrInter(a, b, keyF=id)::
local aSet = keySet(a, keyF);
local bSet = keySet(b, keyF);
std.foldl(function(acc, e) acc + (
local key = keyF(e);
if (key != null && std.objectHas(bSet, key)) then [e] else []
), a, []),
arrDiff(a, b, keyF=id)::
local bSet = keySet(b, keyF);
std.foldl(function(acc, e) acc + (
local key = keyF(e);
if (key != null && std.objectHas(bSet, key)) then [] else [e]
), a, []),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment