SegmentCodec

zio.blocks.endpoint.SegmentCodec
See theSegmentCodec companion object
sealed trait SegmentCodec[A]

Typed descriptor for a single URL path segment. Subtypes include Literal, Int, String, Combined (intra-segment composition via ~), and Trailing (captures remaining path).

Combine representation first, then transform: ~ composes only physical SegmentCodec structure, while transform / transformOrFail lift the segment into a PathCodec (making ~ unavailable afterwards — a transformed wire codec is a domain value, not intra-segment structure).

Attributes

Companion
object
Source
SegmentCodec.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class BoolSeg[N]
class Combined[A, B, C]
object Empty
class IntSeg[N]
class Literal
class LongSeg[N]
class StringSeg[N]
object Trailing
class UUIDSeg[N]
Show all
Self type

Members list

Type members

Types

type PathVars

Phantom capture marker: SegmentCodec.NoPathVars when this segment captures nothing (empty and literal segments), SegmentCodec.HasPathVars when it captures a value (bool, int, long, string, UUID, trailing, and any composition containing one of those). This is a second, parallel type track: it never affects A (the runtime-decoded value type) and has zero runtime footprint. Its only consumer is PathCodec.orElse, which requires both branches to be NoPathVars so a capturing codec mapped to Unit is rejected at the call site instead of failing expand at runtime.

Phantom capture marker: SegmentCodec.NoPathVars when this segment captures nothing (empty and literal segments), SegmentCodec.HasPathVars when it captures a value (bool, int, long, string, UUID, trailing, and any composition containing one of those). This is a second, parallel type track: it never affects A (the runtime-decoded value type) and has zero runtime footprint. Its only consumer is PathCodec.orElse, which requires both branches to be NoPathVars so a capturing codec mapped to Unit is rejected at the call site instead of failing expand at runtime.

Attributes

Source
SegmentCodec.scala

Value members

Abstract methods

def doc: Doc

Attributes

Source
SegmentCodec.scala
def examples: Chunk[(String, A)]

Attributes

Source
SegmentCodec.scala

Concrete methods

final def format(value: A): Path

Attributes

Source
SegmentCodec.scala
final def render(prefix: String = ..., suffix: String = ...): String

Attributes

Source
SegmentCodec.scala
final def transform[B, PV](decode: A => B, encode: B => A)(implicit ev: CombinePathVars[PathVars, NoPathVars, PV]): PathCodec[B] { type PathVars = PV; }

Maps the decoded segment value into a domain type, lifting into a PathCodec.

Maps the decoded segment value into a domain type, lifting into a PathCodec.

Example: SegmentCodec.string("id").transform(CustomerId(_), _.value)

Value parameters

decode

maps the decoded segment value into the exposed type

encode

maps the exposed type back into the original segment representation used by format

Attributes

Returns

a path codec with the transformed value type and the same route shape as self

Source
SegmentCodec.scala
final def transformOrFail[B, PV](decode: A => Either[String, B], encode: B => Either[String, A])(implicit ev: CombinePathVars[PathVars, NoPathVars, PV]): PathCodec[B] { type PathVars = PV; }

Effectfully maps the decoded segment value into a domain type, lifting into a PathCodec. decode returning Left causes path decoding / matching to fail; encode returning Left is propagated as the Left result of format.

Effectfully maps the decoded segment value into a domain type, lifting into a PathCodec. decode returning Left causes path decoding / matching to fail; encode returning Left is propagated as the Left result of format.

Example: SegmentCodec.string("id").transformOrFail(CustomerId.parse, id => Right(id.value))

Attributes

Source
SegmentCodec.scala
final def ~[B, C, PV2, PVC](that: SegmentCodec[B] { type PathVars = PV2; })(implicit combiner: WithOut[A, B, C], pathVarsCombiner: CombinePathVars[PathVars, PV2, PVC]): SegmentCodec[C] { type PathVars = PVC; }

Composes two physical segments into one (for example int("n") ~ literal("-") ~ string("rest")).

Composes two physical segments into one (for example int("n") ~ literal("-") ~ string("rest")).

Adjacent string ~ string, numeric ~ numeric (Int/Long in any order, including through a flattened combined tail), and anything involving Trailing are rejected at runtime with IllegalArgumentException (ambiguous splits); put a literal, bool, or UUID segment between them.

The result's PathVars is the logical OR of both sides (computed by the pathVarsCombiner implicit, which defaults conservatively to HasPathVars when either side's marker is unknown), so orElse keeps rejecting compositions that capture.

Attributes

Source
SegmentCodec.scala
final def ~[C, PVC](that: String)(implicit combiner: WithOut[A, Unit, C], pathVarsCombiner: CombinePathVars[PathVars, NoPathVars, PVC]): SegmentCodec[C] { type PathVars = PVC; }

Composes a physical segment with a literal suffix (for example string("word") ~ "!"). The literal is validated exactly like SegmentCodec.literal (empty, /-carrying, or encoding-requiring values are rejected with IllegalArgumentException).

Composes a physical segment with a literal suffix (for example string("word") ~ "!"). The literal is validated exactly like SegmentCodec.literal (empty, /-carrying, or encoding-requiring values are rejected with IllegalArgumentException).

Attributes

Source
SegmentCodec.scala