gpt4 book ai didi

java - 如何用Java实现clojure ISeq?

转载 作者:行者123 更新时间:2023-11-30 02:14:32 29 4
gpt4 key购买 nike

我想将 Java 函数的映射传递给 Clojure。这些函数使用实现 IFn 接口(interface)的 Java 匿名类。我还需要实现 ISeq 接口(interface)来传递列表。 ISeq 接口(interface)很简单,但有 no documentation 。我需要知道 ISeq 中的每个方法的作用和/或找到实现所有 ISeq 方法的类的 Java 代码(我不想 copy my lists 到 Clojure 结构)。

最佳答案

I need to know what each method in ISeq does

您还应该了解它扩展的接口(interface):

public interface Seqable {
ISeq seq(); // returns an ISeq instance
}

public interface IPersistentCollection extends Seqable {
// returns the count of this coll
int count();
// returns a new coll with o cons'd onto it
IPersistentCollection cons(Object o);
// returns a new empty coll (of same type?)
IPersistentCollection empty();
// compares this coll against o for equality
boolean equiv(Object o);
}

public interface ISeq extends IPersistentCollection {
// returns the first item in this seq
Object first();
// returns a new seq of every item in this except the first
ISeq next();
// returns a new seq of every item in this except the first
// ASeq returns empty for empty
ISeq more();
// returns a new seq with o cons'd onto this seq
ISeq cons(Object o);
}

...or find Java code of a class that implements all ISeq methods

ASeq abstract class implements (most of) ISeq 。扩展 ASeq 的类 implement ISeq.next() .

除了重新实现 ISeq 之外,肯定还有更简单的方法来实现您的目标。也许查看 Clojure 的 Java 实现会给您一些想法。

关于java - 如何用Java实现clojure ISeq?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49009034/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com