-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #539 from cb372/cats-NonEmptyList-syntax
Add syntax for Cats NonEmptyList
- Loading branch information
Showing
2 changed files
with
23 additions
and
4 deletions.
There are no files selected for viewing
11 changes: 9 additions & 2 deletions
11
modules/cats/shared/src/main/scala/eu/timepit/refined/cats/syntax.scala
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,14 +1,21 @@ | ||
package eu.timepit.refined.cats | ||
|
||
import cats.data.ValidatedNel | ||
import cats.data.{NonEmptyList, ValidatedNel} | ||
import cats.syntax.either._ | ||
import eu.timepit.refined.api.RefinedTypeOps | ||
import eu.timepit.refined.types.numeric.PosInt | ||
|
||
object syntax extends CatsRefinedTypeOpsSyntax | ||
object syntax extends CatsRefinedTypeOpsSyntax with CatsNonEmptyListSyntax | ||
|
||
trait CatsRefinedTypeOpsSyntax { | ||
implicit class CatsRefinedTypeOps[FTP, T](rtOps: RefinedTypeOps[FTP, T]) { | ||
def validate(t: T): ValidatedNel[String, FTP] = | ||
rtOps.from(t).toValidatedNel | ||
} | ||
} | ||
|
||
trait CatsNonEmptyListSyntax { | ||
implicit class CatsNonEmptyListRefinedOps[A](nel: NonEmptyList[A]) { | ||
def refinedSize: PosInt = PosInt.unsafeFrom(nel.size) | ||
} | ||
} |
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