1 /*
<lambda>null2  * Copyright 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.appfunctions.internal
18 
19 import androidx.annotation.RestrictTo
20 import androidx.appfunctions.metadata.CompileTimeAppFunctionMetadata
21 
22 /**
23  * An [AppFunctionInventory] that aggregates the function metadata from multiple
24  * [AppFunctionInventory] instances.
25  *
26  * AppFunction compiler will automatically generate the implementation of this class to access all
27  * generated [CompileTimeAppFunctionMetadata] exposed by the application.
28  */
29 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
30 public abstract class AggregatedAppFunctionInventory : AppFunctionInventory {
31 
32     /** The list of [AppFunctionInventory] instances that contribute to this aggregate. */
33     public abstract val inventories: List<AppFunctionInventory>
34 
35     final override val functionIdToMetadataMap:
36         Map<String, CompileTimeAppFunctionMetadata> by lazy {
37         // Empty collection can't be reduced
38         if (inventories.isEmpty()) return@lazy emptyMap()
39         inventories.map(AppFunctionInventory::functionIdToMetadataMap).reduce { acc, map ->
40             acc + map
41         }
42     }
43 }
44