Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stdlib): Add More String Iteration Functions #1864

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

spotandjake
Copy link
Member

This pr adds forEachChar, forEachCharI, map and mapi to the String library.

stdlib/string.gr Outdated Show resolved Hide resolved
stdlib/string.gr Outdated
* @since v0.6.0
*/
@unsafe
provide let forEachChar = (fn: Char -> Void, str: String) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably share some code between this function and forEachCodePoint; same with forEachChari

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the idx change, but I dont think it is optimial to share code here, the type signatures of fn are different so its not as simple as just having a bool that says to use char or code point. meaning you would need to use a wrapper function into the helper that tags the char, which it invokes an extra function call. On another note if we do want to go this route we might as well justhave a forEachCodePointIHelper which returns an unsafe code point. and then each function just becomes forEachCodePointIHelper((c, _) => fn(tagChar(c)), str).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants