UNPKG

option-t

Version:

A toolkit of Nullable/Option/Result type implementation in ECMAScript. Their APIs are inspired by Rust's `Option<T>` and `Result<T, E>`.

23 lines (22 loc) 725 B
import { isNotSameOkField, isSameErrField, isSameValField, } from '../internal/intrinsics_compare.js'; /** * Return `true`: * 1. if `lhs === rhs`. * 2. if _lhs_ and _rhs_ is same kind, and they contain same value. * * Otherwise, return `false`. * * This function is designed for `Result<T, E>`. * This function may return `true` if input values has same properties with `Result<T, E>` * and their properties are same between _lhs_ and _rhs_. */ export function equalForResult(lhs, rhs) { if (lhs === rhs) { return true; } if (isNotSameOkField(lhs, rhs)) { return false; } const isEqual = isSameValField(lhs, rhs) && isSameErrField(lhs, rhs); return isEqual; }