nunof07/smalltypes

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

Summary

Maintainability
A
0 mins
Test Coverage
import {
    Conditions,
    Scalar,
    ScalarLike
} from '@main';

/**
 * Logical disjunction operator.
 */
export class Or implements Scalar<boolean> {
    /**
     * Conditions.
     */
    private readonly conditions: Iterable<boolean>;

    /**
     * Ctor.
     * @param conditions Conditions.
     */
    constructor(...conditions: ScalarLike<boolean>[]) {
        this.conditions = new Conditions(conditions);
    }

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

    /**
     * Get the value.
     */
    public value(): boolean {
        for (const condition of this.conditions) {
            if (condition) {
                return true;
            }
        }

        return false;
    }
}