I've played with F# for over a year, but I've only recently begun tentatively using it for professional work. I'm concerned that my c-style OOP principles are blinding me to the advantages of a functional language. I wrote the following code and it works just fine, but I feel like I'm just not quite using the language to its full potential. It still feels too C#-ish to me.
open System
open System.Configuration
open System.DirectoryServices
open System.DirectoryServices.ActiveDirectory
type adEntry =
static member prop (name:string) (entry:SearchResult) =
( entry.Properties.Item( name ).Item( 0 ).ToString() )
static member formatUserName (format:string) (entry:SearchResult) =
let displayName = adEntry.prop "displayName" entry
let first = displayName.Substring ( 2 + displayName.IndexOf ", " )
let last = displayName.Substring ( 0, displayName.IndexOf ", " )
let ntid = adEntry.prop "cn" entry
format.Replace( "%f", first )
.Replace( "%l", last )
.Replace( "%i", ntid )
type ad =
static member query (filter:string) =
use searcher = new DirectorySearcher( filter )
Seq.cast<SearchResult> ( searcher.FindAll() )
[<EntryPoint>]
let main argv =
let groupQuery = "memberof=CN=" + ( ConfigurationManager.AppSettings.Item "ADGroup" ) + ",OU=XYZ Groups,DC=xyz,DC=com"
let results =
Seq.map
( adEntry.formatUserName "%f %l-%i" )
( ad.query groupQuery )
Seq.iter
( printf "%s\n" )
results
ignore ( Console.ReadKey true )
0
Am I missing out on F#'s power or maintainability by using types in the code above?