tablecloth icon indicating copy to clipboard operation
tablecloth copied to clipboard

Add List.partitionMap

Open Dean177 opened this issue 5 years ago • 0 comments

 (* Partition into two lists, of potentially different type, using function
   * `f`.  Returns value in the first list for `Left` and second list for
   * `Right`. *)
  let partitionMap (items : 'c list) ~(f : 'c -> ('a, 'b) Either.t): ('a list * 'b list) =
    TableclothList.foldRight
      ~initial:([], [])
      ~f:(fun (lefts, rights) item ->
        match f item with
        | Left a ->
            (a :: lefts, rights)
        | Right b ->
            (lefts, b :: rights))
      items

Dean177 avatar Jun 18 '20 18:06 Dean177