[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)

29 Oct 2020, 12:56

v0.35.0 has been published.

.groupBy was added. https://biga-ahk.github.io/biga.ahk/#/?id=groupby
Creates an object composed of keys generated from the results of running each element of collection thru iteratee.

Code: Select all

A.groupBy([6.1, 4.2, 6.2], A.floor)
; => {4: [4.2], 6: [6.1, 6.2]}

A.groupBy([6.1, 4.2, 6.3], func("Ceil"))
; => {5: [4.2], 7: [6.1, 6.3]}


users := [ { "user": "barney", "lastActive": "Monday" }
        , { "user": "fred", "lastActive": "Tuesday" }
        , { "user": "pebbles", "lastActive": "Tuesday" } ]
        
; The `A.property` iteratee shorthand.
A.groupBy(users, "lastActive")
/* => {"Monday": [{ "user": "barney", "lastActive": "Monday" }]
     , "Tuesday": [{ "user": "fred", "lastActive": "Tuesday" }, { "user": "pebbles", "lastActive": "Tuesday" }]}*/
Somewhat similar to .partition; except this can separate elements into a number of groups.
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

18 Nov 2020, 17:35

v0.35.1 has been published.

.isEqual was updated. Previously only two parameters were allowed. The 2nd parameter is now variadic allowing multiple values to be compared in a single call.

Code: Select all

A.isEqual(1, 1, 1)
; => true

A.isEqual({ "a": 1 }, { "a": 1 }, { "a": 2 })
; => false
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

28 Dec 2020, 13:24

v0.35.2 has been published.

.sampleSize has been updated. Previously supplying an associative array would yield unexpected results. This has been fixed.

Previously:

Code: Select all

A.sampleSize({"key1": "value1", "key2": "value2"}, 2)
; => ["", ""]
Now:

Code: Select all

A.sampleSize({"key1": "value1", "key2": "value2"}, 2)
; => ["value1", "value2"]
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

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

30 Dec 2020, 02:13

Can you add some functionality that is not built into the ahk? We understand your sticking to Lodash. But if we are using this library it would be nice if it gives some additional stuff as well. Especially some functional features built into python.
Thanks for everything.
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

30 Dec 2020, 15:12

That is a cool idea. I don't know when but I do want to make an accompanying utility class for things that aren't exact translations but still needed.
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

15 Jan 2021, 19:06

v0.35.4 has been published.

.truncate should perform much faster.
.indexOf should perform slightly faster.

There was an incorrect parameter accepted on .initial

There was a bug with .truncate that would not allow a blank omission option "". This is now an accepted option.
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

19 Jan 2021, 16:37

v0.36.0 has been publshed.

.pad .padStart and .padEnd have been added.

A longstanding bug was fixed in .floor
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

19 Jan 2021, 19:56

v0.37.1 has been published.

For some other projects I created a process for aliases and I brought that support into biga.ahk's build script. Therefore the following aliases now work, are documented, and are included in tests:

.head is also accessible via .first
.forEach is also accessible via .each
.toPairs is also accessible via .entries
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

26 Jan 2021, 18:20

v0.38.0 has been published.

.last and .sortedUniq have been added.


.last
Gets the last element of array.

Code: Select all

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

A.last([])
; => ""

A.last("fred")
; => "d"

A.last(100)
; => "0"


.sortedUniq
This method is like .uniq except that it's optimized for sorted arrays.

Code: Select all

A.sortedUniq([1, 1, 2])
; => [1, 2]
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

28 Jan 2021, 01:52

v0.38.1 has been published.

Small bug fixed in .uniq

.camelCase and .startCase were simplified slightly.

Writing biga.ahk has frequently forced me to learn and explore ahk more deeply. The library uses an internal system for some simple type checking. That system got more sophisticated with this version after I started noticing some artifacts with my usage of is alnum which cost me a few hours of head scratching and bug hunting.

Please enjoy it :thumbup:


Hopefully tomorrow, but perhaps more realistically next month; I want to get some performance measuring in place to track any areas that could be faster.
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

