What does a double exclamation mark (!!) in Fsharp

2019-02-24 04:40发布

问题:

I've come across the following code and can not understand what operation the double exclamation marks provide. This code-snipet is from a FAKE script used in a CICD system. Microsoft's Symbol and Operator Reference does not list this operator, nor can I find it in FAKE's API Reference.

  !! (projectPackagePath + "/*.zip")
    |> Seq.iter(fun path ->
      trace ("Removing " + path)
      ShellExec tfCommand ("delete " + path + " /noprompt")

Another example of usage

let buildLabelFiles = 
    !!(labelPath @@ "*.txt")

回答1:

The !! operator takes a file pattern and returns a collection of files matching the pattern.

For example, if you want to print all text files in the current folder, you can write:

for file in !! "*.txt" do
  printfn "%s" file

If you look at the operator definition in the source code, you can see that it is just an alias for creating a FileIncludes value (see the type definition) that includes files given by the specified pattern. The FileIncludes type implements IEnumerable, so you can iterate over the files, but you can do a couple of other things with FileIncludes such as combining two file sets using ++ or removing some files from a file set using --.



标签: f# f#-fake