#iterator #sorting #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

#1983 in Algorithms

Download history 373/week @ 2024-06-16 91/week @ 2024-06-23 231/week @ 2024-06-30 106/week @ 2024-07-07 197/week @ 2024-07-14 165/week @ 2024-07-21 323/week @ 2024-07-28 161/week @ 2024-08-04 290/week @ 2024-08-11 172/week @ 2024-08-18 360/week @ 2024-08-25 145/week @ 2024-09-01 180/week @ 2024-09-08 77/week @ 2024-09-15 141/week @ 2024-09-22 155/week @ 2024-09-29

557 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