Skip to content

Commit

Permalink
refactor sidebars.
Browse files Browse the repository at this point in the history
  • Loading branch information
khajavi committed Jul 10, 2023
1 parent a5dd59c commit da4a61e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
32 changes: 13 additions & 19 deletions docs/getting-started.md → docs/basic-building-blocks.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
---
id: getting-started
title: "Getting Started"
id: basic-building-blocks
title: "Basic Building Blocks"
---

To get started, first we need to understand that a ZIO Schema is basically built-up from these three
sealed traits: `Record[R]`, `Enum[A]` and `Sequence[Col, Elem]`, along with the case class `Primitive[A]`. Every other type is just a specialisation of one of these (or not relevant to get you started).

We will take a look at them now.

## Basic Building Blocks

### Schema

The core data type of ZIO Schema is a `Schema[A]` which is **invariant in `A`** by necessity, because a Schema allows us to derive operations that produce an `A` but also operations that consume an `A` and that imposes limitations on the types of **transformation operators** and **composition operators** that we can provide based on a `Schema`.

It looks kind of like this (simplified):
Expand All @@ -24,7 +18,7 @@ sealed trait Schema[A] { self =>
}
```

### Primitives
## Primitives

To describe scalar data type `A`, we use the `Primitive[A]` data type which basically is a wrapper around `StandardType`:

Expand Down Expand Up @@ -61,7 +55,7 @@ val intSchema1: Schema[Int] = Schema[Int]
val intSchema2: Schema[Int] = Schema.primitive[Int]
```

### Fail
## Fail

To represents the absence of schema information for the given `A` type, we can use `Schema.fail` constructor, which creates the following schema:

Expand All @@ -74,9 +68,9 @@ object Schema {
}
```

### Collections
## Collections

#### Sequence
### Sequence

Often we have a type that is a collection of elements. For example, we might have a `List[User]`. This is called a `Sequence` and is represented using the `Sequence[Col, Elem, I]` type class:

Expand Down Expand Up @@ -137,7 +131,7 @@ object Person {
}
```

#### Map
### Map

Likewise, we can have a type that is a map of keys to values. ZIO Schema represents this using the following type class:

Expand Down Expand Up @@ -170,7 +164,7 @@ object Person {
}
```

#### Set
### Set

The `Set` type class is similar to `Sequence` and `Map`. It is used to represent a schema for a set of elements:

Expand Down Expand Up @@ -202,7 +196,7 @@ object Person {
}
```

### Records
## Records

Our data structures usually are composed of a lot of types. For example, we might have a `User` type that has a `name` field, an `age` field, an `address` field, and a `friends` field.

Expand Down Expand Up @@ -299,7 +293,7 @@ object Schema {
}
```

### Enumerations
## Enumerations

Other times, you might have a type that represents a list of different types. For example, we might have a type, like this:

Expand Down Expand Up @@ -364,7 +358,7 @@ object Schema {
}
```

### Optionals
## Optionals

To create a `Schema` for optional values, we can use the `Optional` type class:

Expand All @@ -383,7 +377,7 @@ Using the `Schema.option[A]` constructor, makes it easier to do so:
val option: Schema[Option[Person]] = Schema.option[Person]
```

### Either
## Either

Here is the same but for `Either`:

Expand All @@ -404,7 +398,7 @@ val eitherPersonSchema: Schema[scala.util.Either[String, Person]] =
Schema.either[String, Person]
```

### Tuple
## Tuple

Each schema has a `Schema#zip` operator that allows us to combine two schemas and create a schema for a tuple of the two types:

Expand Down
3 changes: 2 additions & 1 deletion docs/motivation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
id: motivation
title: "Understanding The Motivation Behind ZIO Schema"
title: "The Motivation Behind ZIO Schema"
sidebar_label: "Motivation"
---

ZIO Schema is a library used in many ZIO projects such as _ZIO Flow_, _ZIO Redis_, _ZIO Web_, _ZIO SQL_ and _ZIO DynamoDB_. It is all about reification of our types. Reification means transforming something abstract (e.g. side effects, accessing fields, structure) into something "real" (values).
Expand Down
5 changes: 2 additions & 3 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ const sidebars = {
collapsed: false,
link: { type: "doc", id: "index" },
items: [
"motivation",
"use-cases",
"basic-building-blocks",
{
type: "category",
label: "Writing Schema",
collapsed: true,
link: { type: "doc", id: "index" },
items: [
"manual-schema-construction",
"automatic-schema-derivation"
],
},
"motivation",
"getting-started",
"transforming-schemas",
"codecs",
"protobuf-example",
Expand Down

0 comments on commit da4a61e

Please sign in to comment.