假设我有一个List<Tuple>
,其中每个元素中的第一个元素是一个字符串。在Kotlin中是否有一个扩展函数来从这些元组中选择第一个元素?
我正在寻找类似Select
的C#LINQ语法:
myTuples.Select(t => t.item1)
答案 0 :(得分:5)
在Kotlin中,元组可以是apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: zalenium-deployment
spec:
selector:
matchLabels:
app: zalenium
role: grid
replicas: 1
template:
metadata:
labels:
app: zalenium
role: grid
spec:
serviceAccountName: zalenium
serviceAccount: zalenium
containers:
- name: zalenium-pod
image: dosel/zalenium
ports:
- containerPort: 4444
protocol: TCP
volumeMounts:
- name: zalenium-shared
mountPath: /tmp/mounted
- name: zalenium-videos
mountPath: /home/seluser/videos
resources:
requests:
memory: "250m"
cpu: "500m"
limits:
memory: "1Gi"
volumes:
- name: zalenium-shared
persistentVolumeClaim:
claimName: zalenium-shared-claim
- name: zalenium-videos
persistentVolumeClaim:
claimName: zalenium-videos-claim
或Pair
。您只需映射列表并选择第一个元素,如下所示:
Triple
当然,你可以省去这些类型,我已将它们留下来,以便更容易理解。