effect icon indicating copy to clipboard operation
effect copied to clipboard

Add combinators to shape up equality of the produced data value

Open parischap opened this issue 1 year ago • 1 comments

What is the problem this feature would solve?

Schema interoperates with effect/Data. The Schema.data(schema) combinator can be used to build a schema from an existing schema that can decode a value A to a value Data<A>. However, the equality operator of the produced Data<A> is not always appropiate. It often happens that we need the equality operator to bear only on a subgroup of A's properties. For instance:

export class Person extends Data.Class<{
	readonly id: string;
	readonly firstName: string;
	readonly lastName: string;
	readonly address: string;
}> {
	[Equal.symbol] = (that: Equal.Equal): boolean =>
		that instanceof Person
			? this.id=== that.id
			: false;
	[Hash.symbol] = (): number => Hash.hash(this.id);
}

What is the feature you are proposing to solve the problem?

Add a .notInEqual combinator:

const person= S.data(
  S.struct({
    id: S.string,
    firstName: pipe(S.string,S.notInEqual),
    lastName: pipe(S.string,S.notInEqual),
    address: pipe(S.string,S.notInEqual),
  })
);

What alternatives have you considered?

parischap avatar Dec 16 '23 09:12 parischap

could be an underlying feature of Data and an option to S.data()

mikearnaldi avatar Feb 03 '24 12:02 mikearnaldi