Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

Text · 14 lines · 442 B · at 46fbf38

import { Some, None, type Option } from "@tsus/runtime";const findFirst = (xs: number[], pred: (x: number) => boolean): Option<number> => {  for (const x of xs) {    if (pred(x)) {      return Some(x);    }  }  return None;};console.log(findFirst([1, 2, 3], (x) => x > 1).unwrapOr(-1));console.log(findFirst([1, 2, 3], (x) => x > 9).unwrapOr(-1));console.log(findFirst([1, 2, 3], (x) => x === 2).map((x) => x * 10).unwrapOr(0));