Skip to content

Add invoke operator function extensions for Function types#2

Merged
MukjepScarlet merged 7 commits into
CCBlueX:mainfrom
Emirlol:invoke
Jan 12, 2026
Merged

Add invoke operator function extensions for Function types#2
MukjepScarlet merged 7 commits into
CCBlueX:mainfrom
Emirlol:invoke

Conversation

@Emirlol

@Emirlol Emirlol commented Jan 10, 2026

Copy link
Copy Markdown
Contributor

Just a little syntax sugar so we don't have to juggle between apply, get, get<primitive>, test, or accept. If it's invokeable, invoke it.

Hope you don't mind the PR.


Some notes:

I had to update kotlin version to use Enum.entries, but then noticed there are already forEach style functions for the fast util types. If it's unnecessary, I can revert it back. Same goes for gradle version (well, what I said earlier applies mostly to the gradle version as kotlin-dsl uses the embedded kotlin version within gradle, but I had already updated kotlin by the time I figured this out).

Also, I'm not sure what to do for formatting. I might've accidentally reformatted some spaces into tabs. I see there's something called spotless, but I don't know how to use it and I didn't see a gradle task for it either.

@Emirlol

Emirlol commented Jan 10, 2026

Copy link
Copy Markdown
Contributor Author

It also dawned on me too late that the get style methods are called that since maps are literally implementations of them. While I don't get why a Map inherits a Function (it doesn't in the java stdlib) these methods also allow calling the map.

I don't think this is that bad by itself since it feels like the indexing operator, but the original get methods are also usable with the indexing operator. This means both of map(key) and map[key] do the same thing. The key point is that map[key] does not generalize to generic keys, since those are deprecated and the javadoc refers you to the specific method that returns the unboxed value. With invoke, those also work.
So, while not harmful, I don't know if this would be confusing or not.

@MukjepScarlet

Copy link
Copy Markdown
Collaborator

Don't use \t as indent

Comment thread gradle/libs.versions.toml Outdated
@MukjepScarlet

Copy link
Copy Markdown
Collaborator

I don't think this is that bad by itself since it feels like the indexing operator, but the original get methods are also usable with the indexing operator. This means both of map(key) and map[key] do the same thing. The key point is that map[key] does not generalize to generic keys, since those are deprecated and the javadoc refers you to the specific method that returns the unboxed value. With invoke, those also work.

This is interesting. get{ValueType} also exists in {Type}Lists.

@MukjepScarlet MukjepScarlet merged commit 4d5015f into CCBlueX:main Jan 12, 2026
@Emirlol Emirlol deleted the invoke branch January 13, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants