Neat way to return a single row with Query.jl pipes

Hello,

This is more of a code style thing, but I often need to construct a Query.jl pipeline (|>) that returns a single row, not a query result with multiple rows. Is there a neat way of doing this? Currently, I use collect at the end of the pipeline, and then just return the first element of the array, which is ugly.

Here is an example of what I am talking about. I need to return a single NamedTuple.

ret = load("myfile.csv") |> 
@map({_.key, score=my_scoring_funk(_)}) |> 
@orderby_descending(_.score) |> 
@take(1) |> 
collect # This is ugly

return ret[1] # This is ugly too

I think you can use first here. first gives you the first element of an iterable collection.

ret = load("myfile.csv") |> 
@map({_.key, score=my_scoring_funk(_)}) |> 
@orderby_descending(_.score) |> 
@take(1) |> # I do not think this line is necessary if you want the first row
first
1 Like