How do you apply a List filter before a List map in OCaml? I'm trying the pipe operator but with no success:
let r infile =
match List.tl (In_channel.read_lines infile ) with
| None -> []
| Some body ->
List.filter body ~f:(fun line -> true)
|> List.map body ~f:(fun line ->
match split_on_comma line with
| _ :: _ :: num :: street :: unit :: city :: _ :: region :: _ ->
String.strip (num ^ " " ^ addr_case street ^ ", " ^ addr_case city ^ " " ^ region)
| _ -> assert false)
utop is giving me:
"This expression has type string list but an expression was expected of type string list -> 'a"
I'm aware the List.filter does nothing at present. I'm simply trying to use it before the List.map
The standard OCaml List.filter doesn't have the
~f:parameter. Most likely you're using Core.I don't have Core set up right now, so I can't test. But one possible problem is that you're using
bodyin theList.mapcall. I think you should leave it out. You want to process the result of theList.filterexpression. You don't want to process body, which is the original value from the match.Here is a similar expression using the OCaml standard library versions of the functions: