我有这段代码,想知道相同的lambda表达式是什么。实际上,我尝试了相同的高级教程,但仍然无法从注释行开始找出以下代码的lambda表达式。
IDictionary<string, GitItem> mappedPathToGitItems = new Dictionary<string, GitItem>();
mappedPathToGitItems = clientWrapper.GetFilePathToGitItems(
gitLatestCommit, versionDescriptor, mappedPath, maxBatchSize);
List<string> filepaths = new List<string>();
// Lambda expression starts from here
// filepaths = {Lambda expression of the below code.}
foreach(KeyValuePair<string, GitItem> entry in mappedPathToGitItems)
{
string item = entry.Key;
GitItem gitItem = entry.Value;
if(gitItem != null)
{
filepaths.Add(item);
}
}
// Ends here
答案 0 :(得分:5)
List<string> filepaths = mappedPathToGitItems
.Where(kvp => kvp.Value != null)
.Select(kvp => kvp.Key)
.ToList();
答案 1 :(得分:0)
当您说“ lambda表达式等效”时,我认为您的意思是通过LINQ:
return Column(
children: <Widget>[
Text('Hellow'),
ListView(
padding: const EdgeInsets.only(top: 20.0),
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
)]);