Code Explainers
Code explainers tagged #grouping
java
public class DuplicateFinder { public Map<String, List<Path>> findDuplicates(Path root) throws IOException { Map<String, List<Path>> byHash = new HashMap<>();
Finding duplicate files by content hash
hashing
file-io
streams
Intermediate
8 steps
java
import java.util.Comparator; import java.util.LinkedHashMap; import java.util.Map; import java.util.regex.Pattern;
Ranking the most frequent words in Java
streams
regex
grouping
Intermediate
7 steps
ruby
class DigestMailer < ApplicationMailer default from: "notifications@example.com" def weekly_digest(user)
Building a weekly digest email in Rails
mailers
active-record
query-scopes
Intermediate
6 steps
rust
use std::collections::HashMap; #[derive(Debug, Clone)] struct Row {
Building a tree from flat parent-id rows in Rust
recursion
hashmap
tree-building
Intermediate
6 steps
go
package api func RegisterRoutes(r *gin.Engine, deps *Dependencies) { r.GET("/health", func(c *gin.Context) {
Layering route groups and middleware in Gin
routing
middleware
authentication
Intermediate
8 steps
php
<?php function buildTree(array $items, ?int $parentId = null): array {
Building a tree from a flat list in PHP
recursion
tree
grouping
Intermediate
6 steps
java
public Map<Long, List<Order>> ordersByCustomer(List<Order> orders) { return orders.stream() .collect(Collectors.groupingBy(Order::getCustomerId)); }
Grouping streams with Java Collectors
streams
grouping
collectors
Intermediate
5 steps
java
package com.example.logs; import java.io.IOException; import java.io.UncheckedIOException;
Counting HTTP statuses with Java streams
streams
regex
file-io
Intermediate
6 steps
typescript
interface Order { id: number; customerId: string; total: number;
A type-safe groupBy in TypeScript
generics
reduce
type-inference
Intermediate
6 steps
javascript
function groupBy(items, keySelector) { const resolveKey = typeof keySelector === 'function' ? keySelector : (item) => item[keySelector];
Building a flexible groupBy in JavaScript
higher-order-functions
reduce
data-transformation
Intermediate
6 steps
php
<?php namespace App\Support;
Grouping records with array_reduce in PHP
array-reduce
grouping
higher-order-functions
Intermediate
6 steps