Skip to content

Commit f890bf1

Browse files
committed
remove unnecessary "match"
1 parent 74cd5ad commit f890bf1

File tree

2 files changed

+34
-66
lines changed

2 files changed

+34
-66
lines changed

core/src/main/scala/scalikejdbc/async/AsyncDBSession.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,10 @@ trait AsyncDBSession extends LogSupport {
105105
implicit
106106
cxt: EC = ECGlobal): Future[Option[A]] = {
107107
val _parameters = ensureAndNormalizeParameters(parameters)
108-
iterable(statement, _parameters: _*)(extractor).map { results =>
109-
results match {
110-
case Nil => None
111-
case one :: Nil => Option(one)
112-
case _ => throw TooManyRowsException(1, results.size)
113-
}
108+
iterable(statement, _parameters: _*)(extractor).map {
109+
case Nil => None
110+
case one :: Nil => Option(one)
111+
case results => throw TooManyRowsException(1, results.size)
114112
}
115113
}
116114

core/src/main/scala/scalikejdbc/async/AsyncRelationalSQLs.scala

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ class AsyncOneToOneSQLToOption[A, B, Z](val underlying: OneToOneSQLToOption[A, B
2828
with AsyncSQLToOption[Z] {
2929
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
3030
session.oneToOneIterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(underlying.extractTo)(underlying.transform).map {
31-
results =>
32-
results match {
33-
case Nil => None
34-
case _ if results.size == 1 => results.headOption
35-
case _ => throw new TooManyRowsException(1, results.size)
36-
}
31+
case Nil => None
32+
case results if results.size == 1 => results.headOption
33+
case results => throw new TooManyRowsException(1, results.size)
3734
}
3835
}
3936
}
@@ -66,12 +63,9 @@ class AsyncOneToManySQLToOption[A, B, Z](val underlying: OneToManySQLToOption[A,
6663
with AsyncSQLToOption[Z] {
6764
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
6865
session.oneToManyIterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(underlying.extractTo)(underlying.transform).map {
69-
results =>
70-
results match {
71-
case Nil => None
72-
case _ if results.size == 1 => results.headOption
73-
case _ => throw new TooManyRowsException(1, results.size)
74-
}
66+
case Nil => None
67+
case results if results.size == 1 => results.headOption
68+
case results => throw new TooManyRowsException(1, results.size)
7569
}
7670
}
7771
}
@@ -104,12 +98,9 @@ class AsyncOneToManies2SQLToOption[A, B1, B2, Z](val underlying: OneToManies2SQL
10498
with AsyncSQLToOption[Z] {
10599
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
106100
session.oneToManies2Iterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(underlying.extractTo1, underlying.extractTo2)(underlying.transform).map {
107-
results =>
108-
results match {
109-
case Nil => None
110-
case _ if results.size == 1 => results.headOption
111-
case _ => throw new TooManyRowsException(1, results.size)
112-
}
101+
case Nil => None
102+
case results if results.size == 1 => results.headOption
103+
case results => throw new TooManyRowsException(1, results.size)
113104
}
114105
}
115106
}
@@ -142,12 +133,9 @@ class AsyncOneToManies3SQLToOption[A, B1, B2, B3, Z](val underlying: OneToManies
142133
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
143134
session.oneToManies3Iterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(
144135
underlying.extractTo1, underlying.extractTo2, underlying.extractTo3)(underlying.transform).map {
145-
results =>
146-
results match {
147-
case Nil => None
148-
case _ if results.size == 1 => results.headOption
149-
case _ => throw new TooManyRowsException(1, results.size)
150-
}
136+
case Nil => None
137+
case results if results.size == 1 => results.headOption
138+
case results => throw new TooManyRowsException(1, results.size)
151139
}
152140
}
153141
}
@@ -181,12 +169,9 @@ class AsyncOneToManies4SQLToOption[A, B1, B2, B3, B4, Z](val underlying: OneToMa
181169
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
182170
session.oneToManies4Iterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(
183171
underlying.extractTo1, underlying.extractTo2, underlying.extractTo3, underlying.extractTo4)(underlying.transform).map {
184-
results =>
185-
results match {
186-
case Nil => None
187-
case _ if results.size == 1 => results.headOption
188-
case _ => throw new TooManyRowsException(1, results.size)
189-
}
172+
case Nil => None
173+
case results if results.size == 1 => results.headOption
174+
case results => throw new TooManyRowsException(1, results.size)
190175
}
191176
}
192177
}
@@ -220,12 +205,9 @@ class AsyncOneToManies5SQLToOption[A, B1, B2, B3, B4, B5, Z](val underlying: One
220205
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
221206
session.oneToManies5Iterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(
222207
underlying.extractTo1, underlying.extractTo2, underlying.extractTo3, underlying.extractTo4, underlying.extractTo5)(underlying.transform).map {
223-
results =>
224-
results match {
225-
case Nil => None
226-
case _ if results.size == 1 => results.headOption
227-
case _ => throw new TooManyRowsException(1, results.size)
228-
}
208+
case Nil => None
209+
case results if results.size == 1 => results.headOption
210+
case results => throw new TooManyRowsException(1, results.size)
229211
}
230212
}
231213
}
@@ -259,12 +241,9 @@ class AsyncOneToManies6SQLToOption[A, B1, B2, B3, B4, B5, B6, Z](val underlying:
259241
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
260242
session.oneToManies6Iterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(
261243
underlying.extractTo1, underlying.extractTo2, underlying.extractTo3, underlying.extractTo4, underlying.extractTo5, underlying.extractTo6)(underlying.transform).map {
262-
results =>
263-
results match {
264-
case Nil => None
265-
case _ if results.size == 1 => results.headOption
266-
case _ => throw new TooManyRowsException(1, results.size)
267-
}
244+
case Nil => None
245+
case results if results.size == 1 => results.headOption
246+
case results => throw new TooManyRowsException(1, results.size)
268247
}
269248
}
270249
}
@@ -298,12 +277,9 @@ class AsyncOneToManies7SQLToOption[A, B1, B2, B3, B4, B5, B6, B7, Z](val underly
298277
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
299278
session.oneToManies7Iterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(
300279
underlying.extractTo1, underlying.extractTo2, underlying.extractTo3, underlying.extractTo4, underlying.extractTo5, underlying.extractTo6, underlying.extractTo7)(underlying.transform).map {
301-
results =>
302-
results match {
303-
case Nil => None
304-
case _ if results.size == 1 => results.headOption
305-
case _ => throw new TooManyRowsException(1, results.size)
306-
}
280+
case Nil => None
281+
case results if results.size == 1 => results.headOption
282+
case results => throw new TooManyRowsException(1, results.size)
307283
}
308284
}
309285
}
@@ -337,12 +313,9 @@ class AsyncOneToManies8SQLToOption[A, B1, B2, B3, B4, B5, B6, B7, B8, Z](val und
337313
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
338314
session.oneToManies8Iterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(
339315
underlying.extractTo1, underlying.extractTo2, underlying.extractTo3, underlying.extractTo4, underlying.extractTo5, underlying.extractTo6, underlying.extractTo7, underlying.extractTo8)(underlying.transform).map {
340-
results =>
341-
results match {
342-
case Nil => None
343-
case _ if results.size == 1 => results.headOption
344-
case _ => throw new TooManyRowsException(1, results.size)
345-
}
316+
case Nil => None
317+
case results if results.size == 1 => results.headOption
318+
case results => throw new TooManyRowsException(1, results.size)
346319
}
347320
}
348321
}
@@ -376,12 +349,9 @@ class AsyncOneToManies9SQLToOption[A, B1, B2, B3, B4, B5, B6, B7, B8, B9, Z](val
376349
override def future()(implicit session: AsyncDBSession, cxt: EC = ECGlobal): Future[Option[Z]] = {
377350
session.oneToManies9Iterable(underlying.statement, underlying.rawParameters: _*)(underlying.extractOne)(
378351
underlying.extractTo1, underlying.extractTo2, underlying.extractTo3, underlying.extractTo4, underlying.extractTo5, underlying.extractTo6, underlying.extractTo7, underlying.extractTo8, underlying.extractTo9)(underlying.transform).map {
379-
results =>
380-
results match {
381-
case Nil => None
382-
case _ if results.size == 1 => results.headOption
383-
case _ => throw new TooManyRowsException(1, results.size)
384-
}
352+
case Nil => None
353+
case results if results.size == 1 => results.headOption
354+
case results => throw new TooManyRowsException(1, results.size)
385355
}
386356
}
387357
}

0 commit comments

Comments
 (0)