nunof07/smalltypes

View on GitHub
src/main/scalar/Equals.ts

Summary

Maintainability
A
1 hr
Test Coverage
import {
    Scalar,
    ScalarLike,
    ScalarOf
} from '@main';

/**
 * Compare values for equality.
 */
export class Equals<T> implements Scalar<boolean> {
    /**
     * Source value.
     */
    private readonly source: Scalar<T>;

    /**
     * Compared value.
     */
    private readonly compared: Scalar<T>;

    /**
     * Ctor.
     * @param source Value.
     * @param compared Compared.
     */
    constructor(source: ScalarLike<T>, compared: ScalarLike<T>) {
        this.source = new ScalarOf(source);
        this.compared = new ScalarOf(compared);
    }

    /**
     * Type determinant.
     */
    public isScalar(): true {
        return true;
    }

    /**
     * Gets the value.
     */
    public value(): boolean {
        return this.source.value() === this.compared.value();
    }
}