Here is my first try at F#. My only functional experience is from JS.
This program takes a path as an argument and presents the user with numbered subdirs in that path. The user then selects one of the subdirs by entering it's number and the program opens explorer with the newest subdir of the selected subdir.
Any comments will be greatly appreciated — shorter and better syntax, conversions to point-free style, structuring...
open System
open System.IO
let toDirWithCreationDate path =
(path, Directory.GetCreationTime(path))
let getLatestSubDir =
Seq.map toDirWithCreationDate
>> Seq.sortByDescending snd
>> Seq.head
>> fst
let getNumberedSubDirTuples =
let ints = Seq.initInfinite (fun n -> n + 1)
Directory.GetDirectories
>> Seq.sort
>> Seq.zip ints
let printDirMenu =
Seq.iter (fun (a, b) -> printfn "%A %A" a b)
let openDir (dir:string) =
ignore (System.Diagnostics.Process.Start(dir))
[<EntryPoint>]
let main argv =
let path = argv |> Seq.head
let dirsSeq = getNumberedSubDirTuples path
printDirMenu dirsSeq
let dirNr = System.Console.ReadLine()
let dir =
dirsSeq
|> Seq.tryFind(fun (a,b) -> a = int(dirNr))
let latestSubdir =
match dir with
| Some d -> Directory.GetDirectories (snd d) |> getLatestSubDir |> openDir
| None -> printfn "Invalid input"
0