使用foldRight定义如下的concat函数可以正确连接列表
def concat[T](xs: List[T], ys: List[T]): List[T] = (xs foldRight(ys))(_ :: _)
Run Code Online (Sandbox Code Playgroud)
但是使用foldLeft这样做
def concat1[T](xs: List[T], ys: List[T]): List[T] = (xs foldLeft(ys))(_ :: _)
Run Code Online (Sandbox Code Playgroud)
导致编译错误value :: is not a member of type parameter T,需要帮助理解这种差异.
编辑:
以防万一有人可能正在寻找折叠的详细解释 http://lampwww.epfl.ch/teaching/programmation_avancee/documents/programmation_avancee_5_en-2x2.pdf
如果有人给出用例来解释下面给出的每个Watermark API和Apache flink之间的区别,将会很有帮助
AssignerWithPeriodicWatermarks[T]AssignerWithPunctuatedWatermarks[T]是否可以使用 传递环境变量sls deploy,sls似乎没有类似的开关-e,唯一可能的方式看起来像有一个单独的 yaml 文件来管理变量并使用 serverless.yml 文件中的“environment:”元素传递它,如上所述在本文中 。
在下面的场景中
class Group {
...
Set<User> users;
...
}
Run Code Online (Sandbox Code Playgroud)
在用户数量为6位数的情况下,可以安全地假设对集合执行任何操作都是使用任何ORM直接使用效率低(Java中的JPA/Hibernate,可以使用hibernate的ExtraLazyCollection来解决).
为了处理这种情况,是否可以,它不是将聚合和组合实体之间的域关系表示为集合,而是表示为由DomainService支持的操作,随后是存储库.
class Group {
User addUser(User anUser, GroupUserService aGroupUserService){ ... }
void removeUser(User anUser, GroupUserService aGroupUserService){ ... }
}
class GroupUserService {
GroupRepository groupRepository;
User addUser(User anUser) {
groupRepository.addUser(anUser);
}
}
class GroupRepository {
User addUser(User anUser) {
//execute the query(JQL or native) to save the user
}
}
Run Code Online (Sandbox Code Playgroud)
这听起来像是一个合理的解决方案而不违反DDD的原则,在这种情况下是否有一个优化被忽略了.
为什么以下语句对 有效.map()但对无效.flatMap()?
val tupled = input.map(x => (x*2, x*3))
//Compilation error: cannot resolve reference flatMap with such signature
val tupled = input.flatMap(x => (x*2, x*3))
Run Code Online (Sandbox Code Playgroud)
不过这个说法没有问题:
val tupled = input.flatMap(x => List(x*2, x*3))
Run Code Online (Sandbox Code Playgroud) 我想在指定年份之间的一年中在 Quarter 上做一个笛卡尔积
Year(2105, 2016) 应该返回 Quarter(2015, Q1), Quarter(2015, Q2)... Quarter(2016, Q4)
代表季度的枚举将是
public enum Quarters {
Q1, Q2, Q3, Q4
}
Run Code Online (Sandbox Code Playgroud)
我试图想出的代码卡在下面
IntStream.rangeClosed(this.getYear(), to.getYear())
.boxed()
.map(i -> Arrays
.stream(Quarters.values())
.map(q -> new Quarter(i, q))
);
Run Code Online (Sandbox Code Playgroud)
上面的代码返回Stream<Stream<Quarter>>,我需要扁平化为Stream<Quarter>任何帮助表示赞赏。
我有几个单向JPA2失败案例@OnetoMany关系下面是代码片段
@Entity
@Table(name="CUSTOMER")
@Access(AccessType.FIELD)
public class Customer {
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@JoinColumn(name="CUSTOMER_ID", referencedColumnName="CUSTOMER_ID")
private List<Address> customerAddresses;
....
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,它无法在服务器启动期间创建实体管理器工厂,并出现以下错误
DEBUG - Second pass for collection: xx.xxx.xxxxxxx.core.domainmodel.customerinfo.Customer.customerAddresses
DEBUG - Binding a OneToMany: xx.xxx.xxxxxxx.core.domainmodel.customerinfo.Customer.customerAddresses through a foreign key
DEBUG - Mapping collection: xx.xxx.xxxxxxx.core.domainmodel.customerinfo.Customer.customerAddresses -> CUSTOMER_ADDRESS
DEBUG - Unable to build entity manager factory
java.lang.NullPointerException: null
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1456) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
Run Code Online (Sandbox Code Playgroud)
当我referencedColumnName从@JoinColumn注释中删除属性时,服务器启动都很好
但是当我试图坚持下面失败的实体时,Hibernate为失败生成了跟踪(CUSTOMER_ID is the name of the identity generated PK column in CUSTOMER table and FK in the CUSTOMER_ADDRESS table …
在Java中的函数编程一书中,作者仅使用Function<T, U>接口构建了一个compose函数(然而,该接口不是Java 8附带的,但非常相似),其片段如下所示:
public interface Function<T, U> {
U apply(T arg);
}
Run Code Online (Sandbox Code Playgroud)
虽然我可以理解下面的compose的方法版本,它接受2个函数并返回一个组合函数
public static final Function<Integer, Integer> compose (final Function<Integer, Integer> f1,
final Function<Integer, Integer> f2) {
arg -> f1.apply(f2.apply(arg));
}
Run Code Online (Sandbox Code Playgroud)
我只是无法通过Function <>和lambdas来了解下面的compose实现
static Function<Function<Integer, Integer>,
Function<Function<Integer, Integer>,
Function<Integer, Integer>>> compose =
x -> y -> z -> x.apply(y.apply(z));
Run Code Online (Sandbox Code Playgroud)
PS:无法理解我的想法并继续前进其余部分:(
我正在尝试从以下Scala代码中使用Java 8 Stream,并遇到编译错误。
任何帮助表示赞赏!
def sendRecord(record: String): Unit throws Exception
bufferedReader.lines().forEach(s => sendRecord(s))
Cannot resolve forEach with such signature, expect: Consumer[_ >: String], actual: (Nothing)
Run Code Online (Sandbox Code Playgroud)
PS:尽管有迹象表明它几乎是直截了当的,例如https://gist.github.com/adriaanm/892d6063dd485d7dd221,但它似乎不起作用。我正在运行Scala 2.11.8
我尝试使用ENV变量来配置连接URL,我有一个预先配置有alchemy_conn和broker_url等的ami,我已经将环境变量写入从/ ams实例中的/ etc / environment中,以覆盖airflow.cfg中的属性。文件。我也能够从python代码访问变量。
但是它在运行ariflow时似乎没有生效,也尝试重新启动该过程但没有用,它仍然指向airflow.cfg文件中的那个
java ×3
java-8 ×3
scala ×3
hibernate ×2
java-stream ×2
airflow ×1
apache-flink ×1
flatmap ×1
fold ×1
jpa ×1
jpa-2.0 ×1
lambda ×1
list ×1
one-to-many ×1