I have the following code:

    member this.ProcessEvent(sourceStream: OrderResponse) =          
       match sourceStream.Action with
        | Action.Partial
        | Action.Insert ->
            |> Seq.iter (fun x -> this.orderState.[x.OrderId] <- this.ConvertFullOrder x)
        | Action.Update ->
            |> Seq.iter (fun x -> this.orderState.[x.OrderId] <- this.UpdateOrder x this.orderState.[x.OrderId])
        | Action.Delete ->
            |> Seq.iter (fun x -> this.orderState.Remove(x.OrderId) |> ignore)
        | _ -> ()

It is processing a list of events and an action. The data is processed and stored in a dictionary. The action tells to insert, update or delete some of the records and applies to all the events received in the same message.

For each case, I iterate through the sourceStream.Data list.

Is there a better / more readable way where I can declare I am going to process that list and then, based on the Action, have different code? this would allow to remove the multiple sourceStream.Data |> bits and specify it only once.

  • 1
    \$\begingroup\$ Whoever VTCd this question, please explain. \$\endgroup\$ – IEatBagels Oct 30 '19 at 12:40
  • 1
    \$\begingroup\$ I didn't VTC but my presumption is that it would be helpful to have sample usage of this function so reviewers can have a better sense of how it is utilized \$\endgroup\$ – Sᴀᴍ Onᴇᴌᴀ Oct 30 '19 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.