# Searchsorted by=\<transform\> keyword question

**URL:** <https://discourse.julialang.org/t/searchsorted-by-transform-keyword-question/39851>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 20, 2020, 6:53pm UTC](https://discourse.julialang.org/t/searchsorted-by-transform-keyword-question/39851 "2020-05-20T18:53:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstook](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstook/32/3731_2.png) [@cstook](https://discourse.julialang.org/u/cstook)\
**Post date:** [May 20, 2020, 6:53pm UTC](https://discourse.julialang.org/t/searchsorted-by-transform-keyword-question/39851/1 "2020-05-20T18:53:02Z")

</div>

I thought that the transform specified with the by keyword was a function applied before the comparison. I don’t understand the last three examples below. Probably missing something obvious.

How does the by keyword work?

These make sense

```julia
julia> searchsorted([11,12,13,14,15],1)
1:0

julia> searchsorted([11,12,13,14,15],100)
6:5

julia> searchsorted([11,12,13,14,15],13)
3:3

julia> searchsorted([-15,-14,-13,-12,-11], 13)
6:5

julia> searchsorted([-11,-12,-13,-14,-15], 13, by=abs)
3:3

julia> searchsorted([-11,-12,-13,-14,-15], 13, by=x->abs(x))
3:3

```

What is wrong here?

```julia
julia> searchsorted([11,12,13,14,15],13, by= x->x^2) # should be 1:0 ?
3:3

julia> searchsorted([11,12,13,14,15],13, by= x->x+100) # should be 1:0 ?
3:3

julia> searchsorted([11,12,13,14,15],130, by= x->x+100) # should be 3:3 ?
6:5

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 20, 2020, 7:00pm UTC](https://discourse.julialang.org/t/searchsorted-by-transform-keyword-question/39851/2 "2020-05-20T19:00:37Z")

</div>

The function `by` is applied to both sides of the comparison, as in `by(x) < by(y)`, so those results all look correct to me.

---

<div class="post-metadata">

**Author:** ![cstook](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstook/32/3731_2.png) [@cstook](https://discourse.julialang.org/u/cstook)\
**Post date:** [May 20, 2020, 7:10pm UTC](https://discourse.julialang.org/t/searchsorted-by-transform-keyword-question/39851/3 "2020-05-20T19:10:41Z")

</div>

That makes sense. Thank You!
