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)