Title: Checking for "Admin" Role in an Array Using Effect and Matchers

What is the best way to loop over an array and see if "some" matchers returned true?

All I want to do is check if the user has "Admin" role.

 const permissionMatch = pipe(
      Match.type<Permission.Permission>(),
      Match.tag("Admin", () => Either.right(true)),
      Match.orElse(() =>
        Either.left(new InsufficentRoles({ requiredRoles: ["Admin"] })),
      ),
    );


Lets say I have an array:

const roles = ['Admin', 'User']

const hasPermission: Effect.Effect<boolean, InsufficentRoles, never> = pipe(
      Effect.all(roles.map(permissionMatch)),
      Effect.map((result) => result.some((v) => v === true)),
    );


Does this look right? Can it be improved?
Was this page helpful?