RobTrew/prelude-jxa

Introducing equality for `Date` objects

unlocked2412 opened this issue · 3 comments

prelude-jxa/jsPrelude.js

Lines 1199 to 1218 in 3532094

const eq = a =>
// True when a and b are equivalent in the terms
// defined below for their shared data type.
b => {
const t = typeof a;
return t !== typeof b ? (
false
) : "object" !== t ? (
"function" !== t ? (
a === b
) : a.toString() === b.toString()
) : (() => {
const kvs = Object.entries(a);
return kvs.length !== Object.keys(b).length ? (
false
) : kvs.every(([k, v]) => eq(v)(b[k]));
})();
};

I think it would be a good idea to allow the comparison of Date objects. Along the lines of:

// eq (==) :: Eq a => a -> a -> Bool
const eq = a =>
    // True when a and b are equivalent in the terms
    // defined below for their shared data type.
    b => {
        const t = typeName(a);

        return t !== typeName(b) ? (
            false
        ) : "Dict" !== t ? (
            "Date" !== t ? (
                "function" !== t ? (
                    a === b
                ) : a.toString() === b.toString()
            ) : 0 === (a - b) // Date equality
        ) : (() => {
            const kvs = Object.entries(a);

            return kvs.length !== Object.keys(b).length ? (
                false
            ) : kvs.every(([k, v]) => eq(v)(b[k]));
        })();
    };

What do you think ?

I suppose the key issue the level of granularity at which equality would be defined.

An arbitrary parameterised level.

For equality at the level of days, I think the Prelude already contains eqDate, tut it sounds as if you are thinking about equalities at slightly finer levels too.

I am thinking at millisecond level. You're absolutely right about the issue, I think.

If two people were born on 01/01/1978 would be weird to say they weren't born the same day beacuse their birth dates are X milliseconds apart...I am closing the issue for now.