Skip to content

Commit ef4b38a

Browse files
authored
Renamed AtLeastOneFragment type class to AtMostOneFragment (#1727)
* Renamed `AtLeastOneFragment` to `AtMostOneFragment`
1 parent 1740e5e commit ef4b38a

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

changelog.d/1727

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
synopsis: Renamed `AtLeastOneFragment` type class to `AtMostOneFragment`
2+
prs: #1720
3+
4+
description: {
5+
6+
The previously named `AtLeastOneFragment` type class defined in the
7+
`Servant.API.TypeLevel` module has been renamed to `AtMostOneFragment`,
8+
since the previous name was misleading.
9+
10+
}

servant-client-core/src/Servant/Client/Core/HasClient.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import Servant.API.ContentTypes
8888
(contentTypes, AllMime (allMime), AllMimeUnrender (allMimeUnrender))
8989
import Servant.API.Status
9090
(statusFromNat)
91-
import Servant.API.TypeLevel (FragmentUnique, AtLeastOneFragment)
91+
import Servant.API.TypeLevel (FragmentUnique, AtMostOneFragment)
9292
import Servant.API.Modifiers
9393
(FoldRequired, RequiredArgument, foldRequiredArgument)
9494
import Servant.API.TypeErrors
@@ -821,7 +821,7 @@ instance ( HasClient m api
821821
-- > getBooks = client myApi
822822
-- > -- then you can just use "getBooksBy" to query that endpoint.
823823
-- > -- 'getBooks' for all books.
824-
instance (AtLeastOneFragment api, FragmentUnique (Fragment a :> api), HasClient m api
824+
instance (AtMostOneFragment api, FragmentUnique (Fragment a :> api), HasClient m api
825825
) => HasClient m (Fragment a :> api) where
826826

827827
type Client m (Fragment a :> api) = Client m api

servant-server/src/Servant/Server/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ import Servant.Server.Internal.ServerError
114114
import GHC.TypeLits
115115
(ErrorMessage (..), TypeError)
116116
import Servant.API.TypeLevel
117-
(AtLeastOneFragment, FragmentUnique)
117+
(AtMostOneFragment, FragmentUnique)
118118

119119
class HasServer api context where
120120
-- | The type of a server for this API, given a monad to run effects in.
@@ -961,7 +961,7 @@ instance {-# OVERLAPPABLE #-} TypeError (NoInstanceFor (HasServer api context))
961961
-- > server = getBooks
962962
-- > where getBooks :: Handler [Book]
963963
-- > getBooks = ...return all books...
964-
instance (AtLeastOneFragment api, FragmentUnique (Fragment a1 :> api), HasServer api context)
964+
instance (AtMostOneFragment api, FragmentUnique (Fragment a1 :> api), HasServer api context)
965965
=> HasServer (Fragment a1 :> api) context where
966966
type ServerT (Fragment a1 :> api) m = ServerT api m
967967

servant/src/Servant/API/TypeLevel.hs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module Servant.API.TypeLevel (
4747
And,
4848
-- ** Fragment
4949
FragmentUnique,
50-
AtLeastOneFragment
50+
AtMostOneFragment
5151
) where
5252

5353

@@ -244,14 +244,14 @@ type family ElemGo e es orig :: Constraint where
244244

245245
-- ** Logic
246246

247-
-- | If either a or b produce an empty constraint, produce an empty constraint.
247+
-- | If either 'a' or 'b' produce an empty constraint, produce an empty constraint.
248248
type family Or (a :: Constraint) (b :: Constraint) :: Constraint where
249249
-- This works because of:
250250
-- https://ghc.haskell.org/trac/ghc/wiki/NewAxioms/CoincidentOverlap
251251
Or () b = ()
252252
Or a () = ()
253253

254-
-- | If both a or b produce an empty constraint, produce an empty constraint.
254+
-- | If both 'a' or 'b' produce an empty constraint, produce an empty constraint.
255255
type family And (a :: Constraint) (b :: Constraint) :: Constraint where
256256
And () () = ()
257257

@@ -263,21 +263,22 @@ families are not evaluated (see https://ghc.haskell.org/trac/ghc/ticket/12048).
263263

264264
-- ** Fragment
265265

266-
class FragmentUnique api => AtLeastOneFragment api
267-
268-
-- | If fragment appeared in API endpoint twice, compile-time error would be raised.
266+
-- | If there is more than one fragment in an API endpoint,
267+
-- a compile-time error is raised.
269268
--
270-
-- >>> -- type FailAPI = Fragment Bool :> Fragment Int :> Get '[JSON] NoContent
271-
-- >>> instance AtLeastOneFragment FailAPI
269+
-- >>> type FailAPI = Fragment Bool :> Fragment Int :> Get '[JSON] NoContent
270+
-- >>> instance AtMostOneFragment FailAPI
272271
-- ...
273272
-- ...Only one Fragment allowed per endpoint in api...
274273
-- ...
275274
-- ...In the instance declaration for...
276-
instance AtLeastOneFragment (Verb m s ct typ)
275+
class FragmentUnique api => AtMostOneFragment api
276+
277+
instance AtMostOneFragment (Verb m s ct typ)
277278

278-
instance AtLeastOneFragment (UVerb m cts as)
279+
instance AtMostOneFragment (UVerb m cts as)
279280

280-
instance AtLeastOneFragment (Fragment a)
281+
instance AtMostOneFragment (Fragment a)
281282

282283
type family FragmentUnique api :: Constraint where
283284
FragmentUnique (sa :<|> sb) = And (FragmentUnique sa) (FragmentUnique sb)

0 commit comments

Comments
 (0)