Guidance on Writing Effectful Functions with Effect Library

Hi, can anyone guide me with mental model of effect and how to write effectful function, for example, i am currently writing like this whenever possible since, normal code flow is understandable for me, its hard to get mind around pipes.

function execute(request: HttpClientRequest.HttpClientRequest) {
      return Effect.gen(function* () {
        const response = yield * client.execute(request)
        const extractedJson = yield * response.json

        const error = yield * Schema.decodeUnknown(ServerErrorResponseSchema)(extractedJson).pipe(Effect.either)
        if (Either.isRight(error)) {
          return yield * Effect.fail(error.right.toError())
        }

        const success = yield * Schema.decodeUnknown(ServerSuccessResponseSchema)(extractedJson).pipe(Effect.either)
        if (Either.isRight(success)) {
          return yield * Effect.succeed(success.right)
        }

        return yield * Effect.fail(new MalformedServerResponseError({ raw: extractedJson, message: 'Recieved server response that is neither an error nor a success. Server sent an unexpected response.' }))
      })
    }


is this proper way to write? of code can be more clear in another way?
Was this page helpful?