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
instead of
But i do this every time
instead of
But i do this every time
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"))
);Effect.andThen(arr => arr[0].id), Effect.flatMap(RA.head),
Effect.map((x) => x.id),
Effect.orElseSucceed(() => null)