05 Mar 2021, 18:45

v0.40.0 has been published.

Bug fixed in .join and .toString
various small changes for performance


.some was added.
Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate returns truthy. The predicate is invoked with three arguments: (value, index|key, collection).

Code: Select all

users := [{ "user": "barney", "active": true }, { "user": "fred", "active": false }]
; The `A.matches` iteratee shorthand.
A.some(users, { "user": "barney", "active": false })
; => false

; The `A.matchesProperty` iteratee shorthand.
A.some(users, ["active", false])
; => true

; The `A.property` iteratee shorthand.
A.some(users, "active")
; => true
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

20 Mar 2021, 03:16

v0.40.1 has been published.

.map should be measurably faster and will now work with iteratees/functions that call for more than just value.
The iteratee is invoked with three arguments: (value, index|key, collection).

bug fixed in .head and .take when used with associative arrays.


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)

09 Apr 2021, 15:39

When I started using these methods I began to notice I didn't have to think about loops so much or digging around them to get the data I wanted. I just threw the library at every problem and started thinking about my app or project at a higher level because I wasn't constantly sifting through arrays or strings.
As I got more familiar with the ethos of immutability (creating new arrays instead of modifying existing ones), my ability to add new features without breaking old ones improved significantly. I also had slightly less circumstantial bugs because my apps were less fragile and monolithic arrays were not being mutated by two or three different functions.
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

20 Apr 2021, 09:52

v0.41.0 has been published.

added methods:
.findKey https://biga-ahk.github.io/biga.ahk/#/?id=findkey
.findLast https://biga-ahk.github.io/biga.ahk/#/?id=findlast

fixes:
using .property shorthands with associative array collections will work now.

Code: Select all

users := {"barney": {"active": true }, "fred": {"active": false }, "pebbles": {"active": false }}

; The `A.property` iteratee shorthand.
A.count(users, "active")
; => 1
Was previously returning 0
Last edited by Chunjee on 21 Apr 2021, 12:01, 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)

20 Apr 2021, 11:03

Obviously navigating a 10,000+ element array is going to be "slower" in an ahk environment. If dealing with an exceptionally large array and the .property shorthand; it may help speedwise to have one or more of the property being queried near or at the head of the array.
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

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

21 Apr 2021, 16:11

v0.42.0 has been published. I would like to think of this a big update.

added methods:
.depthOf https://biga-ahk.github.io/biga.ahk/#/?id=depthof
was previously an internally method for some of the flatten methods. Figured it might be useful and added it's own documentation.
.mapKeys https://biga-ahk.github.io/biga.ahk/#/?id=mapkeys
.mapValues https://biga-ahk.github.io/biga.ahk/#/?id=mapValues


fixes:
.sortby was refactored so that it may now accept bigA methods or other boundfunctions for the iteratees parameter. Meaning you can now easily sort by the result of other methods, without adding them to the resulting array.

Code: Select all

; sort by the size of the string
A.sortBy(["ab", " abc", "a", "abc"], A.size)
; => ["a", "ab", "abc", " abc"]

Code: Select all

arr := ["cba",  "dcb", "c", "zza"]

; regular sort
A.sortBy(arr)
; => ["c", "cba", "dcb", "zza"]

; sort by the last character
A.sortBy(arr, A.last)
; => ["cba", "zza", "dcb", "c"]
It may need a little more work to take arguments backwards. I will give .flip another shot but in the meantime you can wrap methods in a function to sort flip the order like so:

Code: Select all

; sort by number of `b` characters
arr := ["pebbles", "barney", "BBQ Benny"]
A.sortBy(arr, Func("fn_countBs"))
; => ["BBQ Benny", "barney", "pebbles"]

fn_countBs(x)
{
	return biga.count(x, "b")
}
Please enjoy the new features :thumbup:
Last edited by Chunjee on 21 Apr 2021, 16:37, edited 1 time in total.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

21 Apr 2021, 16:19

@Chunjee, thanks once again for all your work on this great project. By the way, updating with npm is really painless, thanks.
Regards,
burque505

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 116 guests