#sorting #iterator #data-structures

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

#2217 in Algorithms

Download history 184/week @ 2024-11-15 166/week @ 2024-11-22 136/week @ 2024-11-29 132/week @ 2024-12-06 64/week @ 2024-12-13 18/week @ 2024-12-20 43/week @ 2024-12-27 69/week @ 2025-01-03 85/week @ 2025-01-10 92/week @ 2025-01-17 79/week @ 2025-01-24 40/week @ 2025-01-31 70/week @ 2025-02-07 189/week @ 2025-02-14 233/week @ 2025-02-21 188/week @ 2025-02-28

680 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