Skip to content

Commit 5a002aa

Browse files
Merge pull request #29 from morgen-peschke/release-0.3.0
Release 0.3.0
2 parents 163a24a + b534dcb commit 5a002aa

File tree

53 files changed

+2046
-1019
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2046
-1019
lines changed

.scalafix.conf

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
rules: [
2+
# Standard rules
23
DisableSyntax
34
LeakingImplicitClassVal
45
NoValInForComprehension
56
RedundantSyntax
6-
OrganizeImports
7+
8+
# https://github.com/liancheng/scalafix-organize-imports
9+
OrganizeImports,
10+
11+
# https://github.com/typelevel/typelevel-scalafix
12+
TypelevelMapSequence,
13+
TypelevelAs,
14+
TypelevelUnusedShowInterpolator,
15+
TypelevelFs2SyncCompiler
16+
# Disabled because it throws a MissingSymbolException
17+
# TypelevelUnusedIO
718
]
819

920
DisableSyntax.noVars = true
@@ -13,7 +24,7 @@ DisableSyntax.noReturns = true
1324
DisableSyntax.noWhileLoops = true
1425
DisableSyntax.noAsInstanceOf = true
1526
DisableSyntax.noIsInstanceOf = true
16-
DisableSyntax.noXml = false
27+
DisableSyntax.noXml = true
1728
DisableSyntax.noDefaultArgs = true
1829
DisableSyntax.noFinalVal = true
1930
DisableSyntax.noFinalize = true
@@ -24,5 +35,12 @@ DisableSyntax.regex: [
2435
id = "non-final case class"
2536
pattern = "^\\s{2,}case class"
2637
message = "Extending a case class produces broken classes. See https://stackoverflow.com/a/34562046/1188897"
38+
},
39+
{
40+
id = noPrintln
41+
pattern = "\\W*println\\("
42+
message = "Please log instead of using println"
2743
}
28-
]
44+
]
45+
46+
ExplicitResultTypes.memberVisibility = [Public, Protected, Private]

.scalafmt.conf

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,48 @@ fileOverride {
66
}
77
}
88

9-
style = default
10-
maxColumn = 80
9+
maxColumn = 120
1110

1211
project.git = true
1312
project.excludeFilters = []
1413

1514
assumeStandardLibraryStripMargin = true
1615

1716
align {
18-
preset = some
17+
preset = most
1918
stripMargin = true
2019
openParenCallSite = false
21-
openParenDefnSite = false
20+
openParenDefnSite = true
2221
openParenTupleSite = true
23-
closeParenSite = true
24-
beforeOpenParenCallSite = true
25-
beforeOpenParenDefnSite = true
26-
arrowEnumeratorGenerator = true
27-
tokens = [ ":", "=", "=>", "->", "<-", "//" ]
28-
}
29-
30-
danglingParentheses {
31-
defnSite = false
32-
callSite = true
33-
ctrlSite = true
34-
tupleSite = true
22+
arrowEnumeratorGenerator = false
23+
ifWhileOpenParen = false
24+
tokens."+" = [
25+
{
26+
code = ":"
27+
owners = [{
28+
parents = [ "Defn\\." ]
29+
}]
30+
},
31+
{
32+
code = "="
33+
owners = [{
34+
parents = [ "Defn\\." ]
35+
}]
36+
},
37+
{
38+
code = "->"
39+
owners = [{
40+
parents = [ "Term\\.ApplyInfix" ]
41+
}]
42+
}
43+
]
3544
}
3645

3746
newlines {
38-
beforeOpenParenDefnSite = fold
47+
beforeOpenParenDefnSite = unfold
3948
sometimesBeforeColonInMethodReturnType = true
4049
alwaysBeforeElseAfterCurlyIf = true
4150
inInterpolation = avoid
42-
beforeTypeBounds = unfold
43-
beforeCurlyLambdaParams = multilineWithCaseOnly
44-
afterCurlyLambdaParams = squash
4551
implicitParamListModifierPrefer = before
4652
avoidForSimpleOverflow=[tooLong,punct,slc]
4753
}
@@ -53,4 +59,9 @@ optIn {
5359
breaksInsideChains = true
5460
}
5561

