[Class] biga.ahk (166 utility methods)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by Chunjee » 10 Sep 2021, 21:35

v0.49.0

new:
.castArray
.toArray
.at

fixes:
.merge

Code: Select all

A.castArray("abc")
; =>  ["abc"]

A.toArray("abc")
; => ["a", "b", "c"]
Please enjoy it :thumbup:

samuells
Posts: 1
Joined: 20 Feb 2021, 12:47

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by samuells » 02 Nov 2021, 06:06

Hi 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.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by Chunjee » 03 Nov 2021, 13:53

samuells wrote:
02 Nov 2021, 06:06
Hi 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.
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.

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


Whereas .forEach is designed to loop the entire array anytime it is called (though it may exit iteration early by returning false)

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


william_ahk
Posts: 481
Joined: 03 Dec 2018, 20:02

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by william_ahk » 15 Nov 2021, 09:05

Hi 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!

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by Chunjee » 16 Nov 2021, 12:04

william_ahk wrote:
15 Nov 2021, 09:05
Hi 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!
Not that type of sort. Please see .sort() which is a part of array.ahk
That allows two input parameters for comparison like you describe.

william_ahk
Posts: 481
Joined: 03 Dec 2018, 20:02

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by william_ahk » 17 Nov 2021, 01:34

Chunjee wrote:
16 Nov 2021, 12:04
william_ahk wrote:
15 Nov 2021, 09:05
Hi 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!
Not that type of sort. Please see .sort() which is a part of array.ahk
That allows two input parameters for comparison like you describe.
Thanks!

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by Chunjee » 23 Nov 2021, 15:35

v0.51.0

new:
.delay

Code: Select all

A.delay(Func("fn_delayFunc"), 1000, "later")
fn_delayFunc(text) {
    msgbox, % text
}
; => msgboxes "later" after one second.
Please enjoy it :thumbup:

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by Chunjee » 25 Nov 2021, 00:47

Concerning .delay; it also works with boundFuncs which may look more natural if you are already used to using them:

Code: Select all

boundFunc := Func("fn_delayFunc").bind("later")
A.delay(boundFunc, 1000)
fn_delayFunc(text) {
    msgbox, % text
}
; => msgboxes "later" after one second.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by Chunjee » 22 Feb 2022, 12:31

I am very happy with the library and used it to great success in my Wordle helper app you can find here: viewtopic.php?f=19&t=99991

A lot of heavy lifting done in that app with the .filter method. I create matchesProperty functs for letter locations that MUST match and CAN'T match; then filter the large array of letters to filter down to the remaining possible words.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by Chunjee » 10 Mar 2022, 14:14

Created a plugin: https://github.com/Chunjee/frequencies_bigaplugin.ahk

I will writeup a guide on creating your own plugins to establish naming conventions and norms. I would like it to always be as simple as Including the extra package and using the class as normal:

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}
Because the main class has to exist before being modified, plugins will have to be included afterwards


User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (144 super handy utilities and counting)

Post by Chunjee » 06 May 2022, 18:14

been thinking of a new method .typeOf which given a single argument, will return it's type. Javascript returns the following types: number, string, boolean, object, and undefined. There is no float type

ahk v1 doesn't have a clear boolean type; so that is out prettymuch no matter what. But I was thinking to return the following types: integer, float, string, object, and undefined (or "")


from the docs:
AutoHotkey does not have a specific boolean type, so it uses the integer value 0 to represent false and 1 to represent true.

MrDoge
Posts: 151
Joined: 27 Apr 2020, 21:29

Re: [Class] biga.ahk (144 super handy utilities and counting)

Post by MrDoge » 07 May 2022, 11:30

viewtopic.php?f=6&t=2306#p434415
Array, Object, String, Buffer(just VarSetCapacity), Float, Integer

I would consider "" empty string instead of undefined variable
typeOf(varA) ;please return "undefined variable"
typeOf(varB:="") ;please return "String"
varA is undefined, varB is initialized to empty string, but for AHKv1, they have no difference at all, so it's impossible to differentiate
viewtopic.php?f=76&t=89664&start=20#p395439
lexikos wrote:
22 Apr 2021, 07:28
You now know that all non-dynamic variables exist by the time your code executes, as far as AHK is concerned. If you want to test the conditions under which AHK considers a variable initialized, you need only enable #Warn UseUnset and access the variable.
so it seems to be possible, but can you use access the knowledge of #Warn UseUnset ? in a function ?
WHAT, this is insanity, I had not found the spoiler(I thought IsSet() was v2 exclusive), this changes everything


assume var1:=""
%var1% is exactly the same as "": zero capacity, IsByRef() false (it is not the address of the unowned string because integer literals too have this property, so emptyStringAddress below is wrong)
assume var2:="abc", and variables abc, var4 do not exist
%var2% is exactly the same as var3:="" and is exactly the same as var4: zero capacity, IsByRef() true

an empty string can be owned by a variable, or not. so this function does nothing to differentiate..

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
}
___
Array, Object, String, Buffer, Float, Integer, uninitialized variable

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"
            }
        }

    }
}



User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (immutable utility library for arrays, strings, etc)

Post by Chunjee » 23 Jul 2022, 22:55

v0.53.0

new:
.has
.noop
.nthArg
.propertyOf
.toLength
.unzip

fixes:
.property

Code: Select all

object := {"a": { "b": ""}}
A.has(object, "a")
; => true

A.has(object, "a.b")
; => true
Please enjoy it :thumbup:


User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (144 super handy utilities and counting)

Post by Chunjee » 29 Jul 2022, 19:17

v0.54.0

new:
.ary
.conforms
.conformsTo
.eq
.flip
.forInRight
.forIn
.gt
.gte
.isError
.lt
.lte
.toLength
.upperFirst

fixes:
.camelCase
.kebabCase
.snakeCase
.upperCase

performance:
.map should be slightly faster

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"}]
Please enjoy it :thumbup:

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: [Class] biga.ahk (144 super handy utilities and counting)

Post by Chunjee » 01 Nov 2022, 15:18

v0.54.1

fixes:
.pick
.trim
.has documentation

performance:
.difference should be slightly faster

Post Reply

Return to “Scripts and Functions (v1)”