PageRenderTime 19ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/iterator/map_aggregator.e

http://github.com/tybor/Liberty
Specman e | 57 lines | 31 code | 3 blank | 23 comment | 0 complexity | b7b037f93ee95112f2e1a886bbf4ba04 MD5 | raw file
 1-- This file is part of a Liberty Eiffel library.
 2-- See the full copyright at the end.
 3--
 4expanded class MAP_AGGREGATOR[V_, K_, R_]
 5
 6feature {ANY}
 7   map, map_iter (items: MAP[V_, K_]; action: FUNCTION[TUPLE[V_, K_, R_], R_]; initial: R_): R_
 8      local
 9         i: ITERATOR[K_]
10      do
11         Result := initial
12         from
13            i := items.new_iterator_on_keys
14         until
15            i.is_off
16         loop
17            Result := action.item([items.at(i.item), i.item, Result])
18            i.next
19         end
20      end
21
22   map_index (items: MAP[V_, K_]; action: FUNCTION[TUPLE[V_, K_, R_], R_]; initial: R_): R_
23      local
24         i: INTEGER
25      do
26         Result := initial
27         from
28            i := items.lower
29         until
30            i > items.upper
31         loop
32            Result := action.item([items.item(i), items.key(i), Result])
33            i := i + 1
34         end
35      end
36
37end -- class MAP_AGGREGATOR
38--
39-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
40--
41-- Permission is hereby granted, free of charge, to any person obtaining a copy
42-- of this software and associated documentation files (the "Software"), to deal
43-- in the Software without restriction, including without limitation the rights
44-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45-- copies of the Software, and to permit persons to whom the Software is
46-- furnished to do so, subject to the following conditions:
47--
48-- The above copyright notice and this permission notice shall be included in
49-- all copies or substantial portions of the Software.
50--
51-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
57-- THE SOFTWARE.