Comariang data
Hello,
I use typia and noticed that it would be great to have able to compare A and B
How it could be:
import typia from 'typia'
type User = {
name: string
age: number
address: {
room?: number
city: string
street: string
}
}
const ivan: User = {
name: 'ivan',
age: 19,
address: {
street: 'Ivanovskaya',
city: 'Berlin'
}
}
let cache: User | null = null
function heavyFunction(user: User) {
if (t.compare<User>(user, cache)) {
return 'cached'
}
// heavy operation
cache = user
return 'non-cached'
}
heavyFunction(ivan) // -> 'non-cached'
heavyFunction(ivan) // -> 'cached'
Compare unwraps in:
if (
user === cache || (
user.name === cache.name &&
user.age === cache.age &&
(user.address === cache.address ||
(user.address.room === cache.address.room && user.address.city === cache.address.city && user.address.street === cache.address.street)
)
)) {
return 'cached'
}
https://github.com/samchon/nestia/blob/master/packages/e2e/src/internal/json_equal_to.ts
Not okay with this function? Transformed comparator is really required?
Not okay with this function? Transformed comparator is really required?
Usually I use deepEquals / shallowEquals. But directly comparing should be faster I think
Maybe I didn't get what you mean, could you rephrase your message? Sorry I am not native english speaker 😅
Oops, missed link https://github.com/samchon/nestia/blob/master/packages/e2e/src/internal/json_equal_to.ts
I can design the new function interface what you want, but I am concentrating the AI chatbot feature development, so if you want that feature, you should challenge the implementation by yourself
Oops, missed link https://github.com/samchon/nestia/blob/master/packages/e2e/src/internal/json_equal_to.ts
I can design the new function interface what you want, but I am concentrating the AI chatbot feature development, so if you want that feature, you should challenge the implementation by yourself
I can't use the function because it's internal and it can throw exception I'll investigate how to add it, if you agree that it's good function for your library But I am not sure that I'll rich success 😅 but I can try
// src/compare.ts
export namespace compare {
export function covers<T>(x: T, y: T): boolean;
export function equals<T>(x: T, y: T): boolean;
export function less<T>(x: T, y: T): boolean;
}
// test.ts
typia.compare.covers(x, y);
I think this interface seems suitable for your feature.
// src/compare.ts export namespace compare { export function covers<T>(x: T, y: T): boolean; export function equals<T>(x: T, y: T): boolean; export function less<T>(x: T, y: T): boolean; }
// test.ts typia.compare.covers(x, y); I think this interface seems suitable for your feature.
could you explain how must work "covers" and "less" with objects / arrays?
I think let's start with equals. I've started and it's harder that I've thought :D
I faced with a lot of abstractions