slice-group-by

Fast Rust iterators that split slices and strings into contiguous groups

Library
Cargo
v0.3.1
54stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
25/100Needs Attention
Development Activity0
Maintenance0
Community28
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture72
Code Quality76
Innovation70
Learning Curve72

slice-group-by is a Rust library that provides group_by-style iterators for slices and string slices, inspired by Haskell’s groupBy. Given a comparison predicate, it yields contiguous subslices whose adjacent elements satisfy the predicate, so runs of equal or related items can be processed as groups.

Unlike iterator-adapter approaches, it operates directly on slice and str, which keeps data access local and fast. It ships multiple traversal strategies (linear, binary, and exponential search), supports mutable groups, iterating from the end, and works in no_std environments.

What You Get

  • group_by-style iterators over slice and str
  • Linear, binary, and exponential search strategies for different data shapes
  • Mutable grouping iterators for in-place processing
  • Reverse iteration to yield groups starting from the end
  • no_std support with an optional std feature

Common Use Cases

  • Splitting a sorted slice into runs of equal keys for aggregation
  • Grouping characters of a string into contiguous segments
  • Iterating groups from the end of a slice

Under The Hood

Architecture - The crate is organized by strategy: linear_group/, binary_group/, exponential_group/, and linear_str_group/ each implement a family of grouping iterators, tied together by extension traits (GroupBy, GroupByMut, and str equivalents) exported from lib.rs. Each iterator walks a slice or str and yields contiguous subslices determined by the user’s predicate, with mutable and reverse variants alongside the immutable ones.

Tech Stack - Written in Rust (edition 2018) with zero runtime dependencies; only rand is used as a dev-dependency for tests. It declares the algorithms crates.io category and gates the standard library behind a default std feature plus an optional nightly feature for extra optimizations.

Code Quality - Despite its small scope the crate is thoroughly structured, with separate modules per algorithm and a substantial test surface (the single language is Rust across ~100KB, much of it tests and doctests). It is stable and mature; development has been quiet since 2023 because the API is essentially complete.

API Design - The ergonomics mirror the standard library: call slice.linear_group_by(|a, b| ...) or the binary/exponential variants and iterate the resulting groups, exactly like slice::sort_by. Method names communicate both the operation and the search strategy, and the README documents each with runnable examples, so adoption is straightforward for anyone familiar with Rust iterators.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search