Skip to content

Commit

Permalink
Merge pull request #5 from bishabosha/fix-examples
Browse files Browse the repository at this point in the history
fix examples in docs
  • Loading branch information
bishabosha authored Oct 22, 2023
2 parents 847ef0c + 3dfa7f2 commit 424bf6b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def nameOrdinalPairs[E: EnumMirror]: Map[String, Int] =
def safeLookup[E: EnumMirror](name: String): Option[E] =
EnumMirror[E].valueOf(name)
def safeLookup[E: EnumMirror](ordinal: Int): Option[E] =
EnumMirror[E].fromOrdinal(name)
EnumMirror[E].fromOrdinal(ordinal)

// assert that name/ordinal exists for convenience
def unsafeLookup[E: EnumMirror](name: String): E =
EnumMirror[E].unsafeValueOf(name)
EnumMirror[E].valueOfUnsafe(name)
def unsafeLookup[E: EnumMirror](ordinal: Int): E =
EnumMirror[E].unsafeFromOrdinal(name)
EnumMirror[E].fromOrdinalUnsafe(ordinal)
```

`given` instances of `EnumMirror` are not provided automatically, you must explicitly opt in as follows:
Expand Down
8 changes: 4 additions & 4 deletions _docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Type classes are provided in the `enumextensions` package.

See the above use cases in action below:

```scala sc:nocompile
```scala
import enumextensions.EnumMirror

def enumName[E: EnumMirror]: String =
Expand All @@ -33,13 +33,13 @@ def nameOrdinalPairs[E: EnumMirror]: Map[String, Int] =
def safeLookup[E: EnumMirror](name: String): Option[E] =
EnumMirror[E].valueOf(name)
def safeLookup[E: EnumMirror](ordinal: Int): Option[E] =
EnumMirror[E].fromOrdinal(name)
EnumMirror[E].fromOrdinal(ordinal)

// assert that name/ordinal exists for convenience
def unsafeLookup[E: EnumMirror](name: String): E =
EnumMirror[E].unsafeValueOf(name)
EnumMirror[E].valueOfUnsafe(name)
def unsafeLookup[E: EnumMirror](ordinal: Int): E =
EnumMirror[E].unsafeFromOrdinal(name)
EnumMirror[E].fromOrdinalUnsafe(ordinal)
```

`given` instances of `EnumMirror` are not provided automatically, you must explicitly opt in as follows:
Expand Down
1 change: 1 addition & 0 deletions project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
//> using test.dep org.scalameta::munit:1.0.0-M10
//> using option -Xcheck-macros
//> using options -siteroot ${.}
//> using options -project enum-extensions

0 comments on commit 424bf6b

Please sign in to comment.