#sorting #iterator #data-structure

sortby

adds convenient sort functions for Iterators

4 releases

0.1.3 May 6, 2023
0.1.2 Jul 26, 2020
0.1.1 Jun 18, 2020
0.1.0 Jun 17, 2020

#605 in Algorithms

Download history 707/week @ 2023-11-20 201/week @ 2023-11-27 252/week @ 2023-12-04 181/week @ 2023-12-11 455/week @ 2023-12-18 345/week @ 2023-12-25 157/week @ 2024-01-01 163/week @ 2024-01-08 324/week @ 2024-01-15 214/week @ 2024-01-22 159/week @ 2024-01-29 159/week @ 2024-02-05 206/week @ 2024-02-12 266/week @ 2024-02-19 255/week @ 2024-02-26 392/week @ 2024-03-04

1,119 downloads per month

MIT license

10KB
203 lines

Rust Crates

Sort By

Convenience functions that allow for sorting iterators.

Example

use sortby::*;

#[derive(Clone, Debug, Eq, PartialEq)]
struct Person {
  pub age: i32,
  pub name: &'static str,
}

fn main() {
  let data = vec![
    Person {
      name: "Rich",
      age: 18,
    },
    Person {
      name: "Bob",
      age: 9,
    },
    Person {
      name: "Marc",
      age: 21,
    },
    Person {
      name: "Alice",
      age: 18,
    },
  ];

  let sorted: Vec<_> = data.iter()
    .sort_by_desc(|p| p.age)
    .then_sort_by(|p| p.name)
    .collect();

   println!("{:#?}", sorted);
}

lib.rs:

This crate adds convenient sort functions for Iterators.

Example

use sortby::*;

#[derive(Clone, Debug, Eq, PartialEq)]
struct Person {
  pub age: i32,
  pub name: &'static str,
}

let data = vec![
  Person {
    name: "Rich",
    age: 18,
  },
  Person {
    name: "Bob",
    age: 9,
  },
  Person {
    name: "Marc",
    age: 21,
  },
  Person {
    name: "Alice",
    age: 18,
  },
];

let sorted: Vec<_> = data.iter()
  .sort_by_desc(|p| p.age)
  .then_sort_by(|p| p.name)
  .collect();

println!("{:#?}", sorted);

No runtime deps