我有一个复杂的数据结构,我必须创建这个简短的例子以便更好地理解。
type alias People =
{ name : String
, sex : String
, phones : List Phone
}
type alias Phone =
{ number : String
, isActive : Bool
}
此结构填充:
people = [
{ name = "_me"
, sex = "M"
, phones = [
{ number = "(99) 99 9 9999-9999"
, isActive = True
}]
},
{ name = "_you"
, sex = "M"
, phones = [
{ number = "(11) 11 1 1111-1111"
, isActive = True
},
{ number = "(22) 22 2 2222-2222"
, isActive = False
}]
}]
我想只获得手机'来自'人民'列表,如下例所示
phones = [
{ number = "(99) 99 9 9999-9999"
, isActive = True
},
{ number = "(11) 11 1 1111-1111"
, isActive = True
},
{ number = "(22) 22 2 2222-2222"
, isActive = False
}]
我已经尝试了3天,但无济于事。
答案 0 :(得分:3)
您可以通过映射将所有电话号码拉出到列表中以获取某人的电话号码列表,然后将这些电话号码列表连接在一起:
getPhones : List People -> List Phone
getPhones = List.concat << List.map .phones