tablecloth icon indicating copy to clipboard operation
tablecloth copied to clipboard

Use labelled arguments for Set.add, Set.remove, and Map.remove

Open pm5 opened this issue 4 years ago • 1 comments

These functions use positional arguments for the value to be added or removed:

Set.add (Set.Int.fromList [1; 2]) 3 |> Set.toList = [1; 2; 3]
Set.remove (Set.Int.fromList [1; 2]) 2 |> Set.toList = [1]
Map.remove animalPopulations "Mosquito"

Use a ~key label for the keys and ~value label for the values, like what Map.add is doing, makes it easier to use pipelast:

Set.Int.fromList [1; 2] |> Set.add ~value:3 |> Set.toList = [1; 2; 3]
Set.Int.fromList [1; 2] |> Set.remove ~value:2 |> Set.toList = [1]
animalPopulations |> Map.remove ~key:"Mosquito"

pm5 avatar Dec 30 '21 01:12 pm5