Prefer Records of Functions to Interfaces
Matthew Doig

One of the reasons you should use interfaces is to not to disguise the fact that you are still doing object-oriented programming. How you have to use this record of functions feels exactly like you would use an OO object. The only thing you could gain over using a module is to partially apply something like a connection or connection string to the functions before making the record. At that point, record of functions is equivalent to using a standard OO object where the connection is a constructor parameter.

I recognized this because I have also made this mistake, and it brought me back to just doing OO in F#.

The FP alternative is to put these functions on modules. Then at the edge of the program, you can setup and partially apply resources like connections and pass those new functions to the workflows that use them. Send them as a tuple if you want to roll up more than one in a single parameter.

Like what you read? Give Kasey Speakman a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.