Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions scripts/GMLodash/GMLodash.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Project:
// https://github.com/DatZach/GMLodash

// Documentation:
// https://github.com/DatZach/GMLodash/wiki/Collections
// https://github.com/DatZach/GMLodash/wiki/Language
// https://github.com/DatZach/GMLodash/wiki/Utility

#macro _ gmLodashInstance()

function GMLodash() constructor {
Expand Down Expand Up @@ -242,7 +250,34 @@ function GMLodash() constructor {

return false;
};


// For simple array-checking, this is more performant than the `includes` function.
static flatArrayIncludes = function flatArrayIncludes(array, value) {
for(var i = 0; i < array_length(array); i++) {
if(array[i] == value) {
return true;
}
}
return false;
};

// Returns the index of an item within a collection.
static indexOf = function indexOf(collection, iteratee) {
var adapter = get_adapter_for(collection);
var keys = adapter.keys(collection);
iteratee = get_iteratee(iteratee);

for (var i = 0, isize = adapter.size(collection); i < isize; ++i) {
var key = adapter.isMap ? keys[i] : i;
var value = adapter.get(collection, key);
if(iteratee(value, key, collection)) {
return i;
}
}

return undefined;
};

static keyBy = function keyBy(collection, iteratee) {
var cadapter = get_adapter_for(collection);
var radapter = get_map_adapter_for(collection);
Expand Down Expand Up @@ -516,6 +551,8 @@ function GMLodash() constructor {
}
else if (is_ptr(a) && is_ptr(b))
return a == b;
else if (is_bool(a) && is_bool(b))
return a == b;

// TODO More types?

Expand Down Expand Up @@ -699,7 +736,6 @@ function GMLodash() constructor {
}
}
}

ds_stack_destroy(stack);
return result;
};
Expand Down Expand Up @@ -952,4 +988,4 @@ function gmlodash_ds_exists(index, type) {
function gmLodashInstance() {
static instance = new GMLodash();
return instance;
}
}