Effect CommunityEC
Effect Community3y ago
13 replies
bigpopakap

The Purpose of `Schema.identifier()`

Another question: what exactly is the point of Schema.identifier()? Is it to be able to trace an individual value through a bunch of transformations?

For example, I have this:
export const CardSchema = pipe(
    // Validate the input
    S.tuple(
        pipe(
            // Validate the input
            S.string,
            S.nonEmpty({ message: () => 'Should be non-empty"' }),
            S.identifier('first'),
        ),

        pipe(
            // Validate the input
            S.string,
            S.nonEmpty({ message: () => 'Should be non-empty"' }),
            S.identifier('second'),
        ),
    ),

    // Transform to an object
    S.transform(
        S.struct({
            first: pipe(S.string, S.identifier('first')),
            second: pipe(S.string, S.identifier('second')),
        }),

        ([first, second]) => ({ first, second }),
        ({ first, second }) => TU.tuple(first, second),
    ),
);
Was this page helpful?