on develop help sign in
Removing duplicate scopes when using the (!) combinator
3dac194Brendan Hay
gogol/src/Network/Google/Auth/Scope.hs+17−6
@@ -52,7 +52,7 @@ forbid = id
52-- | Append two sets of scopes.
52-- | Append two sets of scopes.
53--
53--
54-- /See:/ 'allow'.
54-- /See:/ 'allow'.
55−(!) :: proxy xs -> proxy ys -> Proxy (xs ++ ys)
55+(!) :: proxy xs -> proxy ys -> Proxy (Nub (xs ++ ys))
56(!) _ _ = Proxy
56(!) _ _ = Proxy
57
57
58-- | Determine if _any_ of the scopes a request requires is
58-- | Determine if _any_ of the scopes a request requires is
@@ -70,16 +70,27 @@ type family HasScope' s a where
70 HasScope' s '[] = 'True -- No scopes are required.
70 HasScope' s '[] = 'True -- No scopes are required.
71 HasScope' (x ': xs) a = x ∈ a || HasScope' xs a
71 HasScope' (x ': xs) a = x ∈ a || HasScope' xs a
72
72
73−-- | Membership.
73+-- | Membership predicate.
74type family (∈) a b where
74type family (∈) a b where
75 (∈) x '[] = 'False
75 (∈) x '[] = 'False
76 (∈) x (y ': xs) = x == y || x ∈ xs
76 (∈) x (y ': xs) = x == y || x ∈ xs
77
77
78−-- | Append.
78+-- | Append two lists.
79type family (++) xs ys where
79type family (++) xs ys where
80− (++) a '[] = a
80+ (++) xs '[] = xs
81− (++) '[] b = b
81+ (++) '[] ys = ys
82− (++) (a ': as) bs = a ': (as ++ bs)
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
83
94
84class AllowScopes a where
95class AllowScopes a where
85 -- | Obtain a list of supported 'OAuthScope' values from a proxy.
96 -- | Obtain a list of supported 'OAuthScope' values from a proxy.