Effect CommunityEC
Effect Community3y ago
4 replies
Nickel

Choosing between `Option` and `Effect` for code involving `X`

I'm dealing with Option. But, I don't know which is the best practice for the following code i.e., Option or Effect?

export const findIndex = (self: X): O.Option<number> =>
    ROA.findFirstIndex(Xs, Equal.equals(self));

export const isFormY = (
    a: X,
    b: X,
    c: X,
): O.Option<boolean> => {
    const modularQuotient = (n: number) => Math.floor(mod(n + 1, 12) / 3);
    return O.Do().pipe(
        O.bind('indexA', () => findIndex(a)),
        O.bind('indexB', () => findIndex(b)),
        O.bind('indexC', () => findIndex(c)),
        O.map(
            ({ indexA, indexB, indexC }) =>
                modularQuotient(indexA) === modularQuotient(indexB) &&
                modularQuotient(indexB) === modularQuotient(indexC),
        ),
    );
};


Effect is a computation and Option is a value... Maybe, using Option for these kind of functions and use Effect on the endpoint of these functions is the best practice.

It looks like fp-ts though lol
Was this page helpful?