You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think we can define a version of buildListForResponse that takes ForResponseLog a such that a is coercible to [x]. Maybe we don't even need a separate function for that and can generalize buildListForResponse because [x] is coercible to [x]. Or maybe we can generalize it somehow differently so support other data types such as Vector. Or maybe this case is not so frequent and we don't to generalize anything 🤷
The text was updated successfully, but these errors were encountered:
How do you think, which Buildable constraint buildListForResponse should rely on? On Buildable for the newtype or Buildable for the inner list?
In the latter case (AFAIU this is what your snippet implements) probably the best way would be to add Functor for ForResponseLog and then write buildListForResponse (take 5) . fmap unFileSummary. It provides a fair balance between avoiding boilerplate vs being explicit and introduces no new entities.
In the former case, I suppose we would need some different function, the formatting added by buildListForResponse goes away here.
For Vector, it's interesting 🤔
I suspect that the solution with Coercible won't work without forcing the user to specify some types manually (though would be glad to be proved wrong).
If so, generalizing buildListForResponse to IsList seems like a pretty fair option to me. Should work for [] and Vector without boilerplate, and provides a simplification for FileSummary case above.
The only issue with IsList is that conversion to the intermediate list may be expensive, comparing to Vector.take which takes O(1). Probably really leaving Vector until a use case for it arises is the best.
Sometimes response type to an endpoint is a list wrapped into
newtype
. If you want to usebuildListForResponse
you need to write something like this:I think we can define a version of
buildListForResponse
that takesForResponseLog a
such thata
is coercible to[x]
. Maybe we don't even need a separate function for that and can generalizebuildListForResponse
because[x]
is coercible to[x]
. Or maybe we can generalize it somehow differently so support other data types such asVector
. Or maybe this case is not so frequent and we don't to generalize anything 🤷The text was updated successfully, but these errors were encountered: