Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the syntax to assign multiple enum values to a property in F#?

I am writing a ServiceStack webservice in F# and need to limit some of the features (removing SOAP support for instance).

In C# I am using the pipe operation to assign multiple Enums (ServiceStack.ServiceHost.Feature) to the EnableFeatures property like so:

SetConfig(new EndpointHostConfig
{
    DebugMode = true, //Show StackTraces in responses in development
    EnableFeatures = Feature.Json | Feature.Xml | Feature.Html | Feature.Metadata | Feature.Jsv
});

However in F# you can't use pipe to accomplish this, and everything else I try is attempting to do function application to the enums. How do I go about assigning multiple enums in this case?

like image 899
John B Fair Avatar asked May 18 '12 15:05

John B Fair


2 Answers

Use a triple pipe:

EnableFeatures = Feature.Json ||| Feature.Xml ||| Feature.Html ||| Feature.Metadata ||| Feature.Jsv
like image 74
Craig Stuntz Avatar answered Sep 19 '22 11:09

Craig Stuntz


If you have a bunch of them you can save a few keystrokes with reduce:

List.reduce (|||) [Feature.Json; Feature.Xml; Feature.Html; Feature.Metadata]
like image 38
Daniel Avatar answered Sep 20 '22 11:09

Daniel