Code Explainers

Code explainers tagged #deduplication

python
from collections import OrderedDict
from typing import Callable, Hashable, Iterable, Iterator, TypeVar
 
T = TypeVar("T")

Two ways to dedupe while keeping order

deduplication generators ordered-data
Intermediate 7 steps
ruby
class PaymentsController < ApplicationController
  before_action :require_idempotency_key
 
  def create

Idempotent payment creation in Rails

idempotency transactions race-conditions
Advanced 10 steps
go
package collection
 
func Deduplicate[T comparable](items []T) []T {
	seen := make(map[T]struct{}, len(items))

Generic deduplication in Go

generics deduplication maps
Intermediate 5 steps
java
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;

Three ways to deduplicate a list by key in Java

streams deduplication collectors
Intermediate 6 steps
python
def two_sum_sorted(numbers, target):
    """Find indices of two values that sum to target in a sorted array."""
    left, right = 0, len(numbers) - 1
    while left < right:

Two-pointer search on sorted arrays

two-pointers arrays sorting
Intermediate 9 steps