com.github.tonivade.purefun.generic.HFoldr Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2020, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.generic;
import com.github.tonivade.purefun.Tuple;
import com.github.tonivade.purefun.Tuple2;
import com.github.tonivade.purefun.generic.HList.HCons;
import com.github.tonivade.purefun.generic.HList.HNil;
@FunctionalInterface
public interface HFoldr, R> {
R foldr(T value, V initialValue, L list);
static HFoldr foldr() {
return (head, value, list) -> value;
}
static , R, X> HFoldr, X>
foldr(HApply, X> apply, HFoldr foldr) {
return (head, value, list) ->
apply.apply(head, Tuple.of(list.head(), foldr.foldr(head, value, list.tail())));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy