Created
April 24, 2024 17:30
-
-
Save thewisenerd/728dadad82e8e932d8da88f4f96a28be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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