Skip to content

Commit 7274dac

Browse files
authored
Merge pull request #17 from gm-core/5-0-0-update
5.0.0 updated docs
2 parents 3279273 + 210942e commit 7274dac

File tree

11 files changed

+512
-224
lines changed

11 files changed

+512
-224
lines changed

README.md

Lines changed: 293 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# gdash - GML Utility Library
22

3-
Version 4.0.0
3+
Version 5.0.0
44

55
## Introduction
66

@@ -14,17 +14,26 @@ gdash is a functional utility library for GML, inspired by [lodash](https://loda
1414
- [API](#api)
1515
* [`_and(valueA, valueB)`](#_andvaluea-valueb)
1616
* [`_array_of(values...)`](#_array_ofvalues)
17+
* [`_backward(array)`](#_backwardarray)
18+
* [`_chunk(array, size)`](#_chunkarray-size)
1719
* [`_clone_array(array)`](#_clone_arrayarray)
1820
* [`_collect(object)`](#_collectobject)
1921
* [`_concat(arrayA, arrayB)`](#_concatarraya-arrayb)
2022
* [`_contains(collection, target [, fromIndex, dsType])`](#_containscollection-target--fromindex-dstype)
2123
* [`_destroy(object)`](#_destroyobject)
24+
* [`_difference_by(array, arrays..., iteratee)`](#_difference_byarray-arrays-iteratee)
25+
* [`_difference(array, arrays...)`](#_differencearray-arrays)
26+
* [`_drop_right(array, n)`](#_drop_rightarray-n)
27+
* [`_drop(array, n)`](#_droparray-n)
2228
* [`_error(message [, fatal])`](#_errormessage--fatal)
29+
* [`_fill(array, value [, start, end])`](#_fillarray-value--start-end)
2330
* [`_filter(collection, script)`](#_filtercollection-script)
2431
* [`_find(array, findScript)`](#_findarray-findscript)
2532
* [`_free(id [, ds_type])`](#_freeid--ds_type)
2633
* [`_get(map, locationString)`](#_getmap-locationstring)
2734
* [`_index_of(collection, value)`](#_index_ofcollection-value)
35+
* [`_intersection_by(arrays..., iteratee)`](#_intersection_byarrays-iteratee)
36+
* [`_intersection(arrays...)`](#_intersectionarrays)
2837
* [`_is_equal(valueA, valueB [, dsType])`](#_is_equalvaluea-valueb--dstype)
2938
* [`_join(array, joinChar)`](#_joinarray-joinchar)
3039
* [`_keys(map)`](#_keysmap)
@@ -48,7 +57,12 @@ gdash is a functional utility library for GML, inspired by [lodash](https://loda
4857
* [`_to_array(list)`](#_to_arraylist)
4958
* [`_to_list(array)`](#_to_listarray)
5059
* [`_type_of(value)`](#_type_ofvalue)
60+
* [`_union_by(arrays..., iteratee)`](#_union_byarrays-iteratee)
61+
* [`_union(arrays...)`](#_unionarrays)
5162
* [`_uniq(array)`](#_uniqarray)
63+
* [`_unzip(array)`](#_unziparray)
64+
* [`_without(array, values...)`](#_withoutarray-values)
65+
* [`_zip(arrays...)`](#_ziparrays)
5266

5367
<!-- tocstop -->
5468

@@ -95,6 +109,43 @@ _arrayOf('hello', 'world', 'i', 'am', 'an', 'array');
95109
// => ['hello', 'world', 'i', 'am', 'an', 'array'];
96110
```
97111

112+
### `_backward(array)`
113+
114+
Creates a new array containing the elements of array in reverse order.
115+
116+
> *Note*: To modify an array in-place, use `_reverse`
117+
118+
```gml
119+
@param {Array} array The array to reverse
120+
121+
@returns {Array} The reversed array
122+
123+
@example
124+
var myArray = [1, 2, 3];
125+
var reverseArray = _backward(myArray);
126+
// => [3, 2, 1]
127+
```
128+
129+
### `_chunk(array, size)`
130+
131+
Creates a two-dimensional array of elements split into groups of given length.
132+
133+
```gml
134+
@param {Array} array The array to split
135+
@param {Integer} size The size of each chunk
136+
137+
@returns {Array} The two-dimensional array of chunks
138+
139+
@example
140+
var arr = [0, 1, 2, 3];
141+
_chunk(arr, 2);
142+
// => [[0, 1], [2, 3]];
143+
144+
var arr = [0, 1, 2, 3];
145+
_chunk(arr, 3);
146+
// => [[0, 1, 2], [3]];
147+
```
148+
98149
### `_clone_array(array)`
99150

100151
Clones a given input array, returning a deep copy.
@@ -179,6 +230,78 @@ _destroy(obj_enemy);
179230
_map(_filter(_collect(obj_enemy)), hasNoHealth), _destroy);
180231
```
181232
233+
### `_difference_by(array, arrays..., iteratee)`
234+
235+
Like `_difference()`, except that it accepts iteratee which is invoked for each element of each array to generate the criterion by which they are compared.
236+
237+
```gml
238+
@param {Array} array The array to inspect
239+
@param {Array} arrays... The arrays whose values are to be excluded
240+
@param {Script} iteratee The script invoked on each element to generate comparison criteria
241+
242+
@returns {Array} The difference between the first and the remaining arrays
243+
244+
@example
245+
// _floor(x)
246+
return floor(x);
247+
248+
var arr0 = [0.5, 1, 2];
249+
var arr1 = [0];
250+
var arr2 = [0.1, 2.9];
251+
_difference_by(arr0, arr1, arr2, _floor);
252+
// => [1];
253+
```
254+
255+
### `_difference(array, arrays...)`
256+
257+
Creates an array of values from the first array not found in the other arrays.
258+
259+
```gml
260+
@param {Array} array The array to inspect
261+
@param {Array} arrays... The arrays whose values are to be excluded
262+
263+
@returns {Array} The difference between the first and the remaining arrays
264+
265+
@example
266+
var arr0 = [0, 1, 2];
267+
var arr1 = [0];
268+
var arr2 = [0, 2];
269+
_difference(arr0, arr1, arr2);
270+
// => [1];
271+
```
272+
273+
### `_drop_right(array, n)`
274+
275+
Creates a slice of array with n elements dropped from the end.
276+
277+
```gml
278+
@param {Array} array The array to inspect
279+
@param {Integer} n The number of elements to drop
280+
281+
@returns {Array} The slice of array
282+
283+
@example
284+
var arr = [0, 1, 2, 3];
285+
_drop_right(arr, 2);
286+
// => [0, 1];
287+
```
288+
289+
### `_drop(array, n)`
290+
291+
Creates a slice of array with n elements dropped from the beginning.
292+
293+
```gml
294+
@param {Array} array The array to inspect
295+
@param {Integer} n The number of elements to drop
296+
297+
@returns {Array} The slice of array
298+
299+
@example
300+
var arr = [0, 1, 2, 3];
301+
_drop(arr, 2);
302+
// => [2, 3];
303+
```
304+
182305
### `_error(message [, fatal])`
183306
184307
When running with the debugger, displays an error window. Otherwise, logs an error using `_log`.
@@ -195,6 +318,30 @@ _error("This is an error that will let the game continue", false);
195318
_error("This is an error that will kill the game", true);
196319
```
197320

321+
### `_fill(array, value [, start, end])`
322+
323+
Fills elements of array with value from start up to, but not including, end.
324+
325+
> *Note*: This method mutates array.
326+
327+
```gml
328+
@param {Array} array The array to fill
329+
@param {*} value The value with which to fill elements of array
330+
@param {Integer} optionalStart The start index
331+
@param {Integer} optionalEnd The end index
332+
333+
@returns {Array} The filled array
334+
335+
@example
336+
var arr = [0, 1, 2, 3];
337+
_fill(arr, 4, 1, 3);
338+
// => [0, 4, 4, 3];
339+
340+
var arr = [0, 1, 2, 3];
341+
_fill(arr, 0);
342+
// => [0, 0, 0, 0];
343+
```
344+
198345
### `_filter(collection, script)`
199346
200347
Returns a collection where values of the input collection are truthy when run through the provided function.
@@ -271,6 +418,47 @@ Returns the index of the given item in the given array, or -1
271418
272419
```
273420

421+
### `_intersection_by(arrays..., iteratee)`
422+
423+
Like `_intersection()`, except that it accepts iteratee which is invoked for each element of each array to generate the criterion by which uniqueness is computed.
424+
425+
```gml
426+
@param {Array} arrays... The arrays to be intersected
427+
@param {Script} iteratee The script invoked on each element to generate uniqueness criteria
428+
429+
@returns {Array} The intersection of the given arrays
430+
431+
@example
432+
// _floor(x)
433+
return floor(x);
434+
435+
var arr0 = [0, 1.9];
436+
var arr1 = [0.6, 3];
437+
_intersection_by(arr0, arr1, _floor);
438+
// => [0];
439+
```
440+
441+
### `_intersection(arrays...)`
442+
443+
Creates an array of unique values common to all given arrays in the order in which they originally appeared.
444+
445+
```gml
446+
@param {Array} arrays... The arrays to be intersected
447+
448+
@returns {Array} The intersection of the given arrays
449+
450+
@example
451+
var arr0 = [0, 1];
452+
var arr1 = [0];
453+
_intersection(arr0, arr1);
454+
// => [0];
455+
456+
var arr0 = ['Sword', 'Potion'];
457+
var arr1 = ['Shield', 'Potion', 'Sword'];
458+
_intersection(arr0, arr1);
459+
// => ['Sword', 'Potion'];
460+
```
461+
274462
### `_is_equal(valueA, valueB [, dsType])`
275463

276464
Checks if two values are equal, being safe about type and checking first-level children of ds_lists and ds_maps. Returns false on type inequality rather than throwing an error.
@@ -525,17 +713,19 @@ _reduce(arr, concat);
525713

526714
### `_reverse(array)`
527715

528-
Reverses a given input array
716+
Reverses the order of elements in array.
717+
718+
> *Note*: This method mutates the input array. To create a new array instead, use `_backward`
529719
530720
```gml
531-
@param {Array} array The array to reverse
721+
@param {Array} array The array to modify
532722

533723
@returns {Array} The reversed array
534724

535725
@example
536-
var myArray = [1, 2, 3];
537-
var reverseArray = _reverse(myArray);
538-
// => [3, 2, 1]
726+
var arr = [0, 1, 2];
727+
_reverse(arr);
728+
// => [2, 1, 0];
539729
```
540730
541731
### `_run(scriptOrPartial, arguments...)`
@@ -706,6 +896,47 @@ _type_of(sprite_get_texture(spr_player, 1));
706896
// => "ptr";
707897
```
708898
899+
### `_union_by(arrays..., iteratee)`
900+
901+
Like `_union()`, except that it accepts iteratee which is invoked for each element of each array to generate the criterion by which uniqueness is computed.
902+
903+
```gml
904+
@param {Array} arrays... The arrays to be unioned
905+
@param {Script} iteratee The script invoked on each element to generate uniqueness criteria
906+
907+
@returns {Array} The union of the given arrays
908+
909+
@example
910+
// _floor(x)
911+
return floor(x);
912+
913+
var arr0 = [0.5, 1.2];
914+
var arr1 = [0, 1.9];
915+
_union_by(arr0, arr1, _floor);
916+
// => [0.5, 1.2];
917+
```
918+
919+
### `_union(arrays...)`
920+
921+
Creates an array of unique values, in the order in which they originally appeared, from all given arrays.
922+
923+
```gml
924+
@param {Array} arrays... The arrays to be unioned
925+
926+
@returns {Array} The union of the given arrays
927+
928+
@example
929+
var arr0 = _array_of(0, 1);
930+
var arr1 = _array_of(0);
931+
_union(arr0, arr1);
932+
// => [0, 1];
933+
934+
var arr0 = _array_of('Sword', 'Potion');
935+
var arr1 = _array_of('Shield', 'Sword');
936+
_union(arr0, arr1);
937+
// => ['Sword', 'Potion', 'Shield'];
938+
```
939+
709940
### `_uniq(array)`
710941
711942
Returns an array with all duplicate values removed
@@ -719,3 +950,59 @@ Returns an array with all duplicate values removed
719950
_uniq([1, 1, 2, 3]);
720951
// => [1, 2, 3]
721952
```
953+
954+
### `_unzip(array)`
955+
956+
From a zipped two-dimensional array, creates a collection of grouped elements by regrouping the elements to their pre-zipped configuration
957+
958+
```gml
959+
@param {Array} array The zipped two-dimensional array
960+
961+
@returns {Array} The two-dimensional array of regrouped elements
962+
963+
@example
964+
var arr0 = [0, 1, 2];
965+
var arr1 = [3, 4, 5];
966+
var arr2 =_zip(arr0, arr1);
967+
_unzip(arr2);
968+
// => [[0, 1, 2], [3, 4, 5]];
969+
970+
```
971+
972+
### `_without(array, values...)`
973+
974+
Creates an array excluding all given values from amongst the elements of the given array
975+
976+
```gml
977+
@param {Array} array The array to inspect
978+
@param {*} values... The values to exclude
979+
980+
@returns {Array} The array of filtered elements
981+
982+
@example
983+
var arr = [0, 1, 0, 2];
984+
_without(arr, 0, 1);
985+
// => [2];
986+
```
987+
988+
### `_zip(arrays...)`
989+
990+
Creates a two-dimensional array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.
991+
992+
```gml
993+
@param {Array} arrays... The remaining arrays
994+
995+
@returns {Array} The array of elements grouped in arrays
996+
997+
@example
998+
var arr0 = [0, 1];
999+
var arr1 = ['Sword', 'Shield'];
1000+
var arr2 = [true, false];
1001+
_zip(arr0, arr1, arr2);
1002+
// => [[0, 'Sword', true], [1, 'Shield', false]];
1003+
1004+
var arr0 = [0, 1, 2];
1005+
var arr1 = [3, 4, 5];
1006+
_zip(arr0, arr1);
1007+
// => [[0, 3], [1, 4], [2, 5]];
1008+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gdash",
3-
"version": "4.0.0",
3+
"version": "5.0.0",
44
"description": "This package.json is to install development utilities for gdash. You can ignore this if you are using gdash in your game.",
55
"scripts": {
66
"readme-toc": "markdown-toc -i README.md",

0 commit comments

Comments
 (0)