62+
rewrite {
63+
rules = [SortImports, RedundantBraces]
64+
redundantBraces.maxLines = 1
65+
}
66+
5667
importSelectors = singleLine

README.md

Lines changed: 10 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,13 @@
22

33
Common utility libraries for Scala, mostly small stuff I don't want to have multiple copies of lying around.
44

5-
## Installation
6-
7-
### SBT
8-
```
9-
libraryDependencies += Seq(
10-
"com.github.morgen-peschke" % "commons-core" % "0.2.0",
11-
"com.github.morgen-peschke" % "commons-collections" % "0.2.0",
12-
"com.github.morgen-peschke" % "commons-decline" % "0.2.0",
13-
"com.github.morgen-peschke" % "commons-shims" % "0.2.0",
14-
"com.github.morgen-peschke" % "commons-scalacheck" % "0.2.0" % Test
15-
)
16-
```
17-
18-
### Mill
19-
```
20-
def ivyDeps = Agg(
21-
ivy"com.github.morgen-peschke::commons-core:0.2.0",
22-
ivy"com.github.morgen-peschke::commons-collections:0.2.0",
23-
ivy"com.github.morgen-peschke::commons-decline:0.2.0",
24-
ivy"com.github.morgen-peschke::commons-shims:0.2.0",
25-
ivy"com.github.morgen-peschke::commons-scalacheck:0.2.0"
26-
)
27-
```
28-
29-
## SubModules
30-
31-
### `commons-core`
32-
33-
This is a home for the most generic of utilities.
34-
35-
#### `Complete`
36-
37-
A placeholder indicating completion, which provides a work-around for the type issues which can arise when returning
38-
things like `Future[Unit]`.
39-
40-
This is very similar to `akka.Done`, and exists as a lightweight alternative to the same.
41-
42-
#### `Slice`
43-
44-
A pure Scala, lightweight implementation of python's slice syntax (e.g `[start:stop:step]`).
45-
46-
### `commons-collections`
47-
48-
Helpers and extensions for working with the Scala standard library.
49-
50-
#### `TakeUntil`
51-
52-
An alternative to `IterableOnce#takeWhile`, which is primarily differentiated on two points:
53-
1. The elements are consumed until the predicate is true, rather than while the predicate is true, so the logic is
54-
reversed.
55-
2. The final element is also taken.
56-
57-
### `commons-scalacheck`
58-
59-
A collection of utilities and syntax to make working with Scalacheck `Gen` smoother.
60-
61-
Highlights include:
62-
- `(0 to 10).choose` as a more flexible alternative to `Gen.chooseNum(0, 10)`
63-
This is particularly handy because `(a until b by c).choose` is equivalent to something closer to this:
64-
```scala
65-
Gen.chooseNum(0, (b-a) - 1).map(l => a + (c * l))
66-
```
67-
- `RangeGens.ranges(min, max)` generates `Range`s within those bounds
68-
- `NumericRangeGens.numericRanges(min, max)` generates `NumericRange`s within those bounds
69-
- `(g: Gen[A]).as.list(a to b)` as an alternative to `Gen.chooseNum(a, b).flatMap(Gen.listOfN(g, foo))`
70-
71-
Variants also exist to produce `Vector`, `Chain`, and the `NonEmpty*` equivalents, as well as one to
72-
lift a `Gen[Char]` into a `Gen[String]`
73-
- `(g: Gen[A]).optional` as a chaining alternative to `Gen.option(g)`
74-
75-
### `commons-decline`
76-
77-
Instances for Decline, notably one for `Slice` as it tends to be very handy for CLI utilities.
78-
79-
### `commons-shims`
80-
81-
Everything in this module has a better alternative in another library. If, however, you're not able to access
82-
the better version, this module aims to provide at least some comfort in the form of minimal dependency alternatives.
83-
84-
The primary example is `Managed`, which solves the same general problem as Java's try-with-resource construct, and
85-
is far better solved by `cats.effect.Resource`.
5+
## SubModule Documentation
6+
7+
- [`commons-core`](core/README.md)
8+
- [`commons-decline`](decline/README.md)
9+
- [`commons-collections`](collections/README.md)
10+
- [`commons-scalacheck`](scalacheck/README.md)
11+
- [`commons-testing`](testing/README.md)
12+
- [`commons-munit`](munit/README.md)
13+
- [`commons-scalatest`](scalatest/README.md)
14+
- [`commons-shims`](shims/README.md)

