refactor: inherit default curl parser values (#2169)

This commit is contained in:
kyteinsky
2022-04-04 21:38:12 +05:30
committed by GitHub
parent dcbc3b6356
commit eea8a44746
16 changed files with 1354 additions and 977 deletions

View File

@@ -0,0 +1,19 @@
import * as O from "fp-ts/Option"
import * as A from "fp-ts/Array"
import { pipe } from "fp-ts/function"
/**
* Tries to match one of the given predicates.
* If a predicate is matched, the associated value is returned in a Some.
* Else if none of the predicates is matched, None is returned.
* @param choice An array of tuples having a predicate function and the selected value
* @returns A function which takes the input and returns an Option
*/
export const optionChoose =
<T, V>(choice: Array<[(x: T) => boolean, V]>) =>
(input: T): O.Option<V> =>
pipe(
choice,
A.findFirst(([pred]) => pred(input)),
O.map(([_, value]) => value)
)