Skip to content

Commit 33cc9bc

Browse files
committed
Update scalafmt-core to 2.6.0
1 parent ab86c72 commit 33cc9bc

15 files changed

+162
-124
lines changed

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=2.5.3
1+
version=2.6.0
22
style = defaultWithAlign
33
maxColumn = 100
44

src/main/scala/catslib/Applicative.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ import org.scalatest.flatspec.AnyFlatSpec
2222
import cats._
2323
import cats.implicits._
2424

25-
/** `Applicative` extends `Apply` by adding a single method, `pure`:
25+
/**
26+
* `Applicative` extends `Apply` by adding a single method, `pure`:
2627
*
2728
* {{{
2829
* def pure[A](x: A): F[A]
2930
* }}}
3031
*
31-
*
3232
* @param name applicative
3333
*/
3434
object ApplicativeSection
3535
extends AnyFlatSpec
3636
with Matchers
3737
with org.scalaexercises.definitions.Section {
3838

39-
/** This method takes any value and returns the value in the context of
39+
/**
40+
* This method takes any value and returns the value in the context of
4041
* the functor. For many familiar functors, how to do this is
4142
* obvious. For `Option`, the `pure` operation wraps the value in
4243
* `Some`. For `List`, the `pure` operation returns a single element
4344
* `List`:
44-
*
4545
*/
4646
def pureMethod(res0: Option[Int], res1: List[Int]) = {
4747
import cats._
@@ -51,7 +51,8 @@ object ApplicativeSection
5151
Applicative[List].pure(1) should be(res1)
5252
}
5353

54-
/** Like `Functor` and `Apply`, `Applicative`
54+
/**
55+
* Like `Functor` and `Apply`, `Applicative`
5556
* functors also compose naturally with each other. When
5657
* you compose one `Applicative` with another, the resulting `pure`
5758
* operation will lift the passed value into one context, and the result
@@ -60,7 +61,8 @@ object ApplicativeSection
6061
def applicativeComposition(res0: List[Option[Int]]) =
6162
(Applicative[List] compose Applicative[Option]).pure(1) should be(res0)
6263

63-
/** = Applicative Functors & Monads =
64+
/**
65+
* = Applicative Functors & Monads =
6466
*
6567
* `Applicative` is a generalization of `Monad`, allowing expression
6668
* of effectful computations in a pure functional way.

src/main/scala/catslib/Apply.scala

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import ApplyHelpers._
2323
import cats._
2424
import cats.implicits._
2525

26-
/** `Apply` extends the `Functor` type class (which features the familiar `map`
26+
/**
27+
* `Apply` extends the `Functor` type class (which features the familiar `map`
2728
* function) with a new function `ap`. The `ap` function is similar to `map`
2829
* in that we are transforming a value in a context (a context being the `F` in `F[A]`;
2930
* a context can be `Option`, `List` or `Future` for example).
@@ -59,7 +60,8 @@ import cats.implicits._
5960
*/
6061
object ApplySection extends AnyFlatSpec with Matchers with org.scalaexercises.definitions.Section {
6162

62-
/** = map =
63+
/**
64+
* = map =
6365
*
6466
* Since `Apply` extends `Functor`, we can use the `map` method from `Functor`:
6567
*/
@@ -75,7 +77,8 @@ object ApplySection extends AnyFlatSpec with Matchers with org.scalaexercises.de
7577
Apply[Option].map(None)(addTwo) should be(res2)
7678
}
7779

78-
/** = compose =
80+
/**
81+
* = compose =
7982
*
8083
* And like functors, `Apply` instances also compose:
8184
*/
@@ -85,7 +88,8 @@ object ApplySection extends AnyFlatSpec with Matchers with org.scalaexercises.de
8588
listOpt.ap(List(Some(plusOne)))(List(Some(1), None, Some(3))) should be(res0)
8689
}
8790

