F # style - prefer () or <|

Which of these two alternatives do you most often use, and which is more "idiomatic"?

  • f arg (obj.DoStuff ())
  • f arg <| obj.DoStuff ()
+3
source share
4 answers

In general, I do not know that one or the other is more idiomatic.

Personally, the only time I use <| with a raise:

raise <| new FooException("blah")

In addition, I always use parens. Note that since most F # codes use curries functions, this usually does not imply any “extra” pairs:

f arg (g x y)

This is when you get into non-card functions and constructors, and also the fact that it starts to become less pretty:

f arg (g(x,y))

, , , F #, ;

f g()

,

f g ()

,

f (g())

( ). , .

+5

, |> , F # .

,

[1; 2; 3] |> (fun x -> x.Length*2)

,

(fun x -> x.Length*2) [1; 2; 3]

" ".

+2

() , , , < | | , () .

0

, | > , .

0

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


All Articles