from typing import Generic, TypeVar, Callable from tudelft.utilities.immutablelist.AbstractImmutableList import AbstractImmutableList from tudelft.utilities.immutablelist.ImmutableList import ImmutableList from decimal import Decimal from abc import ABC OUT=TypeVar("OUT") IN1=TypeVar("IN1") IN2=TypeVar("IN2") class MapThreadList(AbstractImmutableList[OUT], Generic[OUT, IN1, IN2]): ''' @param output type of function and element type of resulting list @param fype of first input parameter of function and of elements in first list @param type of second input parameter of function and of elements in second list ''' def __init__(self, f:Callable[[IN1, IN2], OUT], list1:ImmutableList[IN1], list2:ImmutableList[IN2]): ''' creates a list [f(a1,b1), f(a2, b2) ,. ..., f(an, bb)]. @param f a {@link BiFunction}. Note, previously this used Function2 which was identical to this function now built into Java. @param list1 a list of items [a1,a2,..., an] @param list2 a list of items [b1, b2,...,bn] of same length as list1 ''' if f == None or list1 == None or list2 == None: raise ValueError("null argument") if list1.size() != list2.size(): raise ValueError("lists are unequal size") self.__list1 = list1 self.__list2 = list2 self.__f = f def get(self, index:int) -> OUT: return self.__f(self.__list1.get(index), self.__list2.get(index)); def size(self) -> int: return self.__list1.size();