Giter Site home page Giter Site logo

Comments (4)

bluss avatar bluss commented on August 29, 2024

Maybe the name .map_inplace()? Could even be a win for regular mapping in some weird scenario where moves are costly and don't optimize out.

Do you have a real use case in mind? Asking because we don't want to collect nice to haves that nobody needed. (We already have enough of that in itertools.. 😞 )

from itertools.

abonander avatar abonander commented on August 29, 2024

One example came up in a possible improvement to a solution I gave in this thread on /r/rust (with your suggested naming):

fn permutations(seq: Vec<i32>) -> Vec<Vec<i32>> {
    match seq.len() {
        0 => return vec![],
        1 => return vec![seq],
        _ => (),
    }

    seq.iter().enumerate().flat_map(|(head_idx, &head)| {
        let mut remainder = seq[..head_idx].to_owned();

        if seq.len() > head_idx + 1 {
            remainder.extend(&seq[head_idx + 1..]);
        }

        permutations(remainder).map_inplace(|perm| perm.insert(0, head))
    })
    .collect()
}

However, I don't know if .map_inplace() is the best name, since mapping suggests going from one type to another. For example, Vec::map_in_place() performed the conversion T -> U where mem::size_of::<T>() == mem::size_of::<U>().

I like .edit() or .update(), myself, with .mutate() coming in a close third.

from itertools.

bluss avatar bluss commented on August 29, 2024

I like update too.

from itertools.

bluss avatar bluss commented on August 29, 2024

Implemented by @lucasem in #232 and in itertools 0.7.4!

from itertools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.