on develop help sign in
Removing duplicate scopes when using the (!) combinator
commit3dac194628dbc70c3134a7d7c1319e1bbcca10cc authorBrendan Hay <brendan.g.hay@gmail.com> dateTue 22 Mar 2016, 17:06 (11 years ago) parent724a787
1 file changed+17−6
gogol/src/Network/Google/Auth/Scope.hs+17−6
gogol/src/Network/Google/Auth/Scope.hs+17−6
@@ -52,7 +52,7 @@ forbid = id
5252-- | Append two sets of scopes.
5353--
5454-- /See:/ 'allow'.
55−(!) :: proxy xs -> proxy ys -> Proxy (xs ++ ys)
55+(!) :: proxy xs -> proxy ys -> Proxy (Nub (xs ++ ys))
5656(!) _ _ = Proxy
5757
5858-- | Determine if _any_ of the scopes a request requires is
@@ -70,16 +70,27 @@ type family HasScope' s a where
7070 HasScope' s '[] = 'True -- No scopes are required.
7171 HasScope' (x ': xs) a = x ∈ a || HasScope' xs a
7272
73−-- | Membership.
73+-- | Membership predicate.
7474type family (∈) a b where
7575 (∈) x '[] = 'False
7676 (∈) x (y ': xs) = x == y || x ∈ xs
7777
78−-- | Append.
78+-- | Append two lists.
7979type family (++) xs ys where
80− (++) a '[] = a
81− (++) '[] b = b
82− (++) (a ': as) bs = a ': (as ++ bs)
80+ (++) xs '[] = xs
81+ (++) '[] ys = ys
82+ (++) (x ': xs) ys = x ': (xs ++ ys)
83+
84+-- | Remove duplicates from a list.
85+type family Nub xs where
86+ Nub '[] = '[]
87+ Nub (x ': xs) = x ': Nub (Delete x xs)
88+
89+-- | Remove a specific element from a list.
90+type family Delete x xs where
91+ Delete x '[] = '[]
92+ Delete x (x ': ys) = Delete x ys
93+ Delete x (y ': ys) = y ': Delete x ys
8394
8495class AllowScopes a where
8596 -- | Obtain a list of supported 'OAuthScope' values from a proxy.