Code Explainers
Code explainers tagged #composition
ruby
class Pipeline def initialize @middlewares = [] end
Building a middleware pipeline in Ruby
closures
middleware
composition
Advanced
8 steps
rust
use axum::{ body::Body, http::{Method, StatusCode, Uri}, response::{IntoResponse, Response},
Nesting routers and JSON fallbacks in Axum
routing
http
json-responses
Intermediate
7 steps
php
namespace App\Http\Filters; use Closure; use Illuminate\Database\Eloquent\Builder;
Composable query filters with Laravel's Pipeline
pipeline
query-builder
single-responsibility
Intermediate
7 steps
typescript
function* map<T, U>(source: Iterable<T>, fn: (value: T, index: number) => U): Generator<U> { let index = 0; for (const value of source) { yield fn(value, index++);
Building a lazy iterator pipeline in TypeScript
generators
lazy-evaluation
iterators
Intermediate
7 steps
ruby
require "forwardable" class ShoppingCart extend Forwardable
Delegation in Ruby with Forwardable
delegation
composition
enumerable
Intermediate
9 steps
ruby
class WeightedSampler def initialize(weights) @entries = weights.to_a @total = @entries.sum { |_, w| w }
Weighted random sampling with binary search
weighted-sampling
binary-search
cumulative-sum
Intermediate
7 steps
php
<?php namespace App\Http;
Building an onion middleware pipeline in PHP
middleware
closures
array-reduce
Advanced
9 steps
go
package main import ( "net/http"
How route groups nest in Gin
routing
middleware
api versioning
Intermediate
6 steps
go
package geometry import "fmt"
Implementing fmt.Stringer in Go
interfaces
stringer
composition
Beginner
5 steps