build.sc

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ val Scala13 = "2.13.8"
88

99
val CatsCore = ivy"org.typelevel::cats-core:2.7.0"
1010
val CatsParse = ivy"org.typelevel::cats-parse:0.3.7"
11-
11+
val CatsEffect = ivy"org.typelevel::cats-effect:3.3.14"
1212
val SuperTagged = ivy"org.rudogma::supertagged:2.0-RC2"
13+
val SourceCode = ivy"com.lihaoyi::sourcecode:0.3.0"
1314

1415
val ScalaCheck = ivy"org.scalacheck::scalacheck:1.16.0"
1516
val ScalaTest = ivy"org.scalatest::scalatest:3.2.13"
@@ -19,9 +20,13 @@ val PropSpec = Set(
1920
ivy"org.scalatest::scalatest-propspec:3.2.13",
2021
ivy"org.scalatestplus::scalacheck-1-16:3.2.12.0"
2122
)
23+
val MUnit = ivy"org.scalameta::munit:0.7.29"
2224

2325
trait StyleModule extends ScalafmtModule with ScalafixModule {
24-
override def scalafixIvyDeps = super.scalafixIvyDeps() ++ Agg(ivy"com.github.liancheng::organize-imports:0.6.0")
26+
override def scalafixIvyDeps = super.scalafixIvyDeps() ++ Agg(
27+
ivy"com.github.liancheng::organize-imports:0.6.0",
28+
ivy"org.typelevel::typelevel-scalafix:0.1.5"
29+
)
2530

2631
def commonScalacOptions = Seq(
2732
"-encoding",
@@ -36,6 +41,8 @@ trait StyleModule extends ScalafmtModule with ScalafixModule {
3641
"-language:higherKinds"
3742
)
3843

44+
override def forkEnv: T[Map[String, String]] = super.forkEnv().updated("SCALACTIC_FILL_FILE_PATHNAMES", "yes")
45+
3946
def versionSpecificOptions(version: String) = version match {
4047
case Scala12 =>
4148
Seq(
@@ -67,7 +74,7 @@ trait CommonModule
6774

6875
override def artifactName: T[String] = T { s"commons-${super.artifactName()}" }
6976

70-
def publishVersion: T[String] = "0.2.0"
77+
def publishVersion: T[String] = "0.3.0"
7178

7279
override def pomSettings: T[PomSettings] = PomSettings(
7380
description = "Scala Commons - common utilities for Scala projects",
@@ -87,13 +94,14 @@ trait CommonModule
8794
protected def outerCrossScalaVersion: String = crossScalaVersion
8895
}
8996

90-
trait CommonTestModule extends TestModule.ScalaTest with StyleModule
97+
trait UsingScalaTestModule extends TestModule.ScalaTest with StyleModule
98+
trait UsingMunitTestModule extends TestModule.Munit with StyleModule
9199

92100
object core extends Cross[CoreModule](Scala12, Scala13)
93101
class CoreModule(val crossScalaVersion: String) extends CommonModule {
94102
override def ivyDeps = Agg(CatsCore, CatsParse, SuperTagged)
95103

96-
object test extends Tests with CommonTestModule {
104+
object test extends Tests with UsingScalaTestModule {
97105
override def moduleDeps: Seq[JavaModule] =
98106
super.moduleDeps ++ Seq(scalacheck(crossScalaVersion))
99107

@@ -109,7 +117,7 @@ object collections extends Cross[CollectionsModule](Scala12, Scala13)
109117
class CollectionsModule(val crossScalaVersion: String) extends CommonModule {
110118
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg(CatsCore)
111119

112-
object test extends Tests with CommonTestModule {
120+
object test extends Tests with UsingScalaTestModule {
113121
override def moduleDeps: Seq[JavaModule] =
114122
super.moduleDeps ++ Seq(scalacheck(crossScalaVersion))
115123

@@ -128,7 +136,7 @@ class ScalaCheckModule(val crossScalaVersion: String) extends CommonModule {
128136
collections(crossScalaVersion)
129137
)
130138

131-
object test extends Tests with CommonTestModule {
139+
object test extends Tests with UsingScalaTestModule {
132140
override def crossScalaVersion: String = outerCrossScalaVersion
133141

134142
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg.from(PropSpec)
@@ -149,9 +157,46 @@ object shims extends Cross[ShimsModule](Scala12, Scala13)
149157
class ShimsModule(val crossScalaVersion: String) extends CommonModule {
150158
override def moduleDeps: Seq[PublishModule] = super.moduleDeps ++ Seq(core(crossScalaVersion))
151159

152-
object test extends Tests with CommonTestModule {
160+
object test extends Tests with UsingScalaTestModule {
153161
override def crossScalaVersion: String = outerCrossScalaVersion
154162

155163
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg.from(WordSpec)
156164
}
157165
}
166+
167+
object testing extends Cross[TestingModule](Scala12, Scala13)
168+
class TestingModule(val crossScalaVersion: String) extends CommonModule {
169+
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Seq(SourceCode, SuperTagged, CatsEffect, CatsCore)
170+
171+
object test extends Tests with UsingMunitTestModule {
172+
override def crossScalaVersion: String = outerCrossScalaVersion
173+
174+
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg(MUnit)
175+
}
176+
}
177+
178+
object munit extends Cross[MunitModule](Scala12, Scala13)
179+
class MunitModule(val crossScalaVersion: String) extends CommonModule {
180+
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Seq(MUnit)
181+
182+
override def moduleDeps: Seq[PublishModule] = super.moduleDeps :+ testing(crossScalaVersion)
183+
184+
object test extends Tests with UsingMunitTestModule {
185+
override def crossScalaVersion: String = outerCrossScalaVersion
186+
187+
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg(MUnit)
188+
}
189+
}
190+
191+
object scalatest extends Cross[ScalaTestModule](Scala12, Scala13)
192+
class ScalaTestModule(val crossScalaVersion: String) extends CommonModule {
193+
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Seq(ScalaTest)
194+
195+
override def moduleDeps: Seq[PublishModule] = super.moduleDeps :+ testing(crossScalaVersion)
196+
197+
object test extends Tests with UsingScalaTestModule {
198+
override def crossScalaVersion: String = outerCrossScalaVersion
199+
200+
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg.from(WordSpec)
201+
}
202+
}

collections/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Scala Commons: Collections
2+
3+
Helpers and utilities for working with various collections from the Scala standard library.
4+
5+
## Artifacts
6+
7+
### SBT
8+
```
9+
"com.github.morgen-peschke" % "commons-collections" % commonsVersion
10+
```
11+
12+
### Mill
13+
```
14+
ivy"com.github.morgen-peschke::commons-collections:$commonsVersion"
15+
```
16+
17+
## Documentation
18+
19+
### `peschke.collections.TakeUntil.syntax._`
20+
21+
Provides `TraversibleLike#takeUntil`, which is alternative to `TraversibleLike#takeWhile`.
22+
The most useful distinction between the two is how the final value is handled.
23+
24+
```scala
25+
assert((0 to 10).toList.takeWhile(_ != 5) == List(0, 1, 2, 3, 4))
26+
assert((0 to 10).toList.takeUntil(_ == 5) == List(0, 1, 2, 3, 4, 5))
27+
```
28+
29+
### `peschke.collections.range.syntax._`
30+
31+
Provides utility methods for manipulating `Range` and `NumericRange`.
32+
33+
- `grow` :: This extends a range such that (ignoring underflow) `range.grow(n).drop(n) == range`
34+
- `growRight` :: This extends a range such that (ignoring overflow) `range.growRight(n).dropRight(n) == range`
35+
- `shift` :: This shifts a range towards `Int.MaxValue` by a multiple of the range step
36+
- `unshift` :: This shifts a range towards `Int.MinValue` by a multiple of the range step
37+
- `sliceRange` :: This specialization of `NumericRange#slice` returns a `NumericRange` instead of an `IndexedSeq`

0 commit comments

Comments
 (0)