Skip to content

Commit cc4ab8a

Browse files
committed
Reworded portions of readme, added usage
1 parent e07083c commit cc4ab8a

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

README.md

+24-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,30 @@
22
## Conversion of JavaScript's Array methods to AutoHotkey
33

44

5-
AHK supports functors but no built in functions for functional style operations. Funky. JavaScript's Array object has some nice methods; so I stole them.
5+
AHK supports [objects](https://autohotkey.com/docs/objects/Object.htm), [arrays](https://autohotkey.com/docs/Objects.htm#Table_of_Contents), and [function objects](https://autohotkey.com/docs/objects/Functor.htm). But it lacks built in methods for functional operation on arrays, like `Array.map()`. JavaScript's Array object has some handy methods; so I ported them over.
66

7-
Since AHK is also prototypical in nature, these could have been added to a base object. But that didn't happen for simplicities sake, they are all prefixed with `array_`.
7+
Since AHK is also prototypical in nature, these could have been added to a base object. For simplicity's sake these are global functions. All methods are prefixed with `array_`.
8+
9+
### Usage
10+
11+
Just include the `array_.ahk` file and pass functors as arguments when needed. For instance, to double all values in an array:
12+
13+
array := [1,2,3,4]
14+
result := array_map(array, func("double"))
15+
double(item) {
16+
return item * 2
17+
}
18+
msgbox % array_toString(result) ;outputs "[2,4,6,8]"
19+
20+
or getting fancy with a partial:
21+
22+
array := [12,3,44,9]
23+
result := array_map(array, func("multiply").bind(2))
24+
multiply(a, b) {
25+
return a * b
26+
}
27+
msgbox % array_toString(result) ;outputs "[24,6,88,18]"
28+
829

930
### Stolen Methods
1031

@@ -34,7 +55,7 @@ Since AHK is also prototypical in nature, these could have been added to a base
3455
Considered implementing a `array_sort` quicksort; but currently no immediate need.
3556

3657
### Tests
37-
Nothing is truely complete without testing, so each array_<method> has a test case file in the `tests/` directory.
58+
Nothing is truely complete without testing, so each `array_<method>` has a test case file in the `tests/` directory.
3859

3960
Built a few primitive [test classes](test_suite/tester.ahk) to collect test cases. Management of this test class is located in [testrunner.ahk](testrunner.ahk). Results are output to an edit control in a new window.
4061

0 commit comments

Comments
 (0)