V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
walktewy
V2EX  ›  问与答

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

  •  
  •   walktewy · 2018-07-30 19:25:47 +08:00 · 2202 次点击
    这是一个创建于 2089 天前的主题,其中的信息可能已经有所发展或是发生改变。
    从结构体数组中筛选相关要素,排序等功能,就像数组能执行 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);
    }
    }
    }
    1 条回复    2018-07-31 08:00:10 +08:00
    mmdsun
        1
    mmdsun  
       2018-07-31 08:00:10 +08:00 via Android
    ReactiveX for go 应该有这种功能。我只用过 rxjava
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   956 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 22:03 · PVG 06:03 · LAX 15:03 · JFK 18:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.