main
1// Absence as a value. `{ tag: "some", value }` or `{ tag: "none" }`.
2//
3// ply does not export this type at the pinned commit (package.json) or at ply main
4// on 2026-11-01. This module is the local copy of that shape. When a pin does export
5// it, re-export ply's module from this file and delete the local definitions.
6// Callers keep importing `src/option.ts` either way.
7//
8// The platform's absent value is not a member of this type. Convert at `src/absent.ts`.
10export type Some<T> = { readonly tag: "some"; readonly value: T };
12export type None = { readonly tag: "none" };
14export type Option<T> = Some<T> | None;
16const NONE: None = Object.freeze({ tag: "none" });
18export function some<T>(value: T): Some<T> {
19 return Object.freeze({ tag: "some", value });
20}
22export function none<T = never>(): Option<T> {
23 return NONE;
24}
26export function isSome<T>(option: Option<T>): option is Some<T> {
27 return option.tag === "some";
28}
30export function isNone<T>(option: Option<T>): option is None {
31 return option.tag === "none";
32}
34export function map<T, U>(option: Option<T>, fn: (value: T) => U): Option<U> {
35 if (option.tag === "none") return none();
36 return some(fn(option.value));
37}
39export function flatMap<T, U>(option: Option<T>, fn: (value: T) => Option<U>): Option<U> {
40 if (option.tag === "none") return none();
41 return fn(option.value);
42}
44export function filter<T>(option: Option<T>, keep: (value: T) => boolean): Option<T> {
45 if (option.tag === "none") return none();
46 if (!keep(option.value)) return none();
47 return option;
48}
50export function unwrapOr<T>(option: Option<T>, fallback: T): T {
51 if (option.tag === "none") return fallback;
52 return option.value;
53}
55export function orElse<T>(first: Option<T>, second: Option<T>): Option<T> {
56 if (first.tag === "some") return first;
57 return second;
58}
60/** JSON and other hosts that use null for absence. A present value is returned as itself. */
61export function orNull<T>(option: Option<T>): T | null {
62 if (option.tag === "none") return null;
63 return option.value;
64}
66export function match<T, U>(option: Option<T>, onSome: (value: T) => U, onNone: () => U): U {
67 if (option.tag === "some") return onSome(option.value);
68 if (option.tag === "none") return onNone();
69 return absurd(option);
70}
72/** First element for which `keep` holds. A finished scan is none; the host's find is not used. */
73export function find<T>(items: readonly T[], keep: (item: T) => boolean): Option<T> {
74 for (const item of items) {
75 if (keep(item)) return some(item);
76 }
77 return none();
78}
80function absurd(value: never): never {
81 throw new Error(`unhandled option: ${JSON.stringify(value)}`);
82}
Diagnostics4 git calls · 24 ms
CallStatusSizeTime024 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=41349 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch200975 B · hit18 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=18 git.response.bytes=975 git.response.cache=HIT git.response.duration_ms=18 git.fetch.wants=061f2b8cde6b17e6045b1e83edc95f7c753c57a6 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=975 git.pkt.payload.max=954 git.sideband.band1.bytes=953 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e2e505fd832947
- Request
- 663fbd37…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format