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

**URL:** <https://discourse.julialang.org/t/neat-way-to-return-a-single-row-with-query-jl-pipes/22401>\
**Category:** General Usage\
**Tags:** question, query, dataframes\
**Created:** [March 27, 2019, 10:58am UTC](https://discourse.julialang.org/t/neat-way-to-return-a-single-row-with-query-jl-pipes/22401 "2019-03-27T10:58:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tanhevg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tanhevg/32/12025_2.png) [@tanhevg](https://discourse.julialang.org/u/tanhevg)\
**Post date:** [March 27, 2019, 10:58am UTC](https://discourse.julialang.org/t/neat-way-to-return-a-single-row-with-query-jl-pipes/22401/1 "2019-03-27T10:58:38Z")

</div>

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`.

```julia
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

```

---

<div class="post-metadata">

**Author:** ![hckr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hckr/32/4836_2.png) [@hckr](https://discourse.julialang.org/u/hckr)\
**Post date:** [March 27, 2019, 12:14pm UTC](https://discourse.julialang.org/t/neat-way-to-return-a-single-row-with-query-jl-pipes/22401/2 "2019-03-27T12:14:21Z")

</div>

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

```julia
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

```
