Skip to content

How to implement filter for custom type? #216

@cmeeren

Description

@cmeeren

I have a custom type Skippable<'a> that's just like Option (but semantically different). It's defined in a separate library.

In my code, I want to extend this type to support filter. With that in mind, I have tried the following, but none of them work (I have also tried switching the arguments):

type Skippable<'a> with
  static member Filter(s, p) = Skippable.filter p s
type Skippable<'a> with
  member this.Filter(p) = Skippable.filter p this
type FSharpPlus.Control.Filter with
  static member Filter(s, p) = Skippable.filter p s

In all cases, when I try to use filter on a Skippable<_> value, I get a compiler error saying

No overloads match for method 'ToSeq'.

Is this because I am using extension members? Is it possible to add support to custom types using extension members?

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