如何将歧视联盟传递给职能部门

时间:2015-07-07 14:14:17

标签: f#

我有歧视的联盟:

@Html.PagedListPager(Model, page => Url.Action("Index", new { page, itemsPerPage = ViewBag.CurrentItemsPerPage, Model.FirstOrDefault().SelectedStatusId }))

我有一大段代码我想重构:

$table->group($columns[, $having])

我想创建新函数以在内部匹配中使用它。这就是我所拥有的:

type Attribute =
    | AttrA of o : AttrA
    | AttrB of o : AttrB
    // ...
    | None

参数 // get Attribute match someType with | 0 -> let attrs = foo1 name match attrs.Length with | 0 -> None | _ -> AttrA(o = attrs.[0] ) | 1 -> let attrs = foo2 name match attrs.Length with | 0 -> None | _ -> AttrB(o = attrs.[0] ) // ... 的问题。

  

这不是一项功能,无法应用。

如何修复我的功能?

1 个答案:

答案 0 :(得分:2)

尝试这样的事情:

let foo (f : (string -> 'b[])) (s : string) (make : 'b -> Attribute) =
    let attrs  = f s
    match attrs.Length with
    | 0 -> None
    | _ -> make(attrs.[0])

make可以是常规函数,也可以是类型构造函数,即Attribute.AttrA

相关问题