= lambda o:o+1
add_one = lambda o:o*2
multiple_by_two = TypeTransformer(range(10),[add_one,multiple_by_two])
pipe
= [pipe[i] for i in range(10)]
results 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) test_eq(results,[
Type Transforms
DataPipes for calling functions over map based
__getitem__
calls
TypeTransformer
TypeTransformer (*args, **kwds)
On __getitem__
functions in self.type_tfms
get called over each element. Generally TypeTransformer
as the name suggests is intended to convert elements from one type to another. reference documentation on how to combine this with InMemoryCacheHolder
.
Similar to the fastrl.pipes.iter.transforms
, TypeTransformer
can be used to convert elements into different values…
However if we want to convert types and keep them, we can combine TypeTransformer
with InMemoryCacheHolder
…
= lambda o:str(o)
num2str = lambda o:o+'_postfix'
add_str_postfix = TypeTransformer(range(10),[num2str,add_str_postfix])
pipe = dp.map.InMemoryCacheHolder(pipe)
pipe
= [pipe[i] for i in range(10)]
results '0_postfix', '1_postfix', '2_postfix', '3_postfix',
test_eq(results,['4_postfix', '5_postfix', '6_postfix', '7_postfix', '8_postfix', '9_postfix'])