Skip to content

Instantly share code, notes, and snippets.

@aspnetde
Created August 13, 2017 14:38
Show Gist options
  • Save aspnetde/f5ccb902b620322bb009e18261cb01cf to your computer and use it in GitHub Desktop.
Save aspnetde/f5ccb902b620322bb009e18261cb01cf to your computer and use it in GitHub Desktop.
namespace Foo
module Bar =
let RelationsReducer (state:RelationState) action =
match action with
| ActivitiesRequestSucceeded (id, items)
-> { state with FacilityActivity = state.FacilityActivity |> Array.filter (fun (f, _) -> f <> id)
|> Array.append (items |> Array.map (fun item -> (id, item.Id))) }
| _ -> state
@TeaDrivenDev
Copy link

Use line breaks very liberally. :-)

match action with
| ActivitiesRequestSucceeded (id, items) ->
    {
        state with
            FacilityActivity =
                state.FacilityActivity
                |> Array.filter (fun (f, _) -> f <> id)
                |> Array.append (items |> Array.map (fun item -> (id, item.Id)))
    }
| _ -> state

@jackfoxy
Copy link

jackfoxy commented Aug 13, 2017

namespace Foo

module Bar =

    let RelationsReducer (state:RelationState) action =
        match action with
        | ActivitiesRequestSucceeded (id, items) 
            -> { state 
                    with FacilityActivity = 
                            state.FacilityActivity 
                            |> Array.filter (fun (f, _) -> f <> id)
                            |> Array.append (items 
                                             |> Array.map (fun item -> (id, item.Id))
                                            ) }

        | _ -> state

@isaacabraham
Copy link

isaacabraham commented Aug 13, 2017

Similar to both the above I guess.

let RelationsReducer (state:RelationState) = function
    | ActivitiesRequestSucceeded (id, items) ->
        { state with
            FacilityActivity =
                state.FacilityActivity
                |> Array.filter (fst >> (<>) id)
                |> Array.append (items |> Array.map (fun item -> (id, item.Id))) }
    | _ -> state

I've made a couple of small "compressions" to the code but they are just personal preference e.g. replace match with function. I'd advise avoiding use of binding to the name id as it's a built-in function in F# and might confuse.

@aspnetde
Copy link
Author

Thanks guys. I will have a chat with my Rider configuration, which doesn't seem to like this kind of indentation, which brought the question up in the first place.

@yawaramin
Copy link

Extract variable:

match action with
  | ActivitiesRequestSucceeded (id, items) ->
    let facilityActivity =
      state.FacilityActivity
        |> Array.filter (fun (f, _) -> f <> id)
        |> Array.append (items |> Array.map (fun item -> (id, item.Id)))

      { state with FacilityActivity = facilityActivity }
  | _ -> state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment