F#管道第一个参数 [英] F# pipe first parameter

查看:97
本文介绍了F#管道第一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将第一个参数传递给多参数函数? 例如

is that possible to pipe the first parameter into a multiple parameter function? for example

date = "20160301"

是否可以将date输送到

DateTime.ParseExact(    , "yyyyMMDD", CultureInfo.InvariantCulture)

推荐答案

如@yuyoyuppe在他/她的答案中所述,您不能直接通过管道将其插入ParseExact,因为它是一种方法,因此无法使用.

As @yuyoyuppe explains in his/her answer, you can't pipe directly into ParseExact because it's a method, and thereby not curried.

定义咖喱的Adapter函数通常是一个不错的选择,但是如果您仅在本地需要它,也可以通过管道传递给匿名函数:

It's often a good option to define a curried Adapter function, but you can also pipe into an anonymous function if you only need it locally:

let res =
    date |> (fun d -> DateTime.ParseExact(d, "yyyyMMdd", CultureInfo.InvariantCulture))

为您提供DateTime值:

> res;;
val it : DateTime = 01.03.2016 00:00:00

这篇关于F#管道第一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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