From 8917f8495241ec2c6c8606c90cd75796fdf7c646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 22 Apr 2025 22:59:50 +0200 Subject: [PATCH] SearchPaths work --- packages/reffuse/src/types/SearchPaths.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/reffuse/src/types/SearchPaths.ts b/packages/reffuse/src/types/SearchPaths.ts index e23d672..e3e8bf3 100644 --- a/packages/reffuse/src/types/SearchPaths.ts +++ b/packages/reffuse/src/types/SearchPaths.ts @@ -29,6 +29,10 @@ const persons = [ ] +export const unsafeGet = >(parent: T, path: P): ValueFromPath => ( + path.reduce((acc: any, key: any) => acc?.[key], parent) +) + export const get = >(parent: T, path: P): Option.Option> => path.reduce( (acc: Option.Option, key: any): Option.Option => Option.isSome(acc) ? Predicate.hasProperty(acc.value, key) @@ -39,9 +43,18 @@ export const get = >(parent: T, path: P): Option.Opt Option.some(parent), ) -export const getOrUndefined = >(parent: T, path: P): ValueFromPath => ( - path.reduce((acc: any, key: any) => acc?.[key], parent) + +export const unsafeImmutableSet = >(parent: T, path: P): Option.Option> => path.reduce( + (acc: Option.Option, key: any): Option.Option => Option.isSome(acc) + ? Predicate.hasProperty(acc.value, key) + ? Option.some(acc.value[key]) + : Option.none() + : acc, + + Option.some(parent), ) + const res = get(persons, [1, "name"]) + console.log(res)