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>`.

20 lines (19 loc) 411 B
import { isSome, createNone } from './option.js'; /** * Return one of this pattern: * * 1. a=Some, b=None => _a_ * 2. a=None, b=Some => _b_ * 3. Others => `None` */ export function xorForOption(a, b) { const aIsSome = isSome(a); const bIsSome = isSome(b); if (aIsSome && !bIsSome) { return a; } if (!aIsSome && bIsSome) { return b; } return createNone(); }