88-
/** = ap =
91+
/**
92+
* = ap =
8993
*
9094
* The `ap` method is a method that `Functor` does not have:
9195
*/
@@ -103,7 +107,8 @@ object ApplySection extends AnyFlatSpec with Matchers with org.scalaexercises.de
103107
Apply[Option].ap(None)(None) should be(res4)
104108
}
105109

106-
/** = ap2, ap3, etc =
110+
/**
111+
* = ap2, ap3, etc =
107112
*
108113
* `Apply` also offers variants of `ap`. The functions `apN` (for `N` between `2` and `22`)
109114
* accept `N` arguments where `ap` accepts `1`.
@@ -121,28 +126,29 @@ object ApplySection extends AnyFlatSpec with Matchers with org.scalaexercises.de
121126
Apply[Option].ap3(Some(addArity3))(Some(1), Some(2), Some(3)) should be(res2)
122127
}
123128

124-
/** = map2, map3, etc =
129+
/**
130+
* = map2, map3, etc =
125131
*
126132
* Similarly, `mapN` functions are available:
127-
*
128133
*/
129134
def applyMapn(res0: Option[Int], res1: Option[Int]) = {
130135
Apply[Option].map2(Some(1), Some(2))(addArity2) should be(res0)
131136

132137
Apply[Option].map3(Some(1), Some(2), Some(3))(addArity3) should be(res1)
133138
}
134139

135-
/** = tuple2, tuple3, etc =
140+
/**
141+
* = tuple2, tuple3, etc =
136142
*
137143
* Similarly, `tupleN` functions are available:
138-
*
139144
*/
140145
def applyTuplen(res0: Option[(Int, Int)], res1: Option[(Int, Int, Int)]) = {
141146
Apply[Option].tuple2(Some(1), Some(2)) should be(res0)
142147
Apply[Option].tuple3(Some(1), Some(2), Some(3)) should be(res1)
143148
}
144149

145-
/** = apply builder syntax =
150+
/**
151+
* = apply builder syntax =
146152
*
147153
* In order to use functions `apN`, `mapN` and `tupleN` *infix*,
148154
* import `cats.implicits._`.

src/main/scala/catslib/CatsLibrary.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
package catslib
1818

19-
/** Cats is a library which provides abstractions for functional programming in the Scala programming language.
19+
/**
20+
* Cats is a library which provides abstractions for functional programming in the Scala programming language.
2021
*
2122
* @param name cats
2223
*/

src/main/scala/catslib/EitherSection.scala

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ object EitherStyleWithAdts {
5555
parse(s).flatMap(reciprocal).map(stringify)
5656
}
5757

