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

Introduce String.join function #2762

Merged
merged 6 commits into from
Sep 18, 2023
Merged

Conversation

darkdrag00nv2
Copy link
Contributor

@darkdrag00nv2 darkdrag00nv2 commented Sep 3, 2023

Work towards #2752

Description

Adds join(_ strs: [String], _ separator: String): String function to Cadence. The function returns a string value after concatenating elements of the provided array of string with the given separator.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@codecov
Copy link

codecov bot commented Sep 3, 2023

Codecov Report

Patch coverage: 90.90% and project coverage change: +0.04% 🎉

Comparison is base (5254952) 79.18% compared to head (9356371) 79.22%.
Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2762      +/-   ##
==========================================
+ Coverage   79.18%   79.22%   +0.04%     
==========================================
  Files         333      333              
  Lines       78614    78719     +105     
==========================================
+ Hits        62248    62365     +117     
+ Misses      14063    14045      -18     
- Partials     2303     2309       +6     
Flag Coverage Δ
unittests 79.22% <90.90%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
runtime/interpreter/value_string.go 90.66% <89.65%> (-1.18%) ⬇️
runtime/interpreter/value.go 67.12% <100.00%> (-0.01%) ⬇️
runtime/sema/string_type.go 96.15% <100.00%> (+0.27%) ⬆️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

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

Nice!

runtime/interpreter/value_string.go Outdated Show resolved Hide resolved
runtime/interpreter/value_string.go Outdated Show resolved Hide resolved
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice!

runtime/interpreter/value_string.go Show resolved Hide resolved
runtime/interpreter/value_string.go Show resolved Hide resolved
runtime/sema/string_type.go Outdated Show resolved Hide resolved
runtime/sema/string_type.go Outdated Show resolved Hide resolved
@turbolent
Copy link
Member

@SupunS Contributors can't add labels themselves, please add one for the release notes

@SupunS SupunS added the Feature label Sep 5, 2023
runtime/interpreter/value_string.go Outdated Show resolved Hide resolved
runtime/interpreter/value_string.go Outdated Show resolved Hide resolved
runtime/interpreter/value_string.go Outdated Show resolved Hide resolved
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Looks good!

Regarding the default: Every language's standard library seems to have a different default, so maybe choosing the empty string as the "lowest common denominator" is best, as it avoids surprises based on wrong expectations.

Maybe we should just require it, i.e. not have any default?

For example:

  • Swift: "" (empty string)
  • JavaScript: ","
  • Kotlin: ", " (additional space)
  • Python, Rust, Go: no default

runtime/interpreter/value_string.go Outdated Show resolved Hide resolved
runtime/sema/string_type.go Outdated Show resolved Hide resolved
@darkdrag00nv2
Copy link
Contributor Author

I think it is probably best to just make it required. Made it required in b92d5e1.

If we want to have a default, then I would prefer having the same default in split and join. Empty string won't work in split, so I don't prefer it.

Copy link
Contributor

@dsainati1 dsainati1 left a comment

Choose a reason for hiding this comment

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

If I understand correctly, this function doesn't mutate the input array, so making a note to myself to add the appropriate view annotation as per #2466

@darkdrag00nv2
Copy link
Contributor Author

@SupunS @turbolent Should we merge this?

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice!

runtime/sema/string_type.go Outdated Show resolved Hide resolved
Co-authored-by: Bastian Müller <[email protected]>
@SupunS SupunS merged commit ed71b40 into onflow:master Sep 18, 2023
11 of 14 checks passed
@darkdrag00nv2 darkdrag00nv2 deleted the string_join branch September 20, 2023 17:28
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.

4 participants