/src/lib/abilities/traversable.e
Specman e | 62 lines | 19 code | 3 blank | 40 comment | 1 complexity | ee8d97a793536a94f22b47c0420d234c MD5 | raw file
1-- This file is part of a Liberty Eiffel library. 2-- See the full copyright at the end. 3-- 4deferred class TRAVERSABLE[E_] 5 -- A `TRAVERSABLE[E_]' is a finite readable sequence of objects of type E_. 6 -- For instance, `COLLECTION's and `STRING's are `TRAVERSABLE'. 7 -- 8 -- A good performance should always be obtained by sequentially accessing a `TRAVERSABLE' with increasing 9 -- indexes (from `lower' to `upper'), as demonstrated in the following code snippet : 10 -- 11 -- from 12 -- i := a_traversable.lower 13 -- until 14 -- i > a_traversable.upper 15 -- loop 16 -- do_something_with(a_traversable.item(i)) 17 -- i := i + 1 18 -- end 19 -- 20 -- Other accessing methods (including random access and sequential access from `upper' to `lower') may or 21 -- may not lead to acceptable performance, depending on the particular implementation of `TRAVERSABLE'. 22 23inherit 24 ITERABLE[E_] 25 undefine -- because INDEXABLE features are more performant 26 for_each, for_all, exists, aggregate, 27 out_in_tagged_out_memory 28 end 29 INDEXABLE[E_] 30 31feature {ANY} 32 enumerate: ENUMERATE[E_] 33 local 34 items: TRAVERSABLE[E_] 35 do 36 if items ?:= Current then 37 items ::= Current 38 create Result.make(items) 39 end 40 end 41 42end -- class TRAVERSABLE 43-- 44-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file. 45-- 46-- Permission is hereby granted, free of charge, to any person obtaining a copy 47-- of this software and associated documentation files (the "Software"), to deal 48-- in the Software without restriction, including without limitation the rights 49-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 50-- copies of the Software, and to permit persons to whom the Software is 51-- furnished to do so, subject to the following conditions: 52-- 53-- The above copyright notice and this permission notice shall be included in 54-- all copies or substantial portions of the Software. 55-- 56-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 57-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 58-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 59-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 60-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 61-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 62-- THE SOFTWARE.