new:
.castArray
.toArray
.at
fixes:
.merge
Code: Select all
A.castArray("abc")
; => ["abc"]
A.toArray("abc")
; => ["a", "b", "c"]
Code: Select all
A.castArray("abc")
; => ["abc"]
A.toArray("abc")
; => ["a", "b", "c"]
If you are trying to iterate an array on keypresses there are probably better ways to do that; like a counter variable that increments every time the button is pressed.samuells wrote: ↑02 Nov 2021, 06:06Hi Chunjee, I just found this project and I have to say "really awesome stuff", also well documented thanks for your effort. But I would like to know or probably a suggestion for a future feature, since I have been looking how to do this for awhile. How could I apply the forEach function with the keywait command. I'm trying to iterate an array with for statment and the keywait command, for example when a press some hotkey it start iterating through this array and stop after the first value and continues after pressing the same hotkey again. Something like the forEach function with the keywait thingy. Thanks.
Code: Select all
myArray := [1, 2, 3]
F1::
counter++
; reset counter if it goes past the array size
if (counter > A.size(myArray)) {
counter := 1
}
msgbox, % myArray[counter]
return
Code: Select all
A.forEach([1, 2, 3], Func("fn_forEachFuncExample"))
fn_forEachFuncExample(value)
{
if (value == 3) {
return false
}
msgbox, % value
}
; msgboxes 1, then 2, then exits early on 3rd iteration
Not that type of sort. Please see .sort() which is a part of array.ahkwilliam_ahk wrote: ↑15 Nov 2021, 09:05Hi Chunjee, how is the callback function for the sortBy method used? I'm a bit confused that there's only one input parameter, how can I do advanced comparisons and such? Thanks!
Thanks!Chunjee wrote: ↑16 Nov 2021, 12:04Not that type of sort. Please see .sort() which is a part of array.ahkwilliam_ahk wrote: ↑15 Nov 2021, 09:05Hi Chunjee, how is the callback function for the sortBy method used? I'm a bit confused that there's only one input parameter, how can I do advanced comparisons and such? Thanks!
That allows two input parameters for comparison like you describe.
Code: Select all
A.delay(Func("fn_delayFunc"), 1000, "later")
fn_delayFunc(text) {
msgbox, % text
}
; => msgboxes "later" after one second.
Code: Select all
boundFunc := Func("fn_delayFunc").bind("later")
A.delay(boundFunc, 1000)
fn_delayFunc(text) {
msgbox, % text
}
; => msgboxes "later" after one second.
Code: Select all
#Include %A_ScriptDir%\node_modules
#Include biga.ahk\export.ahk
#Include frequencies_bigaplugin.ahk\export.ahk
A := new biga()
A.frequencies([1, 1, 3, 3, 4, 4, 5, 5, 8, 8])
; => {1: 2, 3: 2, 4: 2, 5: 2, 8: 2}
A.frequencies(["hello", "world", "Hello", "World"])
; => {"hello": 2, "world": 2}
AutoHotkey does not have a specific boolean type, so it uses the integer value 0 to represent false and 1 to represent true.
so it seems to be possible, but can you use access the knowledge of #Warn UseUnset ? in a function ?
Code: Select all
MsgBox % isByreff("")
MsgBox % isByreff(245)
MsgBox % isByreff(var456)
MsgBox % isByreff(var:="245")
isByreff(Byref v) {
static emptyStringAddress := VarSetCapacity(v, 6) ^ &v ^ 6 ;https://florian.github.io/xor-trick/
return &v != emptyStringAddress
}
Code: Select all
; Double-deref "" is a fatal error in general, try (MsgBox % %v%)
; so I can 'not support it', I also cannot support it...
; check before Double-deref:
; (v=="" ? "fatal error" : type(%v%))
MsgBox % type(a) ;"uninitialized variable"
MsgBox % type(a:="") ;"String"
MsgBox % (v=="" ? "fatal error" : type(%v%)) ;"fatal error"
v:="abc"
MsgBox % (v=="" ? "fatal error" : type(%v%)) ;"uninitialized variable"
type(Byref v) { ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=2306
; Array, Object, String, Buffer, Float, Integer, uninitialized variable
static Func_mParam := 3*A_PtrSize, Var_mAttrib := 8 + 3*A_PtrSize + 1
, Var_mAliasFor := 8 + A_PtrSize
, VAR_ATTRIB_UNINITIALIZED := 0x04
, funcAddress := &Func("type")
if IsObject(v) {
; if isArray() https://www.autohotkey.com/boards/viewtopic.php?f=76&t=64332&p=434396#p434396
if (!ObjCount(v) || ObjMinIndex(v) == 1 && ObjMaxIndex(v) == ObjCount(v) && v.Clone().Delete(1, v.MaxIndex()) == ObjCount(v)) {
return "Array"
} else {
return "Object"
}
} else {
objCapacity:=[v].GetCapacity(1)
if (objCapacity>0) {
;strings will get perfectly copied, but Buffer won't
; if ([copy:=v].GetCapacity(1)>0) {
if (v "") { ;concatenation works too, you can MsgBox % Buffer, but a Buffer won't concat
return "String" ;non empty String, we cover empty String down below
} else {
return "Buffer" ;Buffer with string representation, but can't concat
}
} else if (objCapacity==0) {
if (VarSetCapacity(v)) {
return "Buffer" ; 16 size Buffer with no String representation
} else {
; click the spoiler at the bottom in https://www.autohotkey.com/boards/viewtopic.php?f=76&t=89664&start=20#p395439
if (return NumGet(NumGet(NumGet(NumGet(funcAddress + Func_mParam)) + Var_mAliasFor) + Var_mAttrib, "uchar") & VAR_ATTRIB_UNINITIALIZED) {
return "uninitialized variable"
} else {
return "String" ; 0 size String And 0 size Buffer, they're the same thing
}
}
} else {
if (InStr(v,".")) {
return "Float"
} else {
return "Integer"
}
}
}
}
Code: Select all
object := {"a": { "b": ""}}
A.has(object, "a")
; => true
A.has(object, "a.b")
; => true
Code: Select all
objects := [{"a": 2, "b": "hello world"}
, {"a": 1, "b": 2}]
A.filter(objects, A.conforms({"b": A.isString.bind()}))
; => [{"a": 2, "b": "hello world"}]