11# Export DynamicLinks API
22export DynamicLinks,
3- getindex, endof, length, start, next, done , eltype,
3+ getindex, endof, length, iterate, lastindex , eltype,
44 handle, header
55
66# Export Dynamic Link API
@@ -11,6 +11,8 @@ export DynamicLink,
1111export RPath,
1212 handle, rpaths, canonical_rpaths, find_library
1313
14+ # Import iteration protocol
15+ import Base: iterate, length, lastindex
1416
1517"""
1618 DynamicLinks
@@ -24,23 +26,18 @@ given below, with methods that subclasses must implement marked in emphasis:
2426
2527### Iteration
2628 - *getindex()*
27- - *endof()*
28- - length()
29- - start()
30- - next()
31- - done()
29+ - *lastindex()*
30+ - iterate()
3231 - eltype()
3332
3433### Misc.
3534 - *handle()*
3635"""
3736abstract type DynamicLinks{H <: ObjectHandle } end
3837
39- @mustimplement endof (dls:: DynamicLinks )
40- start (dls:: DynamicLinks ) = 1
41- done (dls:: DynamicLinks , idx) = idx > length (dls)
42- next (dls:: DynamicLinks , idx) = (dls[idx], idx+ 1 )
43- length (dls:: DynamicLinks ) = endof (dls)
38+ @mustimplement lastindex (dls:: DynamicLinks )
39+ iterate (dls:: DynamicLinks , idx= 1 ) = idx > length (dls) ? nothing : (dls[idx], idx+ 1 )
40+ length (dls:: DynamicLinks ) = lastindex (dls)
4441eltype (:: Type{D} ) where {D <: DynamicLinks } = DynamicLink
4542@mustimplement getindex (dls:: DynamicLinks , idx)
4643
@@ -83,6 +80,8 @@ marked in emphasis:
8380 - *rpaths()*
8481 - canonical_rpaths()
8582 - find_library()
83+ - lastindex()
84+ - iterate()
8685"""
8786abstract type RPath{H <: ObjectHandle } end
8887
@@ -107,11 +106,9 @@ Return the list of paths that will be searched for shared libraries.
107106"""
108107@mustimplement rpaths (rpath:: RPath )
109108
110- endof (rpath:: RPath ) = lastindex (rpaths (rpath))
111- start (rpath:: RPath ) = 1
112- done (rpath:: RPath , idx) = idx > length (rpath)
113- next (rpath:: RPath , idx) = (rpath[idx], idx+ 1 )
114- length (rpath:: RPath ) = endof (rpath)
109+ lastindex (rpath:: RPath ) = lastindex (rpaths (rpath))
110+ iterate (rpaht:: RPath , idx= 1 ) = idx > length (rpath) ? nothing : (rpath[idx], idx+ 1 )
111+ length (rpath:: RPath ) = lastindex (rpath)
115112eltype (:: Type{D} ) where {D <: RPath } = String
116113getindex (rpath:: RPath , idx) = rpaths (rpath)[idx]
117114
0 commit comments