fthomas / fthomas/refined

Chaining refined string operation

Open
#1,080 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
1.7k
Forks
152
Avg merge
1h 20m
Merged PRs (30d)
6

Description

## Context

Hi, I would like to use `REFINED` to validate some custom input string I have. For some of the string, I would like to chain existing refined string operation as `start_with` and `uuid`.

## Exemple

The input string I have looks like `random_VALID_UUID`. At the moment I write a custom refined type as:

```
final case class PrefixedUUID[S](prefix: S)

object PrefixedUUID {

implicit def prefixedUUIDValidate[S <: String](
implicit
prefix: Witness.Aux[S]
): Validate.Plain[String, PrefixedUUID[S]] = {
Validate.fromPartial(
s => {
if (s.startsWith(prefix.value)) {
val uuid: String = s.stripPrefix(prefix.value)
require(java.util.UUID.fromString(uuid).toString == uuid.toLowerCase)
} else {
throw new Exception("Not a valid UUID")
}
},
s"""PrefixedUUID("${prefix.value}")""",
PrefixedUUID(prefix.value)
)
}
}
```

Is it the best approach to do it? Can I do it in a more generic way (chaining native refined operation)? If not, maybe can you lead me on how I can contribute a generic way to do it for the core refined library, if you are interested?

Thanks,

Contributor guide

No contributing guide indexed for this repository

Research direction

No source files, tests, or entry points are named. Start by reviewing the existing refined string operations and validation APIs to determine whether operations can be composed generically. Done would mean a documented, tested approach for validating a prefixed UUID through reusable native operations.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.