Extracting First Element's ID with RA and Effect

guys is there way to do this ? i want to first element of array and then extract id property with effect features like RA
export const insertUltimateBeneficialOwner = (uboData: UBO, noticeId: number) =>
  Database.pipe(
    Effect.tryMapPromise({
      catch: (err: any) => new InsertUBOError({ msg: err.message }),
      try: ({ db, ubo }) =>
        db
          .insert(ubo)
          .values({ ...uboData, noticeId })
          .returning(),
    }),
    Effect.andThen(RA.get(0)),
    Effect.andThen(RA.getProperty("id"))
  );


instead of

Effect.andThen(arr => arr[0].id),


But i do this every time

    Effect.flatMap(RA.head),
    Effect.map((x) => x.id),
    Effect.orElseSucceed(() => null)
Was this page helpful?