Skip to content

Instantly share code, notes, and snippets.

@kolektiv
Last active April 13, 2017 09:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Potential Alternative Configuration Styles for Freya Machines
/*
Prompted by discussion in the F# Slack, where it was proposed that reducing the use of CEs
might help people more easily pick up Freya.
Of course, there's no reason why both syntaxes can't be made available if that seems like
the right option.
The basic freya { ... } CE is a genuine monad, and so would always stay as a CE option (though
it can also be expressed using standard combinator operators/named functions already).
*/
// Computation Expression
let machineA =
freyaMachine {
cors
corsMethods [GET; HEAD; OPTIONS]
corsHeaders ["Server"]
corsOrigins (SerializedOrigin.parse "http://example.com")
corsMaxAge (60*60*24)
methods [GET;HEAD;OPTIONS]
handleOk sayHello }
// Pipeline
let machineB state =
state
|> FreyaMachine.cors
|> FreyaMachine.corsMethods [GET; HEAD; OPTIONS]
|> FreyaMachine.corsHeaders ["Server"]
|> FreyaMachine.corsOrigins (SerializedOrigin.parse "http://example.com")
|> FreyaMachine.corsMaxAge (60*60*24)
|> FreyaMachine.methods [GET;HEAD;OPTIONS]
|> FreyaMachine.handleOk sayHello
// Composition
let machineC =
FreyaMachine.cors
>> FreyaMachine.corsMethods [GET; HEAD; OPTIONS]
>> FreyaMachine.corsHeaders ["Server"]
>> FreyaMachine.corsOrigins (SerializedOrigin.parse "http://example.com")
>> FreyaMachine.corsMaxAge (60*60*24)
>> FreyaMachine.methods [GET;HEAD;OPTIONS]
>> FreyaMachine.handleOk sayHello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment