Open
Description
Consider this:
using Base.Dates: Second
immutable tsp # time series point
t :: DateTime
y :: Float64
end
t0 = now()
S = [tsp(t0+Second(10), 42), tsp(t0+Second(13), -1), tsp(t0+Second(17), 31)]
searchsortedfirst(S, t0+Second(12), by=x -> x.t)
searchsortedfirst(S, tsp(t0+Second(12), NaN), by=x -> x.t)
The first search call fails and the second is not ideal because one has to use a dummy value (NaN here) to fill in the parts of the item being searched that are not part of the key. I think that in searchsortedfirst(S, x, by=f)
it would make more sense to apply f() to the items of S but not to the item x. If the searchsorted functions worked like that, then the current behavior is easily obtained by using searchsortedfirst(S, f(x), by=f)
. Inversion of f() is not necessarily as easy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment