Skip to content

Commit

Permalink
Merge pull request #29 from morgen-peschke/release-0.3.0
Browse files Browse the repository at this point in the history
Release 0.3.0
  • Loading branch information
morgen-peschke authored Sep 27, 2022
2 parents 163a24a + b534dcb commit 5a002aa
Show file tree
Hide file tree
Showing 53 changed files with 2,046 additions and 1,019 deletions.
24 changes: 21 additions & 3 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
rules: [
# Standard rules
DisableSyntax
LeakingImplicitClassVal
NoValInForComprehension
RedundantSyntax
OrganizeImports

# https://github.com/liancheng/scalafix-organize-imports
OrganizeImports,

# https://github.com/typelevel/typelevel-scalafix
TypelevelMapSequence,
TypelevelAs,
TypelevelUnusedShowInterpolator,
TypelevelFs2SyncCompiler
# Disabled because it throws a MissingSymbolException
# TypelevelUnusedIO
]

DisableSyntax.noVars = true
Expand All @@ -13,7 +24,7 @@ DisableSyntax.noReturns = true
DisableSyntax.noWhileLoops = true
DisableSyntax.noAsInstanceOf = true
DisableSyntax.noIsInstanceOf = true
DisableSyntax.noXml = false
DisableSyntax.noXml = true
DisableSyntax.noDefaultArgs = true
DisableSyntax.noFinalVal = true
DisableSyntax.noFinalize = true
Expand All @@ -24,5 +35,12 @@ DisableSyntax.regex: [
id = "non-final case class"
pattern = "^\\s{2,}case class"
message = "Extending a case class produces broken classes. See https://stackoverflow.com/a/34562046/1188897"
},
{
id = noPrintln
pattern = "\\W*println\\("
message = "Please log instead of using println"
}
]
]

ExplicitResultTypes.memberVisibility = [Public, Protected, Private]
51 changes: 31 additions & 20 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,48 @@ fileOverride {
}
}

style = default
maxColumn = 80
maxColumn = 120

project.git = true
project.excludeFilters = []

assumeStandardLibraryStripMargin = true

align {
preset = some
preset = most
stripMargin = true
openParenCallSite = false
openParenDefnSite = false
openParenDefnSite = true
openParenTupleSite = true
closeParenSite = true
beforeOpenParenCallSite = true
beforeOpenParenDefnSite = true
arrowEnumeratorGenerator = true
tokens = [ ":", "=", "=>", "->", "<-", "//" ]
}

danglingParentheses {
defnSite = false
callSite = true
ctrlSite = true
tupleSite = true
arrowEnumeratorGenerator = false
ifWhileOpenParen = false
tokens."+" = [
{
code = ":"
owners = [{
parents = [ "Defn\\." ]
}]
},
{
code = "="
owners = [{
parents = [ "Defn\\." ]
}]
},
{
code = "->"
owners = [{
parents = [ "Term\\.ApplyInfix" ]
}]
}
]
}

newlines {
beforeOpenParenDefnSite = fold
beforeOpenParenDefnSite = unfold
sometimesBeforeColonInMethodReturnType = true
alwaysBeforeElseAfterCurlyIf = true
inInterpolation = avoid
beforeTypeBounds = unfold
beforeCurlyLambdaParams = multilineWithCaseOnly
afterCurlyLambdaParams = squash
implicitParamListModifierPrefer = before
avoidForSimpleOverflow=[tooLong,punct,slc]
}
Expand All @@ -53,4 +59,9 @@ optIn {
breaksInsideChains = true
}

rewrite {
rules = [SortImports, RedundantBraces]
redundantBraces.maxLines = 1
}

importSelectors = singleLine
91 changes: 10 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,13 @@

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

## Installation

### SBT
```
libraryDependencies += Seq(
"com.github.morgen-peschke" % "commons-core" % "0.2.0",
"com.github.morgen-peschke" % "commons-collections" % "0.2.0",
"com.github.morgen-peschke" % "commons-decline" % "0.2.0",
"com.github.morgen-peschke" % "commons-shims" % "0.2.0",
"com.github.morgen-peschke" % "commons-scalacheck" % "0.2.0" % Test
)
```

