Running Queries on Functors

The goal is to have a function that takes a QueryRunner and returns a result of an arbitrary type T. However, to ensure that the QueryRunner is in the proper state when the function is called, we’ll execute it as a functional effect in a secure way. To achieve this, we’ll create a functor named ProjectionQuery that wraps a function of type (QueryRunner) -> T.

Using a functor offers several advantages. Firstly, it gives us control over when the query is executed. We only want to run the query when it’s correct, and at a minimum, we need to ensure that the projections are up-to-date. In the future, there may be additional checks that need to be performed. Functors allow us to separate the technical infrastructure concerns ...

Get From Objects to Functions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.