小编Dim*_*mka的帖子

F#中RavenDB搜索方法的正确语法是什么

我试图找到RavenDB中包含一个单词的所有帖子(索引就在那里)

这是一个有效的查询,找到以'Liv'开头的所有内容

let post = query {
    for post in session.Query<MyType>() do
    where (post.Text.StartsWith("Liv"))
    select post
}
Run Code Online (Sandbox Code Playgroud)

尝试使用string.Contains()方法作为Where闭包的条件,将抛出NotSupportedException. 这里

所以我试图使用搜索方法,其中:

Expression<Func<T, object>> fieldSelector, 
// Expression marking a field in which terms should be looked for.
Run Code Online (Sandbox Code Playgroud)

来自docs的C#等价物:

List<User> users = session
    .Query<User>("Users/ByNameAndHobbies")
    .Search(x => x.Name, "Adam")
    .Search(x => x.Hobbies, "sport")
    .ToList();
Run Code Online (Sandbox Code Playgroud)

我的第一次尝试就是去

let x = session.Query<MyType>(index).Search((fun xe -> xe.Text ), "Liv")
Run Code Online (Sandbox Code Playgroud)

但是因为它期望对象出错而得到错误.试图将String转换为Object(这是一个奇怪的想法),但得到:

无法理解如何翻译x => x.Invoke(xe)

目前,我没有想法.我应该为搜索和返回对象标记字段.有任何想法吗?

谢谢.

编辑1:我的表达.获取运行时InvalidCastException,因为它无法将字符串转换为obj.

let expr = 
  <@ Func<MyType, _>(fun xe -> xe.Text ) @>
  |> LeafExpressionConverter.QuotationToExpression …
Run Code Online (Sandbox Code Playgroud)

f# ravendb

6
推荐指数
1
解决办法
274
查看次数

通过Rx从MailboxProcessor返回结果是一个好主意吗?

我对下面的代码示例以及人们的想法有点好奇.我们的想法是从NetworkStream(~20 msg/s)读取而不是在main中工作,将事物传递给MainboxProcessor以便在完成时处理并返回绑定.

通常的方法是使用PostAndReply,但我想绑定到ListView或C#中的其他控件.必须使用LastN项目进行魔术并进行过滤.另外,Rx有一些错误处理.

下面的例子观察2..10的数字并返回"你好X".在8它停止像EOF.使其成为ToEnumerable,因为其他线程在完成之前完成,但它也适用于Subscribe.

困扰我的是什么:

  1. 在递归中传递Subject(obj).我认为其中大约有3-4个没有任何问题.好主意?
  2. 主体的一生.

open System
open System.Threading
open System.Reactive.Subjects
open System.Reactive.Linq  // NuGet, take System.Reactive.Core also.
open System.Reactive.Concurrency

type SerializedLogger() = 

    let _letters = new Subject<string>()
    // create the mailbox processor
    let agent = MailboxProcessor.Start(fun inbox -> 

        // the message processing function
        let rec messageLoop (letters:Subject<string>) = async{

            // read a message
            let! msg = inbox.Receive()

            printfn "mailbox: %d in Thread: %d" msg Thread.CurrentThread.ManagedThreadId
            do! Async.Sleep 100
            // write it to the …
Run Code Online (Sandbox Code Playgroud)

f# system.reactive mailboxprocessor

5
推荐指数
1
解决办法
245
查看次数

F#命名约定是否禁止在不同光盘中具有相同的名称.工会类型?

我在一个模块中有一个共同类型,该类型在另外两个有区别的联合类型中使用.

为方便起见,我将它们命名为同名.其他名称不同.接下来,我正在尝试制作一个在控制台中打印类型的帮助器.

第一行无法编译,因为匹配大小写中的类型不匹配.我尝试了一些东西,无论是否打开模块,强制类型等,它仍然会失败.

另一件事是,如果我将鬃毛更改为Common1和Common2,它的工作没有任何问题.

我记得读过具有相同签名的类型存储在同一内部类型中,但我的现实示例有不同的签名但仍然失败.

我在某个地方错过了一点吗?

例:

示例无法编译错误:

错误此表达式应具有类型OneA,但此处具有类型OneB

在此输入图像描述

module commonThings =
    type CommonThing = 
        | Comm1 of int 
        | Comm2 of int 

module thingA =
    open commonThings
    type OneA = 
        | A1 of string
        | Common of CommonThing        
        | A2 of string

module thingB =
    open commonThings
    type OneB = 
        | B1 of string
        | Common of CommonThing        
        | B2 of string

module printAB =
    open commonThings
    open thingA
    open thingB

    let printA (msg:OneA) = 
        match msg with
        | …
Run Code Online (Sandbox Code Playgroud)

f#

2
推荐指数
2
解决办法
193
查看次数

标签 统计

f# ×3

mailboxprocessor ×1

ravendb ×1

system.reactive ×1