Skip to content

Commit 4343e81

Browse files
committed
expanded description
1 parent c6c51b4 commit 4343e81

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

README.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# array_
22
## Conversion of JavaScript's Array methods to AutoHotkey
33

4-
Despite AutoHotKey (1.1.28 at the moment) supporting Arrays and Function Objects, there are no handy built-in methods for parsing Array data. This project ports most of JavaScript's Array object methods over to AutoHotKey.
4+
AutoHotKey is an extremely versatile prototype-based language but lacks built-in iteration helper methods (as of 1.1.28) to perform many of the common behaviors found in other languages. This project ports most of JavaScript's Array object methods over to AutoHotKey.
55

66
### Ported Methods
77
* concat
@@ -30,7 +30,7 @@ Despite AutoHotKey (1.1.28 at the moment) supporting Arrays and Function Objects
3030
### Installation
3131
There are two options for using these functions, either as global functions stored in **array_.ahk** or by extending the built-in Array object with the object stored in **array_base.ahk**. The sorting function in both files depend on the object defined in **array_quicksort.ahk**. This object must be present for sorting to work properly.
3232

33-
Some dislike extending built-in objects. For that reason **array_base.ahk**'s object does not automatically extend Array. Extending Array, or a custom collections object, is left to the implementer (See _**As Array Object Extension**_ below).
33+
Some dislike extending built-in objects. For that reason **array_base.ahk**'s object does not automatically extend Array. Extending Array, or a custom collections object, is left to the implementer (See _**As Array Object Extension**_ below). Using this method based approach grants the ability to perform method-chaining syntax.
3434

3535
### Usage
3636
_**As Global Functions**_
@@ -44,20 +44,22 @@ arrayInt := [1, 5, 10]
4444
arrayObj := [{"name": "bob", "age": 22}, {"name": "tom", "age": 51}]
4545
4646
; Map to doubled value
47-
array_map(arrayInt, func("double")) ; Output: [2, 10, 20]
47+
array_map(arrayInt, func("double_int")) ; Output: [2, 10, 20]
48+
4849
double_int(int) {
4950
return int * 2
5051
}
5152
5253
; Map to object property
5354
array_map(arrayObj, func("get_name")) ; Output: ["bob", "tom"]
55+
5456
get_name(obj) {
5557
return obj.name
5658
}
5759
```
5860

5961
_**As Array Object Extension**_
60-
**array_base.ahk** contains each ported function as a method of the object *_Array*. The most intuitive use case is extending the built-in Array object (assigning it's base object). Some environments avoid modifying built-ins and prefer using custom collection objects.
62+
**array_base.ahk** contains each ported function as a method of the object *_Array*. The most intuitive use case is extending the built-in Array object (assigning it's base object). Some environments avoid modifying built-ins and prefer using custom collection objects. This allows the familar method chaining many have become accustomed to in other languages.
6163

6264
Usage: `Array.<fn>([params*])` (Assuming Array's base object was extended)
6365
```autohotkey
@@ -73,16 +75,27 @@ arrayInt := [1, 5, 10]
7375
arrayObj := [{"name": "bob", "age": 22}, {"name": "tom", "age": 51}]
7476
7577
; Map to doubled value
76-
arrayInt.map(func("double")) ; Output: [2, 10, 20]
78+
arrayInt.map(func("double_int")) ; Output: [2, 10, 20]
79+
7780
double_int(int) {
7881
return int * 2
7982
}
8083
8184
; Map to object property
8285
arrayObj.map(func("get_name")) ; Output: ["bob", "tom"]
86+
8387
get_name(obj) {
8488
return obj.name
8589
}
90+
91+
; Method chaining
92+
arrayObj.map(func("get_prop").bind("age"))
93+
.map(func("double_int"))
94+
.join(",")
95+
96+
get_prop(prop, obj) {
97+
return obj[prop]
98+
}
8699
```
87100

88101
_**Sorting**_
@@ -93,10 +106,11 @@ Direct Usage: `Array_Quicksort.Call(Array, [params*])`
93106
```autohotkey
94107
arrayInt := [11,9,5,10,1,6,3,4,7,8,2]
95108
109+
; Indirect usage
96110
array_sort(arrayInt) ; Output: [1,2,3,4,5,6,7,8,9,10,11]
97111
arrayInt.sort() ; Output: [1,2,3,4,5,6,7,8,9,10,11]
98112
99-
; Each library function facades to the same invocation below
113+
; Direct usage - each library function facades to the same invocation below
100114
Array_Quicksort.Call(arrayInt)
101115
```
102116

0 commit comments

Comments
 (0)