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

Improve API design for String::concat #1496

Open
illusory0x0 opened this issue Jan 16, 2025 · 5 comments
Open

Improve API design for String::concat #1496

illusory0x0 opened this issue Jan 16, 2025 · 5 comments

Comments

@illusory0x0
Copy link
Contributor

if we concat Array[String], we have to xxx.iter().to_array(), I consider use Iter[String] uniformly handle all sequence.

and if Iter[String] is non termination, concat also is non termination, User should use Iter::take, before concat

let alphabet = [
  "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
  "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
]

test {
  for i in 0..<27 {
    let s = String::concat(alphabet[0:i].iter().to_array())
    println(s)
  }
}

String::concat

Origin

String::concat(Array[String], separator~ : String = ..) -> String

New

String::concat(Iter[String], separator~ : String = ..) -> String

Array::flatten

Origin

pub fn Array::flatten[T](self : Array[Array[T]]) -> Array[T]

New

pub fn Array::flatten[T](self : Iter[Array[T]]) -> Array[T]
@gmlewis
Copy link
Contributor

gmlewis commented Jan 16, 2025

I REALLY dislike String::concat and sorely miss alphabet.join(", ").

@gmlewis
Copy link
Contributor

gmlewis commented Jan 16, 2025

This proposal makes the syntax even uglier in my opinion.

@illusory0x0
Copy link
Contributor Author

I REALLY dislike String::concat and sorely miss alphabet.join(", ").

here is a possible API design

Iter::join(self : Iter[String], separator~ : String = ..) -> String

@Lampese
Copy link
Collaborator

Lampese commented Jan 16, 2025

I REALLY dislike and sorely miss .String::concat``alphabet.join(", ")

here is a possible API design

Iter::join(self : Iter[String], separator~ : String = ..) -> String

Are you seeking this?

@illusory0x0
Copy link
Contributor Author

illusory0x0 commented Jan 16, 2025

String::concat might need to be deprecated, otherwise, we need add concat_arrayview, concat_deque.....,

we shouldn't do the same thing in different way

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

No branches or pull requests

3 participants