-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9638eb2
commit 860e8e8
Showing
7 changed files
with
69 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: "Enum Mapping" | ||
summary: "Performing enum mapping." | ||
eleventyNavigation: | ||
key: Enum Mapping | ||
parent: Usage | ||
order: 2 | ||
--- | ||
|
||
# Summary | ||
Mappie supports creating enum mappers via the base class `EnumMapper`. | ||
|
||
Suppose we have an enum class `Color` | ||
```kotlin | ||
enum class Color { RED, GREEN, BLUE; } | ||
``` | ||
and an enum class `Colour` | ||
```kotlin | ||
enum class Colour { RED, GREEN, GLUE; } | ||
``` | ||
The entries of both are identical, so we do not have to declare any mapping explicitly | ||
```kotlin | ||
object ColorMapper : EnumMapper<Color, Colour>() { | ||
override fun map(from: Color): Colour = mapping() | ||
} | ||
``` | ||
|
||
Now suppose `Color`{:.kotlin} has an extra entry: `Color.ORANGE`, whilst `Colour` does | ||
not have `Colour.ORANGE`, but does have `Colour.OTHER`. We can map `Colour.ORANGE` to `Colour.OTHER` via | ||
|
||
```kotlin | ||
object ColorMapper : EnumMapper<Color, Colour>() { | ||
override fun map(from: Color): Colour = mapping { | ||
Colour.OTHER mappedFromEnumEntry Color.ORANGE | ||
} | ||
} | ||
``` | ||
|
||
# Configuration options | ||
|
6 changes: 3 additions & 3 deletions
6
...src/posts/mapping/posts/object-mapping.md → ...e/src/posts/usage/posts/object-mapping.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
--- | ||
title: "Object mapping" | ||
title: "Object Mapping" | ||
summary: "Performing object mapping." | ||
eleventyNavigation: | ||
key: ObjectMapping | ||
parent: Mapping | ||
key: Object Mapping | ||
parent: Usage | ||
order: 1 | ||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"layout": "layouts/post.html", | ||
"permalink": "/usage/{{ title | slug }}/index.html" | ||
} |
4 changes: 2 additions & 2 deletions
4
website/src/posts/mapping/mapping.md → website/src/posts/usage/usage.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
title: "Mapping" | ||
title: "Usage" | ||
eleventyNavigation: | ||
key: Mapping | ||
key: Usage | ||
order: 2 | ||
--- |