Shortcut F # for calling a method on an object in lambda

I think this is somewhat related to this question , but not sure, and since there is no real answer, here I go:

in Scala you can write code there, for example:

aStringArray.map(_.toUpperCase())

which is short for:

aStringArray.map(s => s.toUpperCase())

Is there anything similar in F # or a way to implement it (without an operator? Or heavy use of reflection)? If this is not possible, is this considered a language for a future version? (I'm really verbosity of functions just to call a method on an object in a closure!).

+5
source share
4 answers

, F # _.Foo() Scala, -, fun a -> a.Foo().

, F #, F #. (, , _ + 10, ?). , , ... , !

, F # ( OO), ( ). , F # ( ). :.

type Foo(a:int) = 
  member x.Add(b:int) = a + b

// Attribute allows you to define module with the same name
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Foo = 
  let add b (v:Foo) = v.Add(b)

fun v -> v.Add(10), Foo.add 10 . , String F #, .

+6

fun s -> s.ToUpper() , ​​ Scala.

, _ Scala ( ) F #, , , ,

filter ((=) 42) list
+5

, , , ( ), , :

let toupper (s:string) = s.ToUpper()
aStringArray.map toupper
-1
source

All Articles