Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
use new iterator protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeits committed Aug 4, 2018
1 parent 0b5c81f commit 2087e1a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/baseutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ best_arg, best_val = argmax(f, iter)
Computes the first element of iterator, on which f takes its maximum.
"""
function argmax(f, iter)
state = start(iter)
best_arg, state = next(iter, state)
iter_result = iterate(iter)
if iter_result === nothing
throw(ArgumentError("Cannot compute the argmax of an empty collection"))
end
best_arg, state = iter_result
best_val = f(best_arg)
while !done(iter,state)
arg, state = next(iter,state)
while true
iter_result = iterate(iter, state)
if iter_result === nothing
break
end
arg, state = iter_result
val = f(arg)
if val > best_val
best_val = val
Expand All @@ -40,7 +47,6 @@ function argmax(f, iter)
best_arg, best_val
end


w_component(::Type{Point{N, T}}) where {N, T} = T(1)
w_component(::Type{Vec{N, T}}) where {N, T} = T(0)

Expand Down

0 comments on commit 2087e1a

Please sign in to comment.