Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs: add core.md and newtype.md - refined4s-core and Newtype #133

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/core/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"label": "refined4-core",
"position": 2,
"collapsible": true,
"collapsed": false
}
14 changes: 14 additions & 0 deletions docs/core/core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
id: core
title: "core module"
---

import DocCardList from '@theme/DocCardList';

## Import
```scala mdoc
import refined4s.*
import refined4s.syntax.*
```

<DocCardList />
6 changes: 6 additions & 0 deletions docs/core/newtype/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"label": "Newtype",
"position": 1,
"collapsible": true,
"collapsed": false
}
67 changes: 67 additions & 0 deletions docs/core/newtype/newtype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
sidebar_position: 1
id: newtype
title: "Newtype"
---

## `Import`
```scala mdoc
import refined4s.*
```

## Define Newtype

```scala
type NewtypeName = NewtypeName.Type
object NewtypeName extends Newtype[ActualType]
```

e.g.)
```scala
type Name = Name.Type
object Name extends Newtype[String]
```

## Create Value

```scala
val newtypeName = NewtypeName(value)
```

## Get Actual Value

```scala
newtypeName.value
```


## Example
```scala mdoc
type Name = Name.Type
object Name extends Newtype[String]

type Email = Email.Type
object Email extends Newtype[String]

def hello(name: Name): Unit = println(s"Hello ${name.value}")

def send(email: Email): Unit = println(s"Sending email to ${email.value}")

val name = Name("Kevin")
// Name.Type = "Kevin"
name.value

hello(name)

val email = Email("[email protected]")
// Email.Type = "[email protected]"
email.value

send(email)
```
```scala mdoc:fail
hello("Kevin")
```
```scala mdoc:fail
send("[email protected]")
```