Skip to content

Commit e27b6f3

Browse files
committed
Examples
1 parent bd76e87 commit e27b6f3

20 files changed

Lines changed: 1642 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,4 @@ logs/
3737
/.coursier/
3838
/.bsp/
3939
/.home/
40-
examples/
41-
flowforge-docs/
42-
benchmarks/
43-
integration-tests/
40+

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ addCommandAlias("ffRunSpark", "engines-spark/run") // Spark local[*], DQ + Delta
362362

363363
// Ensure examples compiles after contracts-sdk (belt-and-suspenders ordering)
364364
examples / Compile / compile := (examples / Compile / compile)
365-
.dependsOn(contractsSdk / Compile / compile)
365+
.dependsOn(contractsSdk / Compile / compile, core / Compile / compile)
366366
.value
367367

368368
// ===== COMPILE-FAIL TESTS MODULE =====

docs/diagrams/compile-time-contracts/src/flowchart.mmd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
config:
3+
theme: 'neutral'
4+
---
5+
16
flowchart TD
27
A[Developer writes types]
38
A -->|Producer record| A1[Out record]
@@ -55,5 +60,4 @@ flowchart TD
5560
R1[No overhead] --> R2[Optional runtime guards]
5661
R2 --> R3[Quality rules]
5762
end
58-
5963
B --> R
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# BYO‑F Examples
2+
3+
This page demonstrates using FlowForge with different effect systems using the same core APIs.
4+
5+
## IO (Cats‑Effect)
6+
7+
```scala
8+
import cats.effect.IO
9+
import com.flowforge.core.algebra.EffectSystem
10+
import com.flowforge.core.instances.EffectInstances.catsEffectSystemInstance
11+
import com.flowforge.core.algebra.FlowforgeResource
12+
13+
val F = EffectSystem[IO]
14+
val res: FlowforgeResource[IO, java.io.ByteArrayOutputStream] =
15+
FlowforgeResource.make(F.delay(new java.io.ByteArrayOutputStream()))(s => F.delay(s.close()))
16+
17+
res.use { s => F.delay(s.write(1)) }
18+
```
19+
20+
## ZIO Task
21+
22+
```scala
23+
import zio._
24+
import com.flowforge.core.algebra.EffectSystem
25+
import com.flowforge.core.instances.EffectInstances.zioEffectSystemInstance
26+
import com.flowforge.core.algebra.FlowforgeResource
27+
28+
val F = EffectSystem[Task]
29+
val r: FlowforgeResource[Task, java.io.ByteArrayInputStream] =
30+
FlowforgeResource.make(F.delay(new java.io.ByteArrayInputStream(Array[Byte](1,2,3))))(s => F.delay(s.close()))
31+
32+
val prog: Task[Int] = r.use(is => F.delay(is.read()))
33+
```
34+
35+
## Pipeline with BYO‑F
36+
37+
```scala
38+
import com.flowforge.core.PipelineBuilder
39+
import com.flowforge.core.algebra.EffectSystem
40+
import com.flowforge.core.types._
41+
import com.flowforge.core.contracts.{ SchemaConforms, SchemaPolicy }
42+
43+
final case class User(id: Long, email: String, age: Int)
44+
implicit val conforms: SchemaConforms[User, User, SchemaPolicy.Exact] = implicitly
45+
46+
def buildPipeline[F[_]: EffectSystem](src: DataSource, snk: DataSink, dao: com.flowforge.core.algebra.DataAlgebra[F]) =
47+
PipelineBuilder[F]("byo-pipeline")
48+
.addTypedSource[User, User, SchemaPolicy.Exact](TypedSource(src), _ => EffectSystem[F].pure(User(0, "x@y", 18)))
49+
.addTransform[User](u => EffectSystem[F].pure(u.copy(age = u.age + 1)))
50+
.addTypedSink[User, SchemaPolicy.Exact](TypedSink(snk), (_, d) => dao.read[User](src).flatMap(ds => dao.write(ds, d)).void)
51+
.build()
52+
```
53+

0 commit comments

Comments
 (0)