小编Ale*_*rab的帖子

我可以将这个异步java网络API转换为monadic表示(或其他惯用语)吗?

我已经获得了一个java api,用于通过基于回调的样式连接和通过专用总线进行通信.我目前正在scala中实现一个概念验证应用程序,我正在尝试研究如何生成一个稍微更惯用的scala接口.

典型(简化)应用程序在Java中可能看起来像这样:

    DataType type = new DataType();
    BusConnector con = new BusConnector();
    con.waitForData(type.getClass()).addListener(new IListener<DataType>() {
        public void onEvent(DataType t) {
            //some stuff happens in here, and then we need some more data
            con.waitForData(anotherType.getClass()).addListener(new IListener<anotherType>() {
                public void onEvent(anotherType t) {
                    //we do more stuff in here, and so on
                }
            });
        }
    });

    //now we've got the behaviours set up we call
    con.start();
Run Code Online (Sandbox Code Playgroud)

在scala中,我可以明确地定义从(T => Unit)到IListener的隐式转换,这肯定会使事情变得更简单:

implicit def func2Ilistener[T](f: (T => Unit)) : IListener[T] = new IListener[T]{
  def onEvent(t:T) …
Run Code Online (Sandbox Code Playgroud)

monads scala scalaz

9
推荐指数
1
解决办法
624
查看次数

如何将F [A\/ B]拆分为(F [A],F [B])

我偶尔会遇到这样的代码:

val things : List[A \/ B] = ???
val (as, bs) : (List[A], List[B]) = ??? //insert something to do this
Run Code Online (Sandbox Code Playgroud)

或者在我目前的情况下我想要 Map[A, B \/ C] => (Map[A, B], Map[A, C])

有没有一种很好的方法在一般情况下F[A \/ B]对F进行适当限制?它看起来有点像Unzip主题的变体.

scala scalaz scalaz7

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

在调试时如何阻止intellij将特定的jar添加到类路径?

当我在intellij中调试应用程序时,它坚持将所有jar包括在我的jre/lib文件夹和子文件夹中.不幸的是,我使用的其中一个库在启动时手动加载类路径上的每个类,以减少操作期间的加载时间.

因此,立即调试我的应用程序会导致进程旋转100%然后最终死亡.如果我使用命令行intellij使用并从类路径中删除lib文件夹中的jar,应用程序将按预期执行.

如何让intellij不包含jre libs?

intellij-idea

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

标签 统计

scala ×2

scalaz ×2

intellij-idea ×1

monads ×1

scalaz7 ×1