public static BiFunction<AlgebraicDataType, DeriveContext, DeriveResult<DerivedCodeSpec>> derivator(DeriveUtils deriveUtils) { return (adt, deriveContext) -> traverseResults( deriveContext.makes(), Makes.cases() .lambdaVisitor( lazy(() -> MapperDerivator.derive(adt, deriveContext, deriveUtils))) .constructors( lazy( () -> StrictConstructorDerivator.derive(adt, deriveContext, deriveUtils))) .lazyConstructor( lazy( () -> LazyConstructorDerivator.derive(adt, deriveContext, deriveUtils))) .patternMatching( lazy( () -> PatternMatchingDerivator.derive(adt, deriveContext, deriveUtils))) .getters(lazy(() -> GettersDerivator.derive(adt, deriveContext, deriveUtils))) .modifiers(lazy(() -> ModiersDerivator.derive(adt, deriveContext, deriveUtils))) .catamorphism( lazy(() -> new CataDerivator(deriveUtils, deriveContext, adt).derive())) .hktCoerce(DeriveResult.result(DerivedCodeSpec.none()))) .map( codeSpecList -> codeSpecList.stream().reduce(DerivedCodeSpec.none(), DerivedCodeSpec::append)); }
public DeriveResult<DerivedCodeSpec> derive() { return adt.fields() .stream() .map(DataArguments::getType) .anyMatch(tm -> utils.types().isSameType(tm, adt.typeConstructor().declaredType())) ? DataConstructions.cases() .multipleConstructors( MultipleConstructorsSupport.cases() .visitorDispatch(this::visitorDispatchImpl) .functionsDispatch(this::functionDispatchImpl)) .otherwise(() -> result(DerivedCodeSpec.none())) .apply(adt.dataConstruction()) : result(DerivedCodeSpec.none()); }
public static BiFunction<AlgebraicDataType, DeriveContext, DeriveResult<DerivedCodeSpec>> derivator(DeriveUtils deriveUtils) { return (adt, deriveContext) -> traverseResults( Arrays.asList( lazy(() -> StrictConstructorDerivator.derive(adt, deriveContext, deriveUtils)), lazy(() -> LazyConstructorDerivator.derive(adt, deriveContext, deriveUtils)), lazy(() -> MapperDerivator.derive(adt, deriveContext, deriveUtils)), lazy(() -> GettersDerivator.derive(adt, deriveContext, deriveUtils)), lazy(() -> ModiersDerivator.derive(adt, deriveContext, deriveUtils)), lazy(() -> PatternMatchingDerivator.derive(adt, deriveContext, deriveUtils)))) .map( codeSpecList -> codeSpecList.stream().reduce(DerivedCodeSpec.none(), Utils::appendCodeSpecs)); }