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

add examples for filter #269

Merged
merged 2 commits into from
Jan 24, 2025
Merged

Conversation

rwtolbert
Copy link
Contributor

add examples for filter

@sogaiu
Copy link
Collaborator

sogaiu commented Jan 24, 2025

Looks good, though here are some alternates for consideration (note that chr happens at compile time):

(filter |(< 65 $) "foo01bar") 
# => 
@[102 111 111 98 97 114]

(filter |(< (chr "A") $) "foo01bar") 
# => 
@[102 111 111 98 97 114]

May be using chr is somewhat clearer and if folks don't know what that is, searching for it on the Core API page or via doc wouldn't be too bad?

(string/join
  (map string/from-bytes 
       (filter |(< "A" (string/from-bytes $)) "foo01bar"))) 
# =>
"foobar"

(string/from-bytes ;(filter |(< (chr "A") $) "foo01bar"))
# =>
"foobar"

Perhaps this way we can avoid string/from-bytes being called more than once and avoid a few other calls?

@rwtolbert
Copy link
Contributor Author

I like that idea. Let me see what I can do.

@rwtolbert
Copy link
Contributor Author

@sogaiu updated.

@sogaiu sogaiu merged commit d5fa463 into janet-lang:master Jan 24, 2025
1 check passed
@sogaiu
Copy link
Collaborator

sogaiu commented Jan 24, 2025

Thanks!

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