Thursday, June 10, 2010

F# Tricks: Collecting Some Optional Values

Skip this post if you have no idea what F# is, and think LINQ is stupid.When you map inputs to outputs with a function that can return None, or Some Output, you get an annoying issue of having a list containing Nones, and Somes. For example: // Contains both encrypted and un-encrypted files: let listOfFiles:Seq// Return a decrypted File, or None if the file can't be decrypted.let decryptFile file match file with | isFileDecryptable file -> Some DecryptFile file | _ -> None// decryptedFiles contains Nones, intertwined with some Some DecryptedFileslet decryptedFiles = listOfFiles |> Seq.map...

Page 1 of 2312345Next