git.iko.soy/typeable/servant
on master help sign in
Documentation improvements and minor cleanup
commit12d0d0a6e7e70114394661ba27bb609004985763 authorChristian Marie <christian@ponies.io> dateThu 29 Jan 2015, 10:39 (12 years ago) parent70ffe01
1 file changed+12−8
src/Servant/Utils/Links.hs+12−8
src/Servant/Utils/Links.hs+12−8
@@ -118,14 +118,18 @@ type family Or (a :: Constraint) (b :: Constraint) :: Constraint where
118118 Or a () = ()
119119
120120-- | You may use this type family to tell the type checker that your custom type
121−-- is a valid part of a link like so:
122−--
123−-- Not that 'IsElem' is called, which mutually recurses back to `IsElem'`
121+-- may be skipped as part of a link. This is useful for things like
122+-- 'QueryParam' that are optional in a URI and do not affect them if they are
123+-- omitted.
124124--
125125-- >>> data CustomThing
126126-- >>> type instance IsElem' e (CustomThing :> s) = IsElem e s
127127--
128−-- Now you can add a HasLink instance and you are ready to go.
128+-- Note that 'IsElem' is called, which will mutually recurse back to `IsElem'`
129+-- if it exhausts all other options again.
130+--
131+-- Once you have written a HasLink instance for CustomThing you are ready to
132+-- go.
129133type family IsElem' a s :: Constraint
130134
131135-- | Closed type family, check if endpoint is within api
@@ -164,11 +168,11 @@ data Param a
164168 deriving Show
165169
166170addSegment :: String -> Link -> Link
167−addSegment seg l = l { _segments = _segments l ++ [seg] }
171+addSegment seg l = l { _segments = _segments l <> [seg] }
168172
169173addQueryParam :: Param Query -> Link -> Link
170174addQueryParam qp l =
171− l { _queryParams = _queryParams l ++ [qp] }
175+ l { _queryParams = _queryParams l <> [qp] }
172176
173177-- Not particularly efficient for many updates. Something to optimise if it's
174178-- a problem.
@@ -176,7 +180,7 @@ addMatrixParam :: Param Matrix -> Link -> Link
176180addMatrixParam param l = l { _segments = f (_segments l) }
177181 where
178182 f [] = []
179− f xs = init xs ++ [g (last xs)]
183+ f xs = init xs <> [g (last xs)]
180184 -- Modify the segment at the "top" of the stack
181185 g :: String -> String
182186 g seg =
@@ -220,7 +224,7 @@ safeLink
220224 -> MkLink endpoint
221225safeLink endpoint _ = link endpoint mempty
222226
223−-- | Construct a link for an endpoint
227+-- | Construct a link for an endpoint.
224228class HasLink endpoint where
225229 type MkLink endpoint
226230 link :: Proxy endpoint -- ^ The API endpoint you would like to point to