@@ -7,29 +7,30 @@ import urldsl.vocabulary.{Codec, FromString, MaybeFragment, Printer}
7
7
import scala .language .implicitConversions
8
8
import scala .reflect .ClassTag
9
9
10
- /**
11
- * Represents the fragment (or ref) of an URL, containing an information of type T, or an error of type E.
10
+ /** Represents the fragment (or ref) of an URL, containing an information of type T, or an error of type E.
12
11
*
13
- * @tparam T type represented by this PathSegment
14
- * @tparam E type of the error that this PathSegment produces on "illegal" url paths.
12
+ * @tparam T
13
+ * type represented by this PathSegment
14
+ * @tparam E
15
+ * type of the error that this PathSegment produces on "illegal" url paths.
15
16
*/
16
17
trait Fragment [T , + E ] extends UrlPart [T , E ] {
17
18
18
19
import Fragment .factory
19
20
20
- /**
21
- * Extract the information contained in this fragment, as an instance of T.
21
+ /** Extract the information contained in this fragment, as an instance of T.
22
22
*
23
- * @param maybeFragment raw fragment information from the URL
24
- * @return Right a T when the extraction was successful, and Left an error otherwise.
23
+ * @param maybeFragment
24
+ * raw fragment information from the URL
25
+ * @return
26
+ * Right a T when the extraction was successful, and Left an error otherwise.
25
27
*/
26
28
def matchFragment (maybeFragment : MaybeFragment ): Either [E , T ]
27
29
28
30
def matchRawUrl (url : String , urlStringParserGenerator : UrlStringParserGenerator ): Either [E , T ] =
29
31
matchFragment(urlStringParserGenerator.parser(url).maybeFragmentObj)
30
32
31
- /**
32
- * Creates a fragment information from an instance of T.
33
+ /** Creates a fragment information from an instance of T.
33
34
*/
34
35
def createFragment (t : T ): MaybeFragment
35
36
@@ -51,31 +52,33 @@ trait Fragment[T, +E] extends UrlPart[T, E] {
51
52
52
53
def as [U ](implicit codec : Codec [T , U ]): Fragment [U , E ] = as[U ](codec.leftToRight _, codec.rightToLeft _)
53
54
54
- /**
55
- * Turns this fragment matching a `T` into a fragment matching an [[Option ]] of T.
56
- * It will return Some(t) if t could be extracted, and None otherwise.
55
+ /** Turns this fragment matching a `T` into a fragment matching an [[Option ]] of T. It will return Some(t) if t could
56
+ * be extracted, and None otherwise.
57
57
*
58
58
* The failure that happened and led to an error does not matter: it will result in None, no matter what.
59
59
*/
60
60
def ? : Fragment [Option [T ], E ] = factory(
61
61
matchFragment(_) match {
62
62
case Left (_) => Right (None )
63
63
case Right (value) => Right (Some (value))
64
- }, {
64
+ },
65
+ {
65
66
case Some (t) => createFragment(t)
66
67
case None => MaybeFragment (None )
67
68
}
68
69
)
69
70
70
- /**
71
- * Adds an extra satisfying criteria to the de-serialized output of this [[Fragment ]].
72
- * When the output of this [[Fragment ]] does not satisfy the given predicate, the given error is returned
73
- * instead.
71
+ /** Adds an extra satisfying criteria to the de-serialized output of this [[Fragment ]]. When the output of this
72
+ * [[Fragment ]] does not satisfy the given predicate, the given error is returned instead.
74
73
*
75
- * @param predicate criteria that the output has to verify
76
- * @param error error happening when it's not the case
77
- * @tparam E1 new type of the error
78
- * @return a new [[Fragment ]] matching the same fragment information, but only when the predicate is satisfied
74
+ * @param predicate
75
+ * criteria that the output has to verify
76
+ * @param error
77
+ * error happening when it's not the case
78
+ * @tparam E1
79
+ * new type of the error
80
+ * @return
81
+ * a new [[Fragment ]] matching the same fragment information, but only when the predicate is satisfied
79
82
*/
80
83
final def filter [E1 >: E ](predicate : T => Boolean , error : MaybeFragment => E1 ): Fragment [T , E1 ] =
81
84
Fragment .factory[T , E1 ](
@@ -91,19 +94,20 @@ trait Fragment[T, +E] extends UrlPart[T, E] {
91
94
this .asInstanceOf [Fragment [T , DummyError ]].filter(predicate, _ => DummyError .dummyError)
92
95
}
93
96
94
- /**
95
- * Returns a [[Fragment ]] which outputs the contents of this [[Fragment ]] when result is a [[Some ]] and the
96
- * specified `default` value otherwise.
97
- * When generating the path, it will only generate paths corresponding to the [[Some ]] case.
97
+ /** Returns a [[Fragment ]] which outputs the contents of this [[Fragment ]] when result is a [[Some ]] and the specified
98
+ * `default` value otherwise. When generating the path, it will only generate paths corresponding to the [[Some ]]
99
+ * case.
98
100
*
99
- * @note This method is only available when `T =:= Option[U]`.
101
+ * @note
102
+ * This method is only available when `T =:= Option[U]`.
100
103
*
101
- * @param default default value when output is empty
104
+ * @param default
105
+ * default value when output is empty
102
106
*/
103
107
final def getOrElse [U ](default : => U )(implicit ev : T =:= Option [U ]): Fragment [U , E ] =
104
108
factory[U , E ](
105
109
(maybeFragment : MaybeFragment ) => matchFragment(maybeFragment).map(ev(_).getOrElse(default)),
106
- // (u: U) => createFragment(ev.flip(Some(u)))
110
+ // (u: U) => createFragment(ev.flip(Some(u)))
107
111
// we keep the ugliness below while supporting 2.12 todo[scala3] remove
108
112
(u : U ) => createFragment(Some (u).asInstanceOf [T ])
109
113
)
@@ -118,14 +122,13 @@ object Fragment {
118
122
def createFragment (t : T ): MaybeFragment = generator(t)
119
123
}
120
124
121
- /**
122
- * Creates a fragment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString ]] can
125
+ /** Creates a fragment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString ]] can
123
126
* de-serialize it.
124
127
*
125
128
* If the fragment is missing, returns an error.
126
129
*/
127
- def fragment [T , A ](
128
- implicit fromString : FromString [T , A ],
130
+ def fragment [T , A ](implicit
131
+ fromString : FromString [T , A ],
129
132
printer : Printer [T ],
130
133
fragmentMatchingError : FragmentMatchingError [A ]
131
134
): Fragment [T , A ] = factory[T , A ](
@@ -136,14 +139,13 @@ object Fragment {
136
139
(printer.apply _).andThen(Some (_)).andThen(MaybeFragment .apply)
137
140
)
138
141
139
- /**
140
- * Creates a fragment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString ]] can
142
+ /** Creates a fragment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString ]] can
141
143
* de-serialize it.
142
144
*
143
145
* If the fragment is missing, returns None.
144
146
*/
145
- final def maybeFragment [T , A ](
146
- implicit fromString : FromString [T , A ],
147
+ final def maybeFragment [T , A ](implicit
148
+ fromString : FromString [T , A ],
147
149
printer : Printer [T ],
148
150
fragmentMatchingError : FragmentMatchingError [A ]
149
151
): Fragment [Option [T ], A ] = factory[Option [T ], A ](
@@ -163,8 +165,8 @@ object Fragment {
163
165
(_ : Unit ) => MaybeFragment (None )
164
166
)
165
167
166
- implicit def asFragment [T , A ](t : T )(
167
- implicit fromString : FromString [T , A ],
168
+ implicit def asFragment [T , A ](t : T )(implicit
169
+ fromString : FromString [T , A ],
168
170
printer : Printer [T ],
169
171
fragmentMatchingError : FragmentMatchingError [A ],
170
172
classTag : ClassTag [T ]
@@ -173,11 +175,12 @@ object Fragment {
173
175
case MaybeFragment (None ) => Left (fragmentMatchingError.missingFragmentError)
174
176
case MaybeFragment (Some (fragment)) =>
175
177
fromString(fragment) match {
176
- case Left (value) => Left (value)
177
- case Right (decodedValue) => decodedValue match {
178
- case value : T if value == t => Right (())
179
- case _ => Left (fragmentMatchingError.wrongValue(decodedValue, t))
180
- }
178
+ case Left (value) => Left (value)
179
+ case Right (decodedValue) =>
180
+ decodedValue match {
181
+ case value : T if value == t => Right (())
182
+ case _ => Left (fragmentMatchingError.wrongValue(decodedValue, t))
183
+ }
181
184
}
182
185
},
183
186
_ => MaybeFragment (Some (printer.print(t)))
0 commit comments