I'm writing up some CRUD helpers for fun and profit, and I'm finding myself needing an empty or noop route. The mempty
to :>
, if you will.
This is what I'd like to write:
type Index model =
Reassoc (QueryParams model :> Get '[JSON] (Collection model))
type family Reassoc xs where
Reassoc ((x :> y) :> z) = Reassoc (x :> Reassoc (y :> z))
Reassoc (x :> y) = x :> y
type family QueryParams model
type instance QueryParams User =
MakeQueryParams '[ '("organizationId", Int) ]
That all of course builds up to this guy:
type family MakeQueryParams xs where
MakeQueryParams ( '(sym, ty) ': xs )
= QueryParam sym ty :> MakeQueryParams xs
MakeQueryParams '[]
= ... :(
Is there an empty route combinator?
I've worked around this thus far by using a next
parameter in those families, but it's a lot less idiomatic for Servant.
type family MakeQueryParams xs next where
MakeQueryParams '[] next =
next
MakeQueryParams ('(sym, ty) ': xs) next =
QueryParam sym ty :> MakeQueryParams xs next
type Index model = QueryParams model (Get '[JSON] (Collection model))
type family QueryParams model next
type instance QueryParams User next =
MakeQueryParams '[ '("organizationId", Int) ] next
next
is great and perfectly idiomatic (or at least much more than your other attempt). You don't needReassoc
. I'd also argue that something like(QueryParam ... :> QueryParam ...) :> Get ...
shouldn't even be kind-correct. The fact that it currently is is an accident / compromise. – kosmikus