upsetjs export function byName < T extends { name : string ; } > ( a , b ) { return a . name . localeCompare ( b . name ) ; } export function byCardinality < T extends { cardinality : number ; } > ( a , b ) { return b . cardinality - a . cardinality ; } export function byDegree < T extends { degree : number ; } > ( a , b ) { return a . degree - b . degree ; } export function byComposite < T > ( func ) { return ( a , b ) => { return func . reduce ( ( acc , f ) => ( acc === 0 ? f ( a , b ) : acc ) , 0 ) ; } ; } export function negate < T > ( func ) { return ( a , b ) => - func ( a , b ) ; } export function byGroup < E , S extends { sets : ReadonlySet < E > ; } > ( sets ) { return ( a , b ) => { const fixNotFound = ( v ) => ( v < 0 ? Number . POSITIVE_INFINITY : v ) ; const aIndex = fixNotFound ( sets . findIndex ( ( s ) => a . sets . has ( s ) ) ) ; const bIndex = fixNotFound ( sets . findIndex ( ( s ) => b . sets . has ( s ) ) ) ; return aIndex - bIndex ; } ; }