@@ -59,3 +59,44 @@ val fastKFunction = FastKFunction(sample::instanceFun, sample)
59
59
60
60
Depending on how you get the ` KFunction ` , the ` instance parameter ` may be required.
61
61
Even if the ` instance parameter ` is not required, passing an ` instance parameter ` will make the call faster.
62
+
63
+ ### How to call.
64
+ ` FastKFunction ` supports two major types of calls.
65
+
66
+ #### Call by vararg or Collection.
67
+ Calling with ` vararg ` or ` Collection ` is faster if you don't need to use the default arguments and
68
+ can get them in the order in which they are defined.
69
+
70
+ ``` kotlin
71
+ val fastKFunction: FastKFunction <Sample > = FastKFunction (function)
72
+
73
+ // call by vararg
74
+ val result: Sample = fastKFunction.call(1 , 2 , 3 , 4 , 5 )
75
+
76
+ // call by Collection
77
+ val result: Sample = fastKFunction.callByCollection(listOf (1 , 2 , 3 , 4 , 5 ))
78
+ ```
79
+
80
+ #### Call by ArgumentBucket.
81
+ If the default argument is expected to be used, a call using ` ArgumentBucket ` is available.
82
+
83
+ ` ArgumentBucket ` has interfaces like ` MutableMap<KParameter, Any?> ` , which can be used, for example, as follows.
84
+
85
+ ``` kotlin
86
+ data class Sample (
87
+ val arg1 : Int ,
88
+ val arg2 : Int = 0 ,
89
+ val arg3 : String? = null
90
+ )
91
+
92
+ private val fastKFunction: FastKFunction <Sample > = FastKFunction (::Sample )
93
+
94
+ fun map (src : Map <String , Any ?>): Sample {
95
+ return fastKFunction.generateBucket()
96
+ .apply {
97
+ fastKFunction.valueParameters.forEach {
98
+ if (src.containsKey(it.name!! )) this [it] = src.getValue(it.name!! )
99
+ }
100
+ }.let { fastKFunction.callBy(it) }
101
+ }
102
+ ```
0 commit comments