Repeated field check using F # (inside the azure function)

I have an azure function based on the http post template. I expanded json from 1 prop to 3.

let versionJ = json.["version"]
let customerIdJ = json.["customerId"]
let stationIdJ = json.["stationId"]
match isNull versionJ with

What is the best way to check for null in all three? Use a tulip?

match isNull versionJ, isNull customerIdJ, isNull stationIdJ with
+4
source share
3 answers

It depends on what you want to verify for sure. If you want to see that there is at least 1 zero, you can do the following:

let allAreNotNull = [versionJ; customerIdJ; stationIdJ] 
                    |> List.map (not << isNull)
                    |> List.fold (&&) true

If you want to check that they are all zeros, you can do the following:

let allAreNull = [versionJ; customerIdJ; stationIdJ]
                 |> List.map isNull
                 |> List.fold (&&) true

Update

You can also replace it with List.forall:

[versionJ; customerIdJ; stationIdJ]
|> List.forall (not << isNull)


[versionJ; customerIdJ; stationIdJ]
|> List.forall isNull
+2
source

, , , , isNull :

let inline isNull value = (value = null)

:

if isNull versionJ && isNull customerIdJ && isNull stationIdJ then
    // your code
+2

Another approach is inspired by the Applications that apply createRecord, if all the elements (<>) null.

let createRecord v c s  = v, c, s

let inline ap v f =
  match f, v with
  | _     , null
  | None  , _     -> None
  | Some f, v     -> f v |> Some

let v =
  Some createRecord 
  |> ap json.["version"]
  |> ap json.["customerId"]
  |> ap json.["stationId"]
+2
source

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


All Articles