58-
/** In day-to-day programming, it is fairly common to find ourselves writing functions that
58+
/**
59+
* In day-to-day programming, it is fairly common to find ourselves writing functions that
5960
* can fail. For instance, querying a service may result in a connection issue, or some
6061
* unexpected JSON response.
6162
*
@@ -94,7 +95,8 @@ object EitherStyleWithAdts {
9495
*/
9596
object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.definitions.Section {
9697

97-
/** More often than not we want to just bias towards one side and call it a day - by convention,
98+
/**
99+
* More often than not we want to just bias towards one side and call it a day - by convention,
98100
* the right side is most often chosen.
99101
*/
100102
def eitherMapRightBias(res0: Either[String, Int], res1: Either[String, Int]) = {
@@ -106,7 +108,8 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
106108
left.map(_ + 1) should be(res1)
107109
}
108110

109-
/** Because `Either` is right-biased, it is possible to define a `Monad` instance for it.
111+
/**
112+
* Because `Either` is right-biased, it is possible to define a `Monad` instance for it.
110113
*
111114
* Since we only ever want the computation to continue in the case of `Right` (as captured
112115
* by the right-bias nature), we fix the left type parameter and leave the right one free.
@@ -125,7 +128,6 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
125128
* }}}
126129
*
127130
* So the `flatMap` method is right-biased:
128-
*
129131
*/
130132
def eitherMonad(res0: Either[String, Int], res1: Either[String, Int]) = {
131133

@@ -136,7 +138,8 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
136138
left.flatMap(x => Either.right(x + 1)) should be(res1)
137139
}
138140

139-
/** = Using `Either` instead of exceptions =
141+
/**
142+
* = Using `Either` instead of exceptions =
140143
*
141144
* As a running example, we will have a series of functions that will parse a string into an integer,
142145
* take the reciprocal, and then turn the reciprocal into a string.
@@ -178,15 +181,14 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
178181
* }}}
179182
*
180183
* Do these calls return a `Right` value?
181-
*
182184
*/
183185
def eitherStyleParse(res0: Boolean, res1: Boolean) = {
184186
EitherStyle.parse("Not a number").isRight should be(res0)
185187
EitherStyle.parse("2").isRight should be(res1)
186188
}
187189

188-
/** Now, using combinators like `flatMap` and `map`, we can compose our functions together. Will the following incantations return a `Right` value?
189-
*
190+
/**
191+
* Now, using combinators like `flatMap` and `map`, we can compose our functions together. Will the following incantations return a `Right` value?
190192
*/
191193
def eitherComposition(res0: Boolean, res1: Boolean, res2: Boolean) = {
192194
import EitherStyle._
@@ -196,7 +198,8 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
196198
magic("Not a number").isRight should be(res2)
197199
}
198200

199-
/** With the composite function that we actually care about, we can pass in strings and then pattern
201+
/**
202+
* With the composite function that we actually care about, we can pass in strings and then pattern
200203
* match on the exception. Because `Either` is a sealed type (often referred to as an algebraic data type,
201204
* or ADT), the compiler will complain if we do not check both the `Left` and `Right` case.
202205
*
@@ -207,7 +210,6 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
207210
* `NumberFormatException` or `IllegalArgumentException`. However, we "know" by inspection of the source
208211
* that those will be the only exceptions thrown, so it seems strange to have to account for other exceptions.
209212
* This implies that there is still room to improve.
210-
*
211213
*/
212214
def eitherExceptions(res0: String) = {
213215
import EitherStyle._
@@ -221,7 +223,8 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
221223
result should be(res0)
222224
}
223225

224-
/** Instead of using exceptions as our error value, let's instead enumerate explicitly the things that
226+
/**
227+
* Instead of using exceptions as our error value, let's instead enumerate explicitly the things that
225228
* can go wrong in our program.
226229
*
227230
* {{{
@@ -249,7 +252,6 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
249252
* exception classes as error values, we use one of the enumerated cases. Now when we pattern
250253
* match, we get much nicer matching. Moreover, since `Error` is `sealed`, no outside code can
251254
* add additional subtypes which we might fail to handle.
252-
*
253255
*/
254256
def eitherErrorsAsAdts(res0: String) = {
255257
import EitherStyleWithAdts._
@@ -262,7 +264,8 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
262264
result should be(res0)
263265
}
264266

265-
/** = Either in the small, Either in the large =
267+
/**
268+
* = Either in the small, Either in the large =
266269
*
267270
* Once you start using `Either` for all your error-handling, you may quickly run into an issue where
268271
* you need to call into two separate modules which give back separate kinds of errors.
@@ -380,7 +383,6 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
380383
* }}}
381384
*
382385
* Let's review the `leftMap` and `map` methods:
383-
*
384386
*/
385387
def eitherInTheLarge(
386388
res0: Either[String, Int],
@@ -395,7 +397,8 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
395397
left.leftMap(_.reverse) should be(res2)
396398
}
397399

398-
/** There will inevitably come a time when your nice `Either` code will have to interact with exception-throwing
400+
/**
401+
* There will inevitably come a time when your nice `Either` code will have to interact with exception-throwing
399402
* code. Handling such situations is easy enough.
400403
*
401404
* {{{
@@ -417,16 +420,15 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
417420
* }}}
418421
*
419422
* If you want to catch all (non-fatal) throwables, you can use `catchNonFatal`.
420-
*
421-
*
422423
*/
423424
def eitherWithExceptions(res0: Boolean, res1: Boolean) = {
424425
Either.catchOnly[NumberFormatException]("abc".toInt).isRight should be(res0)
425426

426427
Either.catchNonFatal(1 / 0).isLeft should be(res1)
427428
}
428429

429-
/** = Additional syntax =
430+
/**
431+
* = Additional syntax =
430432
*
431433
* For using Either's syntax on arbitrary data types, you can import `cats.implicits._`. This will
432434
* make possible to use the `asLeft` and `asRight` methods:
@@ -440,7 +442,6 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
440442
* }}}
441443
*
442444
* These method promote values to the `Either` data type:
443-
*
444445
*/
445446
def eitherSyntax(res0: Either[String, Int]) = {
446447
import cats.implicits._

src/main/scala/catslib/EvalSection.scala

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import cats._
2020
import org.scalatest.flatspec.AnyFlatSpec
2121
import org.scalatest.matchers.should.Matchers
2222

23-
/** Eval is a data type for controlling synchronous evaluation.
23+
/**
24+
* Eval is a data type for controlling synchronous evaluation.
2425
* Its implementation is designed to provide stack-safety at all times using a technique called trampolining.
2526
* There are two different factors that play into evaluation: memoization and laziness.
2627
* Memoized evaluation evaluates an expression only once and then remembers (memoizes) that value.
@@ -34,7 +35,8 @@ import org.scalatest.matchers.should.Matchers
3435
*/
3536
object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.definitions.Section {
3637

37-
/** = Eval.now =
38+
/**
39+
* = Eval.now =
3840
*
3941
* First of the strategies is eager evaluation, we can construct an Eval eagerly using Eval.now:
4042
*
@@ -56,7 +58,6 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
5658
* We can run the computation using the given evaluation strategy anytime by using the value method.
5759
* eager.value
5860
* // res0: Int = 7
59-
*
6061
*/
6162
def nowEval(resultList: List[Int]) = {
6263
//given
@@ -69,7 +70,8 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
6970
eagerEval.value shouldBe (resultList: List[Int])
7071
}
7172

72-
/** = Eval.later =
73+
/**
74+
* = Eval.later =
7375
*
7476
* If we want lazy evaluation, we can use Eval.later
7577
* In this case
@@ -94,7 +96,6 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
9496
* Eval.later is different to using a lazy val in a few different ways.
9597
* First, it allows the runtime to perform garbage collection of the thunk after evaluation, leading to more memory being freed earlier.
9698
* Secondly, when lazy vals are evaluated, in order to preserve thread-safety, the Scala compiler will lock the whole surrounding class, whereas Eval will only lock itself.
97-
*
9899
*/
99100
def laterEval(resultList: List[Int], counterResult: Int) = {
100101
//given
@@ -112,7 +113,8 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
112113
counter shouldBe counterResult
113114
}
114115

115-
/** = Eval.always =
116+
/**
117+
* = Eval.always =
116118
*
117119
* If we want lazy evaluation, but without memoization akin to Function0, we can use Eval.always
118120
* Here we can see, that the expression is evaluated every time we call .value.
@@ -125,7 +127,6 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
125127
* //Always evaluated
126128
* alwaysEval.eval
127129
* }}}
128-
*
129130
*/
130131
def alwaysEval(resultList: List[Int], counterAfterListEval: Int, latestCounter: Int) = {
131132
//given
@@ -144,12 +145,12 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
144145
counter shouldBe latestCounter
145146
}
146147

147-
/** = Eval.defer =
148+
/**
149+
* = Eval.defer =
148150
*
149151
* Defer a computation which produces an Eval[A] value
150152
* This is useful when you want to delay execution of an expression which produces an Eval[A] value. Like .flatMap, it is stack-safe.
151153
* Because Eval guarantees stack-safety, we can chain a lot of computations together using flatMap without fear of blowing up the stack.
152-
*
153154
*/
154155
def deferEval(resultList: List[Int]) = {
155156
//given

0 commit comments

Comments
 (0)