Skip to content

Commit 80298d5

Browse files
Relocates examples (both Kotlin and Scala) (#111)
* Relocates examples (both Kotlin and Scala) * Adds the Book Scala example
1 parent 8118c14 commit 80298d5

33 files changed

+87
-18
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ could be useful if you use Gradle.
4343
- In Scala (work in progress)
4444

4545
You can also have a look at our
46-
[examples](https://github.com/xebia-functional/xef/tree/main/example/src/main/kotlin/com/xebia/functional/xef/auto)
46+
[examples](https://github.com/xebia-functional/xef/tree/main/examples/kotlin/src/main/kotlin/com/xebia/functional/xef/auto)
4747
to have a feeling of how using the library looks like.
File renamed without changes.

examples/scala/.scalafmt.conf

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# tune this file as appropriate to your style! see: https://olafurpg.github.io/scalafmt/#Configuration
2+
3+
version = "3.7.1"
4+
5+
runner.dialect = "scala3"
6+
7+
maxColumn = 150
8+
9+
continuationIndent.callSite = 2
10+
11+
newlines {
12+
sometimesBeforeColonInMethodReturnType = false
13+
}
14+
15+
align {
16+
arrowEnumeratorGenerator = false
17+
ifWhileOpenParen = false
18+
openParenCallSite = false
19+
openParenDefnSite = false
20+
21+
tokens = ["%", "%%"]
22+
}
23+
24+
docstrings.style = Asterisk
25+
26+
rewrite {
27+
rules = [SortImports, RedundantBraces]
28+
redundantBraces.maxLines = 1
29+
}
30+
31+
optIn {
32+
breaksInsideChains = true
33+
}
34+
35+
project.excludeFilters = [
36+
"metals.sbt"
37+
]

examples/scala/build.gradle.kts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@file:Suppress("DSL_SCOPE_VIOLATION")
2+
3+
plugins {
4+
scala
5+
alias(libs.plugins.scala.multiversion)
6+
alias(libs.plugins.spotless)
7+
}
8+
9+
java {
10+
sourceCompatibility = JavaVersion.VERSION_19
11+
targetCompatibility = JavaVersion.VERSION_19
12+
toolchain {
13+
languageVersion = JavaLanguageVersion.of(19)
14+
}
15+
}
16+
17+
dependencies {
18+
implementation(projects.xefCore)
19+
implementation(projects.xefScala)
20+
implementation(projects.kotlinLoom)
21+
implementation(libs.circe.parser)
22+
}
23+
24+
tasks.withType<Test>().configureEach {
25+
useJUnit()
26+
}
27+
28+
spotless {
29+
scala {
30+
scalafmt("3.7.1").configFile(".scalafmt.conf").scalaMajorVersion("2.13")
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.xebia.functional.xef.scala.auto
2+
3+
import com.xebia.functional.auto.*
4+
import com.xebia.functional.scala.auto.ScalaSerialDescriptor
5+
import com.xebia.functional.scala.auto.ScalaSerialDescriptorContext.given
6+
import io.circe.Decoder
7+
8+
private final case class Book(name: String, author: String, summary: String) derives ScalaSerialDescriptor, Decoder
9+
10+
@main def runBook: Unit =
11+
val book = AI(prompt[Book]("To Kill a Mockingbird by Harper Lee summary."))
12+
println(s"To Kill a Mockingbird summary:\n ${book.summary}")

scala/src/main/scala/com/xebia/functional/examples/auto/Book.scala

-16
This file was deleted.

settings.gradle.kts

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
1717

1818
rootProject.name = "xef"
1919

20-
include("example")
20+
include("xef-kotlin-examples")
21+
project(":xef-kotlin-examples").projectDir = file("examples/kotlin")
22+
23+
include("xef-scala-examples")
24+
project(":xef-scala-examples").projectDir = file("examples/scala")
2125

2226
include("kotlin-loom")
2327

0 commit comments

Comments
 (0)