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

List and Sexp should implement FromIterator<Element> #811

Open
popematt opened this issue Aug 12, 2024 · 0 comments
Open

List and Sexp should implement FromIterator<Element> #811

popematt opened this issue Aug 12, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@popematt
Copy link
Contributor

It's a little awkward to turn an iterator of Element into a List right now. You must collect as a Sequence or Vec<Element> and then convert to a List. E.g.:

fn json_to_ion(value: serde_json::Value) -> Element {
    match value {
    // ...
    Value::Array(values) => List(
            values
                .into_iter()
                .map(|v| json_to_ion(v))
                .collect::<Sequence>()
        )
        .into(),
    }
}

Since Sequence already implements FromIterator<Element>, why not Sexp and List? It would be nice to collect directly as a List or Sexp`. E.g.:

fn json_to_ion(value: serde_json::Value) -> Element {
    match value {
        // ...
        Value::Array(values) => values
            .into_iter()
            .map(|v| json_to_ion(v))
            .collect::<List>()
            .into(),
    }
}
@popematt popematt added the enhancement New feature or request label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant