F#: Is there an infix operator that could allow to reuse an object methods over subsequent |>?

Viewed 110

A colleague of mine is converting the C# below to F#:

string GetLatestTestResultXmlPath() =>
    new DirectoryInfo(Path.Combine(projFolder, "TestResults"))
        .GetDirectories()
        .OrderByDescending(d => d.LastWriteTime)
        .First()
        .GetDirectories("Out")
        .First()
        .GetFiles("*.log")
        .First()
        .FullName

The most natural result he got was:

let latestTestResultFilePath =
    (new DirectoryInfo(Path.Combine(projFolder, "TestResults")))
        .GetDirectories()
        .OrderByDescending(fun d -> d.LastWriteTime)
        .First()
        .GetDirectories("Out")
        .First()
        .GetFiles("*.log")
        .First()
        .FullName

While it's completely fine, he was wondering whether he could get something that using an infix operator over subsequent pipe forward |> operators. Something along those lines:

let latestTestResultFilePath =
    let directoryInfo = new DirectoryInfo(Path.Combine(projFolder, "TestResults"))
    directoryInfo 
    |> (// magic operator here).GetDirectories()
    |> (// magic operator here).OrderByDescending(fun d -> d.LastWriteTime)
    |> (// magic operator here).First()
    |> (// magic operator here).GetDirectories("Out")
    |> (// magic operator here).First()
    |> (// magic operator here).GetFiles("*.log")
    |> (// magic operator here).First()
    |> (// magic operator here).FullName

I also got curious, and I am suspecting it might possible with an infix operator capable of doing, but not sure which one can actually fit that role.

This is purely out of curiosity.

1 Answers

This is not possible because you are using LINQ which is static extension.

Related