Giter Club home page Giter Club logo

sift's People

Contributors

brinkokevin avatar cxmeel avatar reselim avatar rusty483 avatar sasial-dev avatar zenthial avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sift's Issues

[Feature request]: Data partition

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

Add moonwave checks to PR

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.

Add Set difference functions

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 Dictionary difference functions

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.

Wrong array typing

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

Add array shorthand for deduplication

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.