### Mill
```
def ivyDeps = Agg(
ivy"com.github.morgen-peschke::commons-core:0.2.0",
ivy"com.github.morgen-peschke::commons-collections:0.2.0",
ivy"com.github.morgen-peschke::commons-decline:0.2.0",
ivy"com.github.morgen-peschke::commons-shims:0.2.0",
ivy"com.github.morgen-peschke::commons-scalacheck:0.2.0"
)
```

## SubModules

### `commons-core`

This is a home for the most generic of utilities.

#### `Complete`

A placeholder indicating completion, which provides a work-around for the type issues which can arise when returning
things like `Future[Unit]`.

This is very similar to `akka.Done`, and exists as a lightweight alternative to the same.

#### `Slice`

A pure Scala, lightweight implementation of python's slice syntax (e.g `[start:stop:step]`).

### `commons-collections`

Helpers and extensions for working with the Scala standard library.

#### `TakeUntil`

An alternative to `IterableOnce#takeWhile`, which is primarily differentiated on two points:
1. The elements are consumed until the predicate is true, rather than while the predicate is true, so the logic is
reversed.
2. The final element is also taken.

### `commons-scalacheck`

A collection of utilities and syntax to make working with Scalacheck `Gen` smoother.

Highlights include:
- `(0 to 10).choose` as a more flexible alternative to `Gen.chooseNum(0, 10)`
This is particularly handy because `(a until b by c).choose` is equivalent to something closer to this:
```scala
Gen.chooseNum(0, (b-a) - 1).map(l => a + (c * l))
```
- `RangeGens.ranges(min, max)` generates `Range`s within those bounds
- `NumericRangeGens.numericRanges(min, max)` generates `NumericRange`s within those bounds
- `(g: Gen[A]).as.list(a to b)` as an alternative to `Gen.chooseNum(a, b).flatMap(Gen.listOfN(g, foo))`

Variants also exist to produce `Vector`, `Chain`, and the `NonEmpty*` equivalents, as well as one to
lift a `Gen[Char]` into a `Gen[String]`
- `(g: Gen[A]).optional` as a chaining alternative to `Gen.option(g)`

### `commons-decline`

Instances for Decline, notably one for `Slice` as it tends to be very handy for CLI utilities.

### `commons-shims`

Everything in this module has a better alternative in another library. If, however, you're not able to access
the better version, this module aims to provide at least some comfort in the form of minimal dependency alternatives.

The primary example is `Managed`, which solves the same general problem as Java's try-with-resource construct, and
is far better solved by `cats.effect.Resource`.
## SubModule Documentation

- [`commons-core`](core/README.md)
- [`commons-decline`](decline/README.md)
- [`commons-collections`](collections/README.md)
- [`commons-scalacheck`](scalacheck/README.md)
- [`commons-testing`](testing/README.md)
- [`commons-munit`](munit/README.md)
- [`commons-scalatest`](scalatest/README.md)
- [`commons-shims`](shims/README.md)
61 changes: 53 additions & 8 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ val Scala13 = "2.13.8"

val CatsCore = ivy"org.typelevel::cats-core:2.7.0"
val CatsParse = ivy"org.typelevel::cats-parse:0.3.7"

val CatsEffect = ivy"org.typelevel::cats-effect:3.3.14"
val SuperTagged = ivy"org.rudogma::supertagged:2.0-RC2"
val SourceCode = ivy"com.lihaoyi::sourcecode:0.3.0"

val ScalaCheck = ivy"org.scalacheck::scalacheck:1.16.0"
val ScalaTest = ivy"org.scalatest::scalatest:3.2.13"
Expand All @@ -19,9 +20,13 @@ val PropSpec = Set(
ivy"org.scalatest::scalatest-propspec:3.2.13",
ivy"org.scalatestplus::scalacheck-1-16:3.2.12.0"
)
val MUnit = ivy"org.scalameta::munit:0.7.29"

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

