pragmatic-fp-ts
Version:
Opinionated functional programming library with easy use in mind
16 lines (11 loc) • 450 B
text/typescript
import { equals, getValueOr } from "./main.ts";
export function indexOf<A>(value: A, coll: A[]): number;
export function indexOf<A>(value: A): (coll: A[]) => number;
export function indexOf<A>(value: A, coll?: A[]) {
if (arguments.length === 1) return (theColl: A[]) => indexOf(value, theColl);
const theColl = getValueOr([], coll);
for (let i = 0; i < theColl.length; ++i) {
if (equals(value, theColl[i])) return i;
}
return -1;
}