import type { Comparator , Fn0 } from "@thi.ng/api" ; import { compare } from "@thi.ng/compare/compare" ; import type { Reducer } from "./api.js" ; import { $$reduce , reducer } from "./reduce.js" ; export function minCompare < T > ( init , cmp ? ) ; export function minCompare < T > ( init , xs ) ; export function minCompare < T > ( init , cmp , xs ) ; export function minCompare ( ... args ) { const res = $$reduce ( minCompare , args ) ; if ( res !== undefined ) { return res ; } const init = args [ 0 ] ; const cmp = args [ 1 ] || compare ; return reducer ( init , ( acc , x ) => ( cmp ( acc , x ) <= 0 ? acc : x ) ) ; }