Is there a conditional access statement in F # (similar to the new? In C #)?

Now that C # 6 will finally have this long-awaited ?. operator , is there something similar in F #? And I'm not talking about ? The operator .

+6
source share
3 answers

In functional languages, conditional / compositional traversal, especially in nested structures, is usually modeled using the concept of lenses, which is explained by a brief example in this SO stream .

In the environment of F # Aether ; see the introduction and guide article that builds on Lens Support, designed and written by Maurizio Scheffer at FSharpx here .

+4
source

Idiomatic F # has no null values ​​at all, so what will it be? In F #, the most common way to simulate a lack of value is to use option .

When I need to interact with .NET code that can return null , I convert it to a parameter as soon as possible using this function:

 let toOption (x : obj) = match x with | null -> None | _ -> Some x 

Once you have your value modeled as an option , you can compose it, for example. Option.map , and this serves the same purpose (but better and safer) than the proposed C # operator.

+13
source

You can remove the null option first. And then you can use the parameter calculation expression to achieve the same.

+3
source

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


All Articles