git.iko.soy/typeable/http-api-data
on master help sign in
Rename default toPathPiece/fromPathPiece helpers
ac654a4Nickolay Kudasov
Web/PathPieces/Internal.hs+32−24
@@ -32,12 +32,12 @@ class PathPiece s where
32 -- | Convert from route piece.
32 -- | Convert from route piece.
33 fromPathPiece :: S.Text -> Maybe s
33 fromPathPiece :: S.Text -> Maybe s
34 default fromPathPiece :: FromHttpApiData s => S.Text -> Maybe s
34 default fromPathPiece :: FromHttpApiData s => S.Text -> Maybe s
35− fromPathPiece = either (const Nothing) Just . parseUrlPiece
35+ fromPathPiece = defaultFromPathPiece
36
36
37 -- | Convert to route piece.
37 -- | Convert to route piece.
38 toPathPiece :: s -> S.Text
38 toPathPiece :: s -> S.Text
39 default toPathPiece :: ToHttpApiData s => s -> S.Text
39 default toPathPiece :: ToHttpApiData s => s -> S.Text
40− toPathPiece = toUrlPiece
40+ toPathPiece = defaultToPathPiece
41
41
42instance PathPiece ()
42instance PathPiece ()
43instance PathPiece Char
43instance PathPiece Char
@@ -70,32 +70,32 @@ instance PathPiece All
70instance PathPiece Any
70instance PathPiece Any
71
71
72instance PathPiece a => PathPiece (Dual a) where
72instance PathPiece a => PathPiece (Dual a) where
73− toPathPiece = toPathPiece1
73+ toPathPiece = defaultToPathPiece1
74− fromPathPiece = fromPathPiece1
74+ fromPathPiece = defaultFromPathPiece1
75
75
76instance PathPiece a => PathPiece (Sum a) where
76instance PathPiece a => PathPiece (Sum a) where
77− toPathPiece = toPathPiece1
77+ toPathPiece = defaultToPathPiece1
78− fromPathPiece = fromPathPiece1
78+ fromPathPiece = defaultFromPathPiece1
79
79
80instance PathPiece a => PathPiece (Product a) where
80instance PathPiece a => PathPiece (Product a) where
81− toPathPiece = toPathPiece1
81+ toPathPiece = defaultToPathPiece1
82− fromPathPiece = fromPathPiece1
82+ fromPathPiece = defaultFromPathPiece1
83
83
84instance PathPiece a => PathPiece (First a) where
84instance PathPiece a => PathPiece (First a) where
85− toPathPiece = toPathPiece1
85+ toPathPiece = defaultToPathPiece1
86− fromPathPiece = fromPathPiece1
86+ fromPathPiece = defaultFromPathPiece1
87
87
88instance PathPiece a => PathPiece (Last a) where
88instance PathPiece a => PathPiece (Last a) where
89− toPathPiece = toPathPiece1
89+ toPathPiece = defaultToPathPiece1
90− fromPathPiece = fromPathPiece1
90+ fromPathPiece = defaultFromPathPiece1
91
91
92instance PathPiece a => PathPiece (Maybe a) where
92instance PathPiece a => PathPiece (Maybe a) where
93− toPathPiece = toPathPiece1
93+ toPathPiece = defaultToPathPiece1
94− fromPathPiece = fromPathPiece1
94+ fromPathPiece = defaultFromPathPiece1
95
95
96instance (PathPiece a, PathPiece b) => PathPiece (Either a b) where
96instance (PathPiece a, PathPiece b) => PathPiece (Either a b) where
97− toPathPiece = toPathPiece2
97+ toPathPiece = defaultToPathPiece2
98− fromPathPiece = fromPathPiece2
98+ fromPathPiece = defaultFromPathPiece2
99
99
100-- | Wrapped @'PathPiece'@ value.
100-- | Wrapped @'PathPiece'@ value.
101newtype WrappedPathPiece a = WrappedPathPiece { unwrapPathPiece :: a }
101newtype WrappedPathPiece a = WrappedPathPiece { unwrapPathPiece :: a }
@@ -106,21 +106,29 @@ instance PathPiece a => ToHttpApiData (WrappedPathPiece a) where
106instance PathPiece a => FromHttpApiData (WrappedPathPiece a) where
106instance PathPiece a => FromHttpApiData (WrappedPathPiece a) where
107 parseUrlPiece = fmap WrappedPathPiece . parseMaybeTextData fromPathPiece
107 parseUrlPiece = fmap WrappedPathPiece . parseMaybeTextData fromPathPiece
108
108
109+-- | Convert value to route piece using @'ToHttpApiData'@ implementation.
110+defaultToPathPiece :: ToHttpApiData a => a -> S.Text
111+defaultToPathPiece = toUrlPiece
112+
113+-- | Convert value from route piece using @'FromHttpApiData'@ implementation.
114+defaultFromPathPiece :: FromHttpApiData a => S.Text -> Maybe a
115+defaultFromPathPiece = either (const Nothing) Just . parseUrlPiece
116+
109-- | Convert value to route piece using @'PathPiece'@ instance for its parameter.
117-- | Convert value to route piece using @'PathPiece'@ instance for its parameter.
110−toPathPiece1 :: forall f a. (PathPiece a, ToHttpApiData (f (WrappedPathPiece a))) => f a -> S.Text
118+defaultToPathPiece1 :: (PathPiece a, ToHttpApiData (f (WrappedPathPiece a))) => f a -> S.Text
111−toPathPiece1 = toUrlPiece . (unsafeCoerce :: f a -> f (WrappedPathPiece a))
119+defaultToPathPiece1 = toUrlPiece . (unsafeCoerce :: f a -> f (WrappedPathPiece a))
112
120
113-- | Parse value from route piece using @'PathPiece'@ instance for its parameter.
121-- | Parse value from route piece using @'PathPiece'@ instance for its parameter.
114−fromPathPiece1 :: forall f a. (PathPiece a, FromHttpApiData (f (WrappedPathPiece a))) => S.Text -> Maybe (f a)
122+defaultFromPathPiece1 :: (PathPiece a, FromHttpApiData (f (WrappedPathPiece a))) => S.Text -> Maybe (f a)
115−fromPathPiece1 = either (const Nothing) (Just . (unsafeCoerce :: f (WrappedPathPiece a) -> f a)) . parseUrlPiece
123+defaultFromPathPiece1 = fmap (unsafeCoerce :: f (WrappedPathPiece a) -> f a) . defaultFromPathPiece
116
124
117-- | Convert value to route piece using @'PathPiece'@ instance for its parameters.
125-- | Convert value to route piece using @'PathPiece'@ instance for its parameters.
118−toPathPiece2 :: forall f a b. (PathPiece a, PathPiece b, ToHttpApiData (f (WrappedPathPiece a) (WrappedPathPiece b))) => f a b -> S.Text
126+defaultToPathPiece2 :: (PathPiece a, PathPiece b, ToHttpApiData (f (WrappedPathPiece a) (WrappedPathPiece b))) => f a b -> S.Text
119−toPathPiece2 = toUrlPiece . (unsafeCoerce :: f a b -> f (WrappedPathPiece a) (WrappedPathPiece b))
127+defaultToPathPiece2 = toUrlPiece . (unsafeCoerce :: f a b -> f (WrappedPathPiece a) (WrappedPathPiece b))
120
128
121-- | Parse value from route piece using @'PathPiece'@ instance for its parameters.
129-- | Parse value from route piece using @'PathPiece'@ instance for its parameters.
122−fromPathPiece2 :: forall f a b. (PathPiece a, PathPiece b, FromHttpApiData (f (WrappedPathPiece a) (WrappedPathPiece b))) => S.Text -> Maybe (f a b)
130+defaultFromPathPiece2 :: (PathPiece a, PathPiece b, FromHttpApiData (f (WrappedPathPiece a) (WrappedPathPiece b))) => S.Text -> Maybe (f a b)
123−fromPathPiece2 = either (const Nothing) (Just . (unsafeCoerce :: f (WrappedPathPiece a) (WrappedPathPiece b) -> f a b)) . parseUrlPiece
131+defaultFromPathPiece2 = fmap (unsafeCoerce :: f (WrappedPathPiece a) (WrappedPathPiece b) -> f a b) . defaultFromPathPiece
124
132
125-- | Convert Haskell values to and from sequence of route pieces.
133-- | Convert Haskell values to and from sequence of route pieces.
126class PathMultiPiece s where
134class PathMultiPiece s where