F#从Seq.choose中的列表中获取每个元素 [英] F# get each element from the list in Seq.choose

查看:83
本文介绍了F#从Seq.choose中的列表中获取每个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我有一个字符串元组数组:
让线= [| ("A 1 100"); ("B 2 200"); ("C 3 300")|]

解决方案

Seq.choose将产生一个与正则表达式完全匹配的元素的序列.

您说您想要一个新数组.

因此将Seq.choose的输出通过管道传输到 seq到数组的转换功能:-

让newLines =线
             |> Seq.choose(fun l1->让m = Regex.Match(l1,@"[[A-Z](\ d +)(\ d +)")在
                                     如果m.Success则为Some(List.tail [用于m.Groups中的g-> g.Value])
                                     其他没有)
             |> Seq.toArray 


Hello,
I have an array of string tuples:
let lines = [| ("A 1 100"); ("B 2 200"); ("C 3 300") |]

解决方案

Seq.choose will result in a sequence with exactly those elements for which the regex matches.

You say you want a new array.

So pipe the output of Seq.choose into the seq to array conversion function :--

let newLines = lines
             |> Seq.choose(fun l1 -> let m = Regex.Match(l1, @"[A-Z] (\d+) (\d+)") in
                                     if m.Success then Some (List.tail [ for g in m.Groups -> g.Value ])
                                     else None)
             |> Seq.toArray


这篇关于F#从Seq.choose中的列表中获取每个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