首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将记录转换为元组?

如何将记录转换为元组?
EN

Stack Overflow用户
提问于 2018-05-31 08:15:41
回答 1查看 426关注 0票数 3

我经常使用CSV类型提供程序,它将元组用于所有底层数据。我的问题是,我遇到有很多列的csv文件,并发现围绕操作这种大小的数据构建基础设施相当麻烦。如何构建一个只更新特定列子集的函数,而不必创建庞大的模式匹配语句?请参阅下面的代码示例。

代码语言:javascript
运行
复制
// I want to generate lots of sample data for the first three columns
// And I would like to avoid creating giant record types in order to
// do this task as the csv's are always changing and the records would
// have to change as well
type CumbersomeCSVRow = // 17 fields now, but imagine 212
    string * string * string * Option<int> * string * 
    Option<int> * string * string * string * string * 
    string * string * Option<float> * string * 
    Option<float> * Option<float> * string

// Here is a sample row of data
let sampleCumbersomeRow : CumbersomeCSVRow = 
    ("First","Second","Third",Some(52),"MSCI",None,"B74A123","",
     "Airlines","Transportation","","",Some(1.04293),"Updated",
     Some(0.95),Some(56.7423),"Measured")

// Record type of the sample data that I want to 'insert' into the cumbersome data type
type FirstThreeStrings = 
    { First : string; Second : string; Third : string}

// and some instances of the new data
let generatedFrontMatters = 
    // imagine lots of sample data and workflows to create it, hence the records
    seq { for letter in ["A";"B";"C"] -> 
            { First  = letter;
              Second = letter + letter
              Third  = letter + letter + letter } }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50614975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档