SearchPaths work
All checks were successful
Lint / lint (push) Successful in 14s

This commit is contained in:
Julien Valverdé
2025-04-23 06:47:11 +02:00
parent 1163b83929
commit 6156baec4d

View File

@@ -52,11 +52,20 @@ export const immutableSet = <T, const P extends Paths<T>>(
return Option.none() return Option.none()
const child = immutableSet<any, any>(parent[key.value], Option.getOrThrow(Array.tail(path as Path)), value) const child = immutableSet<any, any>(parent[key.value], Option.getOrThrow(Array.tail(path as Path)), value)
if (Option.isNone(child))
return child
if (Array.isArray(parent) && typeof key === "number") { if (Array.isArray(parent) && typeof key === "number")
return Option.some([
...parent.slice(0, key),
child.value,
...parent.slice(key + 1),
] as T)
return Option.some([]) if (typeof parent === "object")
} return Option.some({ ...parent, [key.value]: child.value })
return Option.none()
} }
@@ -65,6 +74,11 @@ const persons = [
{ name: "El Chanclador" }, { name: "El Chanclador" },
{ name: "AAAYAYAYAYAAY" }, { name: "AAAYAYAYAYAAY" },
] ]
console.log(persons)
const res = get(persons, [1, "name"]) const res = get(persons, [1, "name"])
console.log(res) console.log(res)
const persons2 = Option.getOrThrow(immutableSet(persons, [1, "name"], "El Risitas"))
console.log(Array.isArray(persons2))
console.log(get(persons2, [1, "name"]))