Skip to content

Why do functions of trait Statistics take ownership on the dataset and not immutable reference ? #345

@DvxBellorvm

Description

@DvxBellorvm

Hello

This is a question I have been wondering for a while: why all the functions in the statistics::Statistics trait take self and not &self ?
I often have the use case where I need to compute several statistics on the same dataset, like for example:

use statrs::statistics::Statistics;

fn main() {
    let dataset = vec![0., 1., 2., 3., 4., 5.];
    let mean = dataset.mean();
    let variance = dataset.variance();
}

but I cannot do so because mean(self) function takes ownership on the dataset. The only solution I see is to clone the dataset, which in my use case is usually not wanted.
Naïvely, if I had to implement a mean() function, I would only need an immutable reference on the dataset to do so, so I am wondering if there is a specific reason for this particular design choice, and could it change in the future ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions