当前位置:网站首页>通用泛型 列表 实现map max min
通用泛型 列表 实现map max min
2022-06-09 03:58:00 【KillJUMP】
var min = blocks.Map(block => block.Position.Column).Min();
var max = blocks.Map(block => block.Position.Column).Max(); var xValues = pieceBlocks.Map(b => b.transform.localPosition.x);
var yValues = pieceBlocks.Map(b => b.transform.localPosition.y); public static int FallDistance(this Board board)
{
return board.piece.GetPositions().Values.Map(p => p.Row).Min();
} public static class ICollectionExtension
{
public static T FindFirst<T>(this ICollection<T> collection, Func<T, bool> condition)
{
foreach (var element in collection)
{
if (condition(element)) return element;
}
return default(T);
}
public static T[] First<T>(this ICollection<T> collection, int count)
{
var result = new T[count];
var index = 0;
foreach (var element in collection)
{
if (index >= count) break;
result[index++] = element;
}
return result;
}
public static void Iterate<T>(this ICollection<T> collection, Action<T, int> action)
{
var index = 0;
foreach (var element in collection) action(element, index++);
}
public static U[] Map<T, U>(this ICollection<T> collection, Func<T, U> map)
{
var result = new U[collection.Count];
collection.Iterate((element, index) => result[index] = map(element));
return result;
}
public static T Min<T>(this ICollection<T> colleciton) where T : IComparable
{
return colleciton.CompareAll((a, b) => a.CompareTo(b) < 0);
}
public static T Max<T>(this ICollection<T> colleciton) where T : IComparable
{
return colleciton.CompareAll((a, b) => a.CompareTo(b) > 0);
}
static T CompareAll<T>(this ICollection<T> colleciton, Func<T, T, bool> compare) where T : IComparable
{
T result = default(T);
var hasValue = false;
foreach (var element in colleciton)
{
if (!hasValue || compare(element, result))
{
result = element;
hasValue = true;
}
}
return result;
}
}边栏推荐
- kubernetes 二进制安装(v1.20.16)(四)部署 master
- 网页设计期末作业-xxx公司网站(含导航栏轮播图等等)
- Geometric application problems
- [软件工具][教程]一个很好用的可以将csdn博客文章导出word的工具使用教程
- Interface performance test: Web service interface test
- Internet winter? How software testers go against the trend to enter high paid factories
- Merkle Patricia Trie原理
- Final assignment of Web Design - scenic spot tourism website (including navigation bar, rotation map, exquisite style)
- C#.net调用动态库dll注意事项
- 基于PyQt5完成的图转文功能
猜你喜欢
![[share] network packet loss fault handling scheme](/img/40/39e6548651eaeec5e6c1c39651cc88.png)
[share] network packet loss fault handling scheme

基于PyQt5完成的图转文功能

【优秀毕设】基于OpenCV的人脸识别打卡/签到/考勤管理系统(最简基本库开发、可基于树莓派)

Interface performance test: Web service interface test

Assembly: CPU structure - flag register and related instructions

Calculation method and comparison steps of target detection model map -- compare the map between the original model and the quantitative model

【LeetCode】第48天 - 1037. 有效的回旋镖

C language interview tube: talk about the functions of various string functions. I: I don't know. Interviewer: come back for an interview when the young man has learned how to do it.

Apple Announces Winner of the 2022 Apple Design Award

Domain name resolution (public network)
随机推荐
Server registration use
基於FPGA的VGA顯示彩條、字符、圖片
专家,如何快速转型管理者?
What is the value of Yuan universe virtual real estate?
互联网寒冬?软件测试人员如何逆势而行进入高薪大厂
Gradle 渠道包配置
Five highlights of wwdc2022 lock screen, weather kit, swiftui, collaboration function, apple payment
Final assignment of Web Design - scenic spot tourism website (including navigation bar, rotation map, exquisite style)
How to calculate the number of parameters in the LSTM layer
CPU surge problem location
【word】错误!文档中没有指定样式的文字。 1
After 15000 interns joined Amazon, what was life like in the big factory?
【优秀毕设】基于OpenCV的人脸识别打卡/签到/考勤管理系统(最简基本库开发、可基于树莓派)
域名解析(公网)
人才缺口50万以上,平均薪资20K?网络安全,测试员的下一个风口~
Dapr 1.7 之 Unix Domain socket 他来了
基于PyQt5完成的抠图界面
(三)VGG复现
汇编:Debug的常用命令
基于OpenCV的人脸检测、训练、识别