cxmeel / sift Goto Github PK
View Code? Open in Web Editor NEWImmutable data library for Luau.
Home Page: https://csqrl.github.io/sift/
License: MIT License
Immutable data library for Luau.
Home Page: https://csqrl.github.io/sift/
License: MIT License
I am willing to implement this feature, just want to open an issue for discussion and approval first ๐
Proposal:
local bobsPets = {
cat = true,
dog = true,
bird = true,
}
local timsPets = {
bird = true,
snake = true,
spider = true,
}
-- Asymmetric Difference
Sift.Set.difference(bobsPets, timsPets) -- { cat, dog }
Sift.Set.difference(timsPets, bobsPets) -- { snake, spider }
-- Symmetric Difference
Sift.Set.symmetricDifference(bobsPets, timsPets) -- { cat, dog, snake, spider }
Sift.Set.symmetricDifference(timsPets, bobsPets) -- { cat, dog, snake, spider }
Add an array function to deduplicate values within an array in a shorter and more readable form.
This can currently be achieved like so:
local deduplicated = Sift.Set.toArray(Sift.Set.fromArray(array))
But, it would be cleaner and more readable if there were a built-in function that did this instead.
See: freddylist/llama#3
It looks like handling of holes is intentional by the type signature, but because it uses ipairs
, holes aren't supported. May need to switch to using select
for tuples, as the #
operator doesn't work for lists with holes, IIRC.
Hi I'm using rbxts, and Array.join/aliases returns a wrong type, look
const arr1 = ["a", "b", "c"];
const arr2 = ["d", "e", "f"];
const result = Sift.Array.join(arr1, arr2);
the type return should be string[]
but I get string[][]
and thats wrong.
I think this could fix it:
function concat<T>(...arrays: T[]): T; // remove [] in return type
I find myself doing this often:
local numbers = { 1, 4, 2, 3, 1, 1, 3 }
local ones = Sift.Array.filter(numbers, function(number)
return number == 1
end)
local noOnes = Sift.Array.filter(numbers, function(number)
return number ~= 1
end)
It would be nice to have a partition/split method to separate data:
local numbers = { 1, 4, 2, 3, 1, 1, 3 }
local ones, noOnes = Sift.Array.partition(numbers, function(number)
return number == 1
end)
print(ones) -- { 1, 1, 1 }
print(noOnes) -- { 4, 2, 3, 3 }
It could also apply for Set
and Dictionary
I have written some computationally & memory efficient implementations for these already which produce the exact behaviours I demonstrated in the example code already, so I'd be happy to write up a PR if that's desirable.
Sift.Dictionary.difference(dictA, dictB)
- Would produce a new dictionary containing values which are different in B than in A. This only considers top-level equality. This is also the inverse of Sift.Dictionary.merge
.Sift.Dictionary.differenceDeep(dictA, dictB)
- Would produce a new dictionary containing values which are different in B than in A. Sub-dictionaries would only contain differences as well. This is also the inverse of Sift.Dictionary.mergeDeep
.local kinds = {
Apple = true;
Pear = true;
Others = {
Carrot = true;
Potato = true;
};
}
local dictA = {
Apple = 9;
Pear = 7;
Others = {
Carrot = 11;
Potato = 15;
};
Kinds = kinds;
}
local dictB = {
Apple = 10;
Pear = 7;
Others = {
Carrot = 12;
};
Kinds = kinds;
}
-- Shallow difference, only top level equality
Sift.Dictionary.difference(dictA, dictB) -- { Apple = 10, Others = { Carrot = 12 } }
-- Deep difference, sub-dictionaries will also be deeply diffed
Sift.Dictionary.differenceDeep(dictA, dictB) -- { Apple = 10, Others = { Carrot = 12, Potato = Sift.None }, Kinds = { } }
-- Another valid implementation might omit Kinds since it has no changes. This behaviour might not be expected in some cases though, so it might be worth considering which of the two implementations makes the most sense.
-- It might also be good to consider how table equality should be treated. In the example I assume just == behaviour, but `Dictionary.equals` or `Dictionary.equalsDeep` could also be used for diffing sub-dicts.
Sometimes it's really easy to forget to check moonwave will actually compile after making changes. Usually it'll fail due to "mixed indentation," even if you haven't touched the comments.
It'd be handy to add a check to PRs that will block merging until moonwave succeeds.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.