Following uses JavaScript code but F# is tagged for input from functional programmers.
I understand that in functional programming we shouldn't mutate the state or incoming parameters but I'm confused about formal request pattern when it comes to functional programming.
Formal Request pattern consists of an Object having both input and output parameters within the same object.
The function looks up the associated subset of input parameters and populates the associated result field. The request object is subsequently passed to other objects where each function updates or decorates the result hence forming a pipeline.
In other words request object gets populated as it goes through the pipeline and each successive function depends on the result of the previous operation.
for instance in context of following Javascript code.
var request = {
publicationId: "1234",
permissions: [] // string array
schema: null
// a lot more other input and output params
}
following function reads publicationId
& updates permissions
authorization.requestPermissions(request);
following function reads publicationId
, permissions
(from previous call) & populates schema
article.create(request);
article.upload(request); // uses updated schema from `article.create`
article.publish(request); // uses update schema from `article.upload`
Every subsequent operation is dependent on previous operation's result.
here both permissions
and schema
are output
console.log(request.permissions)
console.log(request.schema)
Question is, is it violating functional programming?
What could I change in this code to make Formal Request pattern more functional programming compliant.