golang 数组能否实现类似 .Net Linq 的类似功能

2018-07-30 19:25:47 +08:00
 walktewy
从结构体数组中筛选相关要素,排序等功能,就像数组能执行 SQL 一样


底下为.Net 的代码
请问除了 https://github.com/ahmetb/go-linq
还有更好的实现吗


class Program
{
public class Student
{
public int StID;
public string LastName;
}
public class CourseStudent
{
public string CourseName;
public int StID;
}
static Student[] students=new Student[]{
new Student{StID=1,LastName="Carson"},
new Student{StID=2,LastName="Klassen"},
new Student{StID=3,LastName="Fleming"},
};
static CourseStudent[] studentsInCourses=new CourseStudent[]{
new CourseStudent{CourseName="Art",StID=1},
new CourseStudent{CourseName="Art",StID=2},
new CourseStudent{CourseName="History",StID=1},
new CourseStudent{CourseName="History",StID=3},
new CourseStudent{CourseName="Physics",StID=3},
}
static void Main()
{
var query=from s in students
join c in studentsInCourses on s.StID equals c.STID
where c.CourseName=="History"
select.LastName;
foreach(var q in query)
{
Console.WriteLine("Student taking History:{0}",q);
}
}
}
2212 次点击
所在节点    问与答
1 条回复
mmdsun
2018-07-31 08:00:10 +08:00
ReactiveX for go 应该有这种功能。我只用过 rxjava

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/475451

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX