Skip to content

Option.getOrFailf - how to use this function? #357

Description

@pmbanka

Description

I am trying to use this function

let inline getOrFailF fmt =
function
| Some x -> x
| None -> failwithf fmt

but it seems to me that it does not do what I expect it to do... consider this snippet that fails to compile:

let x = Some 1

let _ = x |> Option.getOrFailF "asdf %b" true // error FS0001: Type mismatch. Expecting a     'int option -> 'a'  but given a    'bool -> 'b'

let _ = x |> (Option.getOrFailF ("asdf %b" true)) // error FS0003: This value is not a function and cannot be applied

My question is - is this an expected behaviour of this function? How should I use it correctly?

I know there is a workaroud like that:
let _ = x |> Option.getOrFail (sprintf "asdf %b" true)
but I wanted to avoid writing sprintf, hence the question.

Pinging @sideeffffect

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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