#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

#1966 in Algorithms

Download history 166/week @ 2024-07-20 323/week @ 2024-07-27 152/week @ 2024-08-03 299/week @ 2024-08-10 172/week @ 2024-08-17 351/week @ 2024-08-24 150/week @ 2024-08-31 184/week @ 2024-09-07 77/week @ 2024-09-14 141/week @ 2024-09-21 106/week @ 2024-09-28 114/week @ 2024-10-05 43/week @ 2024-10-12 328/week @ 2024-10-19 98/week @ 2024-10-26 82/week @ 2024-11-02

555 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