| 1033 | ) |
| 1034 | ) |
| 1035 | ) |
| 1036 | } |
| 1037 | at(key: PropertyKey, ..._rest: Array<any>): any { |
| 1038 | const err = Result.fail( |
| 1039 | new SchemaIssue.Pointer([key], new SchemaIssue.MissingKey(undefined)) |
| 1040 | ) |
| 1041 | return make( |
| 1042 | compose( |
| 1043 | this.node, |
| 1044 | primitiveNode( |
| 1045 | "Optional", |
| 1046 | (s) => Object.hasOwn(s, key) ? Result.succeed(s[key]) : err, |
| 1047 | (a, s) => { |
| 1048 | if (Object.hasOwn(s, key)) { |
| 1049 | const copy = cloneShallow(s) |
| 1050 | InternalRecord.assignProperty(copy, key, a) |
| 1051 | return Result.succeed(copy) |
| 1052 | } else { |
| 1053 | return err |
| 1054 | } |
| 1055 | } |
| 1056 | ) |
| 1057 | ) |
| 1058 | ) |
| 1059 | } |
| 1060 | pick(keys: any) { |
| 1061 | return this.compose(makeLens(Struct.pick(keys), (p, a) => ({ ...a, ...p }))) |
| 1062 | } |
| 1063 | omit(keys: any) { |
| 1064 | return this.compose(makeLens(Struct.omit(keys), (o, a) => ({ ...a, ...o }))) |
| 1065 | } |
| 1066 | notUndefined(): any { |
| 1067 | return this.refine(Predicate.isNotUndefined, { expected: "a value other than `undefined`" }) |
| 1068 | } |
| 1069 | forEach<S, A, B>(this: Traversal<S, A>, f: (iso: Iso<A, A>) => Optional<A, B>): Traversal<S, B> { |
| 1070 | const inner = f(id<A>()) |
| 1071 | return makeOptional<S, ReadonlyArray<B>>( |
| 1072 | // GET: collect focused Bs |
| 1073 | (s) => |
| 1074 | Result.map(this.getResult(s), (as) => { |
| 1075 | const bs: Array<B> = [] |
| 1076 | for (let i = 0; i < as.length; i++) { |
| 1077 | const r = inner.getResult(as[i]) |
| 1078 | if (Result.isSuccess(r)) bs.push(r.success) |
| 1079 | } |
| 1080 | return bs |
| 1081 | }), |
| 1082 | // SET: bs must match the number of focusable elements |
| 1083 | (bs, s) => |
| 1084 | Result.flatMap(this.getResult(s), (as) => { |
| 1085 | // 1) collect focusable indices |
| 1086 | const idxs: Array<number> = [] |
| 1087 | for (let i = 0; i < as.length; i++) { |
| 1088 | if (Result.isSuccess(inner.getResult(as[i]))) idxs.push(i) |
| 1089 | } |
| 1090 | |
| 1091 | // 2) arity check |
| 1092 | if (bs.length !== idxs.length) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…