Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/common/internal.ts>Comp.anyShallowComp

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function Comp.anyShallowComp
import { Comp } from "https://deno.land/x/rimbu@0.13.0/common/internal.ts";
const { anyShallowComp } = Comp;

Returns a Comp instance that compares any value using default comparison functions. For Iterables and objects, their elements are compared only one level deep for performance and to avoid infinite recursion.

Examples

Example 1

const c = Comp.anyShallowComp();
console.log(c.compare({ a: 1, b: 1 }, { b: 1, a: 1 }))
// => 0
console.log(c.compare([{ a: 1, b: 1 }], [{ b: 1, a: 1 }]) < 0)
// => true
// First object is smaller because the objects are converted to a string and then compares the resulting string.