conditional statements - Conditionally apply filter in forward pipe chain in F#? -


i sequence of records csv file. want optionally filter records date , type , optionally consolidate records meeting criteria. optionally filtering date , type straightforward using seq.filter. optionally consolidate records meeting criteria. have function working, can't figure out how optionally apply resulting sequence. can't use seq.filter because consolidate operates on entire sequence not on 1 item @ time. can solve intermediate variable, wondering if there graceful idiomatic way handle this.

basically want know way conditionally apply 1 (or more) parts of chain in forward pipe sequence.

this want in pseudo code (options holds command line parameters):

let x =     getrecords options.filepath     |> seq.filter (fun r -> if options.date.hasvalue                             r.date.date = options.date.value.date else true)     |> seq.filter (fun r -> if not(string.isnullorempty(options.type))                             r.type = options.type else true)     if options.consolidaterecords         |> consolidaterecords 

you can use if ... else expression identity function in else clause:

let x =     getrecords options.filepath     |> (* ... bunch of stuff ... *)     |> (if options.consolidaterecords consolidaterecords else id)     |> (* ... optionally more stuff ... *) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -