1 |
|
---|
2 | from typing import Generic, TypeVar, Callable
|
---|
3 | from tudelft.utilities.immutablelist.AbstractImmutableList import AbstractImmutableList
|
---|
4 | from tudelft.utilities.immutablelist.ImmutableList import ImmutableList
|
---|
5 | from decimal import Decimal
|
---|
6 | from abc import ABC
|
---|
7 |
|
---|
8 | OUT=TypeVar("OUT")
|
---|
9 | IN1=TypeVar("IN1")
|
---|
10 | IN2=TypeVar("IN2")
|
---|
11 |
|
---|
12 | class 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();
|
---|