source: utilitiespy/tudelft/utilities/immutablelist/MapThreadList.py@ 1343

Last change on this file since 1343 was 1339, checked in by wouter, 7 days ago

added MapThreadList

File size: 1.5 KB
RevLine 
[1339]1
2from typing import Generic, TypeVar, Callable
3from tudelft.utilities.immutablelist.AbstractImmutableList import AbstractImmutableList
4from tudelft.utilities.immutablelist.ImmutableList import ImmutableList
5from decimal import Decimal
6from abc import ABC
7
8OUT=TypeVar("OUT")
9IN1=TypeVar("IN1")
10IN2=TypeVar("IN2")
11
12class MapThreadList(AbstractImmutableList[OUT], Generic[OUT, IN1, IN2]):
13 '''
14 @param <OUT> output type of function and element type of resulting list
15 @param <IN1> fype of first input parameter of function and of elements in
16 first list
17 @param <IN2> type of second input parameter of function and of elements in
18 second list
19
20 '''
21
22 def __init__(self, f:Callable[[IN1, IN2], OUT], list1:ImmutableList[IN1], list2:ImmutableList[IN2]):
23 '''
24 creates a list [f(a1,b1), f(a2, b2) ,. ..., f(an, bb)].
25
26 @param f a {@link BiFunction}. Note, previously this used Function2
27 which was identical to this function now built into Java.
28 @param list1 a list of items [a1,a2,..., an]
29 @param list2 a list of items [b1, b2,...,bn] of same length as list1
30 '''
31 if f == None or list1 == None or list2 == None:
32 raise ValueError("null argument")
33 if list1.size() != list2.size():
34 raise ValueError("lists are unequal size")
35 self.__list1 = list1
36 self.__list2 = list2
37 self.__f = f
38
39 def get(self, index:int) -> OUT:
40 return self.__f(self.__list1.get(index), self.__list2.get(index));
41
42 def size(self) -> int:
43 return self.__list1.size();
Note: See TracBrowser for help on using the repository browser.