Skip to content

Instantly share code, notes, and snippets.

@kolektiv
Last active April 13, 2017 09:30
Show Gist options
  • Save kolektiv/17b3c16f9f7e52bd43bb7e9a5f4bb30f to your computer and use it in GitHub Desktop.
Save kolektiv/17b3c16f9f7e52bd43bb7e9a5f4bb30f to your computer and use it in GitHub Desktop.
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