// Generated by bynkc — do not edit by hand.
// commons report

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "./runtime.js";

export interface Item {
  readonly id: number;
  readonly name: string;
}

export const Item = {
};

export function sortedNames(items: readonly Item[]): readonly Item[] {
  return [...items].sort((__a: Item, __b: Item) => { const __ka = ((i) => i.name)(__a), __kb = ((i) => i.name)(__b); return __ka < __kb ? -1 : __ka > __kb ? 1 : 0; });
}

export function uniqueIds(items: readonly Item[]): readonly Item[] {
  return ((__xs: readonly Item[]) => { const __seen = new Set(); const __out: Item[] = []; for (const __x of __xs) { const __k = ((i) => i.id)(__x); if (!__seen.has(__k)) { __seen.add(__k); __out.push(__x); } } return __out; })(items);
}

export function uniqueInts(xs: readonly number[]): readonly number[] {
  return [...new Set(xs)];
}

export function ascending(xs: readonly number[]): readonly number[] {
  return [...xs].sort((__a: number, __b: number) => { const __ka = ((x) => x)(__a), __kb = ((x) => x)(__b); return __ka < __kb ? -1 : __ka > __kb ? 1 : 0; });
}

export function totalId(items: readonly Item[]): number {
  return (items).reduce((__s: number, __x: Item) => __s + ((i) => i.id)(__x), 0);
}

export function smallestId(items: readonly Item[]): Option<number> {
  return ((__xs: readonly Item[]) => { if (__xs.length === 0) return None; let __m = ((i) => i.id)(__xs[0]); for (const __x of __xs) { const __k = ((i) => i.id)(__x); if (__k < __m) __m = __k; } return Some(__m); })(items);
}

export function largestId(items: readonly Item[]): Option<number> {
  return ((__xs: readonly Item[]) => { if (__xs.length === 0) return None; let __m = ((i) => i.id)(__xs[0]); for (const __x of __xs) { const __k = ((i) => i.id)(__x); if (__k > __m) __m = __k; } return Some(__m); })(items);
}

export function meanId(items: readonly Item[]): Option<number> {
  return ((__xs: readonly Item[]) => { if (__xs.length === 0) return None; let __s = 0; for (const __x of __xs) __s += ((i) => i.id)(__x); return Some(__s / __xs.length); })(items);
}

export function meanDuration(ds: readonly number[]): Option<number> {
  return ((__xs: readonly number[]) => { if (__xs.length === 0) return None; let __s = 0; for (const __x of __xs) __s += ((d) => d)(__x); return Some(Math.round(__s / __xs.length)); })(ds);
}

