I noticed that Http.send[F,A,Msg] is declared as returning Cmd[F, Msg] while effectively returning an instance of Cmd.Run[F, Msg, Msg].
This signature prevents from calling the toTask helper method defined for Cmd.Run, a thing that could enable funnier paradigms like being able to flatten a structure like F[Cmd.Run[F, _, _]] to either F[_] or Cmd[F,_,_] by simply combining in the right way Cmd.Run.apply and .toTask.
The solution is incredibly simple: redeclaring .send return as Cmd.Run[F, Msg, Msg]here: it doesn't break the test nor the compilation wherever it is already used as we're simply narrowing the return type of a function (that btw is covariant in the return type). [EDIT] @Daenyth made me notice that this modification is binary compatible too, so there's no need to wait for an API breaking change.
One confirmation might come from the fact that casting the Http.send result to Cmd.Run works flawlessly
def copyAndSend: IO[ResponseContent]] = for
text <- copyTextFromTextArea
resp <- save(text).asInstanceOf[Cmd.Run[IO, ResponseContent, ResponseContent]].toTask //YOLO
yield ResponseContent(resp)
Important things first: thank you for this awesome library. It's a pleasure to use, and it's so well designed that it's usage is immensely intuitive.
<pun>
At the moment is the best thing that ever happened to me to pursue my life goal of not learning Javascript at all.</pun>
That said, I noted a little design flaw that is incredibly easy to fix IMHO.
While trying to copy the text of a textArea to send it to the backend of my application more or less in this way:
I noticed that
Http.send[F,A,Msg]
is declared as returningCmd[F, Msg]
while effectively returning an instance ofCmd.Run[F, Msg, Msg]
.This signature prevents from calling the
toTask
helper method defined forCmd.Run
, a thing that could enable funnier paradigms like being able to flatten a structure likeF[Cmd.Run[F, _, _]]
to eitherF[_]
orCmd[F,_,_]
by simply combining in the right wayCmd.Run.apply
and.toTask
.The solution is incredibly simple: redeclaring
.send
return asCmd.Run[F, Msg, Msg]
here: it doesn't break the test nor the compilation wherever it is already used as we're simply narrowing the return type of a function (that btw is covariant in the return type). [EDIT] @Daenyth made me notice that this modification is binary compatible too, so there's no need to wait for an API breaking change.One confirmation might come from the fact that casting the
Http.send
result toCmd.Run
works flawlesslyIf you like this solution I can open a PR asap.
Thanks again!