AutomotiveSimulator.jl icon indicating copy to clipboard operation
AutomotiveSimulator.jl copied to clipboard

`SpeedLimit` has no `iterate` method

Open rbalexan opened this issue 4 years ago • 2 comments

It would be nice to be able to iterate over or splat a SpeedLimit object since it is a tuple-like object. For example, splatting into a Distribution object or into a clamp statement to avoid having to type everything out would be super convenient (it is not too tedious, but it would be convenient :) )

Currently, both of these throw a MethodError: no method matching iterate(::SpeedLimit), which makes sense.

Uniform(SpeedLimit(0., 10.)...) # using Distributions
clamp(velocity, SpeedLimit(0., 10.)...)

rbalexan avatar May 03 '20 04:05 rbalexan

That would be a neat feature, instead of implementing iterate for SpeedLimit would it make sense to make it a FieldVector or a NamedTuple`?

MaximeBouton avatar May 06 '20 00:05 MaximeBouton

The other option is to implement iterate which is not that big of a deal. I am pretty sure there must be some julia package with a macro that defines it for us for any structure. For example there is @unpack: https://github.com/mauro3/Parameters.jl

MaximeBouton avatar May 06 '20 00:05 MaximeBouton