Hi, I’m going to ask something which, probably is guided by mi Object Oriented background and now that I’m trying to learn functional programming I’m just doing it wrong.
Suppose I have a function like:
submitLogin: String -> String -> String -> User
submitLogin apiUrl username password =
...
Now, I want to have several implementations of this function, so that in development, I replace this by a “stubbed” or “hardcoded” implementation which will always return a Test/Demo user, so that I don’t need to always have my backend running when not really developing a feature related to it. Let’s suppose this is not always HTTP, like it could be rendering a tag for Google Analytics, etc.
My noob approach was to do something like
submitLogin: Bool ->String -> String -> String -> User
submitLogin useStub apiUrl username password =
case useStub of
True ->
... -- Return hardcoded User
False ->
... -- Do the real thing
Is there any recommended pattern or better way to do this?
Thanks a lot for your help.