Skip to content

[API Proposal]: trySscanf active pattern #635

Closed
@Happypig375

Description

@Happypig375

Background and motivation

There is (|Parsed|_|) wrapping tryParse. There should be a similar need for matching a string with a printf format instead of directly parsing.

Separated from #620 at the request of @gusty

API Proposal

The only unresolved question about this API is the name.

let (|Parsedf|_|) pf = trySscanf pf // doesn't read well but is in line with names like trySscanf
let (|Like|_|) pf = trySscanf pf // The "Like" operator of SQL and Visual Basic which also does simple string pattern matching
let (|Scanned|_|) pf = trySscanf pf // Scanned is to trySscanf like Parsed is to tryParse

API Usage

match "123" with
| Parsedf "%c%c%c" ('1', '2', '3') -> printf "yes"
| _ -> failwith "impossible"

Alternative Designs

No response

Risks

It's an API with heavy STRP type inference like most of F#+. Error messages are an abomination.

Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?

Yes, please assign this issue to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions