<commit_before>import { Option } from './Option';
import { MapFn } from '../shared/Function';

export function mapOrForOption<T, U>(src: Option<T>, def: U, selector: MapFn<T, U>): U {
    let r: U;
    if (src.ok) {
        r = selector(src.val);
    }
    else {
        r = def;
    }
    return r;
}
<commit_msg>Add comments for `mapOr` operator for PlainOption<commit_after>import { Option } from './Option';
import { MapFn } from '../shared/Function';

/**
 *  Return the result of _selector_ with using _src_ as an argument for it if _src_ is `Some(T)`.
 *  Otherwise, return _def_.
 *
 *  Basically, this operation is a combination `map()` and `unwrapOr()`.
 */
export function mapOrForOption<T, U>(src: Option<T>, def: U, selector: MapFn<T, U>): U {
    let r: U;
    if (src.ok) {
        r = selector(src.val);
    }
    else {
        r = def;
    }
    return r;
}

{'fraction_non_alphanumeric': 0.15507411630558723, 'fraction_numerical': 0.0, 'mean_word_length': 2.6736401673640167, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7215208', 'n_tokens_mistral': 305, 'n_tokens_neox': 302, 'n_words': 97}