[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 » 21 Apr 2021, 16:40

At work I don't have dropbox or other 'share my library folder to multiple computers' tool.

I have been meaning to try another project with more dependencies to explore the idea. biga.ahk and most others in my npm profile are basically self-contained.
Last edited by Chunjee on 05 Aug 2021, 14:55, edited 1 time in total.


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 May 2021, 16:05

v0.42.1
fixes:
.findIndex
.isString

v0.42.2
fixes:
.find

performance enhancements:
.dropWhile .count .filter .find .groupBy .map .partition .reject .some .meanBy .findKey .mapKeys .mapValues .findIndex .dropRight

new:
.isCallable

Code: Select all

boundFunc := Func("strLen").bind()
A.isCallable(boundFunc)
; => true
IsFunc(boundFunc)
; => false

A.isCallable(A.isString)
; => true

A.isCallable(A.matchesProperty("a", 1)
; => true

A.isCallable([1,2,3])
; => false

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 » 03 May 2021, 18:27

For all the methods that can call on a function iteratee; I previously had two or three different checks to see what kind it might be. For example there was a simple isFunc() for straightforward functions, a fn.name check for method calls, and then shorthands turn into boundFuncs were their own challenge. But now basically all of these are discoverable with .isCallable
So the innerworkings have been simplified, meaning they are less prone to edge cases and probably slightly faster.


One complication is that some outputs could be confused by situations where the iteratee is called with the value, key, and collection. for example .trim the 2nd parameter is the characters to trim, and the key would not be useful in that situation and I have "guarded" it. I will be exploring all the methods that need to be guarded and the best way to accomplish that for all necessary methods.

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 » 07 May 2021, 19:15

v0.42.3

fixes:
.findIndex type checking
.find type checking
.keyBy will only use .property shorthand
.difference will remove all occurrences of value

performance enhancements:
.keyBy
.sortBy
.filter



.diffrence was only removing from the array once; whereas it will now remove all occurrences in accordance with the documentation "Creates an array of array values not included in the other given arrays."
Previously:

Code: Select all

A.difference([50, 50, 90], [50])
; => [50, 90]
Now:

Code: Select all

A.difference([50, 50, 90], [50])
; => [90]
Last edited by Chunjee on 25 May 2021, 19:04, edited 4 times in total.


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 » 14 May 2021, 16:17

Pretty chill way to generate an array of random numbers. Without a lot of extra helper functions, variables, outputvars, or while loops; you can control: how many, lower limit, upper limit

Code: Select all

boundFunc := A.random.bind(A, 1, 1000)
array := A.times(5, boundFunc)
; => [395, 364, 809, 904, 449]
Last edited by Chunjee on 28 May 2021, 08:26, edited 1 time in total.


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

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

Post by MrDoge » 23 May 2021, 17:30

I converted a modded version of biga.ahk to AHK_H v2 (you may want to create a v2 branch on github)
I wanted the conversion to be totally done automatically, but I had to make a few mods (I used biga.ahk to break and improve ahk_parser.js, so ty)
please test it

og: Biga.ahk
modded: Biga_mid.ahk

converted: Biga.ah2
script that uses it: use biga.ah2

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 » 24 May 2021, 12:00

Thank you that is very much appreciated! I think that is worth linking in the README so that those using v2 can more easily find it.

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 May 2021, 19:01

v0.44.0

new:
.isInteger

fixes:
.parseInt more handling of numberlike strings ("10,100", "10 10")
.includes work with object values

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 » 28 May 2021, 09:59

v0.44.1

performance:
.isCallable should be slightly faster

fixes:
.sample and .sampleSize will now work with string input. Meaning you can now just write A.sample("123") instead of A.sample(strSplit("123"))
There was a bug when using a guarded message (currently only .trim) when an instance of the class had not been initialized. Now the base class will be checked so that any extending class or fork will work.


Getting closer to a good system to handle more guarded methods.


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 » 21 Jul 2021, 16:12

v0.46.0

new:
.maxBy
.minBy
.pickBy
.countBy

fixes:
.words
Some Documentation typos


Count the word frequency in a long string:

Code: Select all

sentence := "If I remain careful, I can repeat what I am compelled to do, over and over again."
; find how many times each word appears in the sentence
wordOccurances := A.countBy(A.words(sentence), A.toLower)
; => {"again": 1, "am": 1, "and": 1, "can": 1, "careful": 1, "compelled": 1, "do": 1, "i": 3, "if": 1, "over": 2, "remain": 1, "repeat": 1, "to": 1, "what": 1}
Please enjoy it :thumbup:

ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

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

Post by ozzii » 22 Jul 2021, 04:05

Thank you for this class and the updates

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 » 28 Jul 2021, 11:40

v0.47.0

new:
.identity
.stubArray
.stubFalse
.stubObject
.stubString
.stubTrue


fixes:
.countBy
.every
.findIndex
.findLastIndex
.keyBy
.mapKeys
.mapValues
.maxBy
.meanBy
.minBy
.partition
.pickBy
.sortBy
.sumBy
.times


performance:
.forEach
.invertBy
.keyBy


In the documentation you may have seen "predicate:=.identity" but prior to today this default didn't work on account of .identity not existing. Most of the fixes listed above had to do with making this work for all those methods; but other methods didn't require any code change and are not listed.

Added 24 new unit tests across 22 different methods to ensure .identity always works as a default parameter. This brings the total tests to 632


.identity is a curious method; it just returns the value supplied; not every useful on it's own but since many methods call functions; it can be useful to pass back the called data without any changes.

Create and fill an array:

Code: Select all

A.times(10, A.identity)
; => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Since .times uses the .identity as a default iteratee; it can be done the same simply with:

Code: Select all

A.times(10)
; => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

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

Re: [Class] biga.ahk (utilities mirroring Lodash)

Post by Chunjee » 14 Aug 2021, 12:21

Chunjee wrote:
02 Oct 2019, 13:16
in v0.3.4 the #Include is now structured

Code: Select all

class biga {
    ; {{methods}}
}

class A extends biga {
    ; no changes
}
Which means a "superobject" named A will be available at the global scope without creating an instance of biga(). This will continue to exist as a convenience but as a normal practice I would recommend creating an instance of any class you use.
I think removing this superglobal A would be a good idea; which was already in my plan at or around v1.0.0

If you disagree please let me know and why.

tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

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

Post by tuzi » 19 Aug 2021, 20:29

Why would I miss this lib for such a long time. It's so good!
I love it. Thank you for share it!

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 » 20 Aug 2021, 23:37

v0.48.0

new:
.get


fixes:
.inRange
The superglobal A has been removed

Code: Select all

object := {"a": [{ "b": { "c": 3} }]}
A.get(object, "a[1].b.c")
; => 3

A.get(object, ["a", "1", "b", "c"])
; => 3

A.get(object, "a.b.c", "default") ; returns default parameter since no value found at "a.b.c"
; => "default"

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 Aug 2021, 18:35

The library is available for use via the Ace bot and the .ahk command on Discord. Include by using #Include <biga>

image.png
image.png (38.69 KiB) Viewed 3435 times

Post Reply

Return to “Scripts and Functions (v1)”