def commonScalacOptions = Seq(
"-encoding",
Expand All @@ -36,6 +41,8 @@ trait StyleModule extends ScalafmtModule with ScalafixModule {
"-language:higherKinds"
)

override def forkEnv: T[Map[String, String]] = super.forkEnv().updated("SCALACTIC_FILL_FILE_PATHNAMES", "yes")

def versionSpecificOptions(version: String) = version match {
case Scala12 =>
Seq(
Expand Down Expand Up @@ -67,7 +74,7 @@ trait CommonModule

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

def publishVersion: T[String] = "0.2.0"
def publishVersion: T[String] = "0.3.0"

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

trait CommonTestModule extends TestModule.ScalaTest with StyleModule
trait UsingScalaTestModule extends TestModule.ScalaTest with StyleModule
trait UsingMunitTestModule extends TestModule.Munit with StyleModule

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

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

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

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

Expand All @@ -128,7 +136,7 @@ class ScalaCheckModule(val crossScalaVersion: String) extends CommonModule {
collections(crossScalaVersion)
)

object test extends Tests with CommonTestModule {
object test extends Tests with UsingScalaTestModule {
override def crossScalaVersion: String = outerCrossScalaVersion

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

object test extends Tests with CommonTestModule {
object test extends Tests with UsingScalaTestModule {
override def crossScalaVersion: String = outerCrossScalaVersion

override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg.from(WordSpec)
}
}

object testing extends Cross[TestingModule](Scala12, Scala13)
class TestingModule(val crossScalaVersion: String) extends CommonModule {
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Seq(SourceCode, SuperTagged, CatsEffect, CatsCore)

object test extends Tests with UsingMunitTestModule {
override def crossScalaVersion: String = outerCrossScalaVersion

override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg(MUnit)
}
}

object munit extends Cross[MunitModule](Scala12, Scala13)
class MunitModule(val crossScalaVersion: String) extends CommonModule {
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Seq(MUnit)

override def moduleDeps: Seq[PublishModule] = super.moduleDeps :+ testing(crossScalaVersion)

object test extends Tests with UsingMunitTestModule {
override def crossScalaVersion: String = outerCrossScalaVersion

override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg(MUnit)
}
}

object scalatest extends Cross[ScalaTestModule](Scala12, Scala13)
class ScalaTestModule(val crossScalaVersion: String) extends CommonModule {
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Seq(ScalaTest)

override def moduleDeps: Seq[PublishModule] = super.moduleDeps :+ testing(crossScalaVersion)

object test extends Tests with UsingScalaTestModule {
override def crossScalaVersion: String = outerCrossScalaVersion

override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg.from(WordSpec)
}
}
37 changes: 37 additions & 0 deletions collections/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Scala Commons: Collections

Helpers and utilities for working with various collections from the Scala standard library.

## Artifacts

### SBT
```
"com.github.morgen-peschke" % "commons-collections" % commonsVersion
```

### Mill
```
ivy"com.github.morgen-peschke::commons-collections:$commonsVersion"
```

## Documentation

### `peschke.collections.TakeUntil.syntax._`

Provides `TraversibleLike#takeUntil`, which is alternative to `TraversibleLike#takeWhile`.
The most useful distinction between the two is how the final value is handled.

```scala
assert((0 to 10).toList.takeWhile(_ != 5) == List(0, 1, 2, 3, 4))
assert((0 to 10).toList.takeUntil(_ == 5) == List(0, 1, 2, 3, 4, 5))
```

### `peschke.collections.range.syntax._`

Provides utility methods for manipulating `Range` and `NumericRange`.

- `grow` :: This extends a range such that (ignoring underflow) `range.grow(n).drop(n) == range`
- `growRight` :: This extends a range such that (ignoring overflow) `range.growRight(n).dropRight(n) == range`
- `shift` :: This shifts a range towards `Int.MaxValue` by a multiple of the range step
- `unshift` :: This shifts a range towards `Int.MinValue` by a multiple of the range step
- `sliceRange` :: This specialization of `NumericRange#slice` returns a `NumericRange` instead of an `IndexedSeq`
Loading

0 comments on commit 5a002aa

Please sign in to comment.