F #: any way to use member functions as unrelated functions?

Is there a way to extract member functions and use them as F # functions? I would like to write the following:

mystring |> string.Split '\n' |> Array.filter (string.Length >> (=) 0 >> not) 

The code above works if you [let]

 let mystring = "ac\nb\n" let stringSplit (y:char) (x:string) = x.Split(y) let stringLength (x:string) = x.Length mystring |> stringSplit '\n' |> Array.filter (stringLength >> (=) 0 >> not) 
+4
source share
2 answers

This is very similar to the question I asked a few days ago (but your wording is better). Consensus seems to be:

  • Not.
  • Perhaps in the future, the syntax string#Split , "foo"#Split or just #Split (type-inferred) will be added. But Don Syme’s suggestion , which Thomas has contacted since 2007, so I don’t know how possible it is - is probably about as likely as the specific syntax of laziness, I would suggest.

Edit:

I think "foo"#Split can also be written as string#Split "foo" . I think it depends on how flexible you define the # syntax.

+5
source

Using

 (fun x -> x.Member ...) 

till. for instance

 someString |> (fun s -> s.Split "\n") |> ... 
+3
source

Source: https://habr.com/ru/post/1312592/


All Articles