
org.aya.util.Arg Maven / Gradle / Ivy
// Copyright (c) 2020-2022 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.util;
import kala.collection.SeqView;
import kala.collection.immutable.ImmutableSeq;
import org.aya.util.binop.BinOpParser;
import org.jetbrains.annotations.NotNull;
import java.util.function.Function;
import java.util.function.UnaryOperator;
/**
* @param the type of expressions.
* In Aya, it is either core term, core pattern, concrete term, or concrete pattern.
* @author ice1000
*/
public record Arg(@Override @NotNull T term, @Override boolean explicit) implements BinOpParser.Elem {
public @NotNull Arg implicitify() {
return new Arg<>(term, false);
}
public @NotNull Arg map(@NotNull Function mapper) {
return new Arg<>(mapper.apply(term), explicit);
}
public static @NotNull SeqView> mapSeq(SeqView> args, @NotNull Function mapper) {
return args.map(t -> t.map(mapper));
}
public static @NotNull ImmutableSeq> mapSeq(ImmutableSeq> args, @NotNull Function mapper) {
return args.map(t -> t.map(mapper));
}
public @NotNull Arg update(@NotNull T term) {
return term == term() ? this : new Arg<>(term, explicit);
}
public @NotNull Arg descent(@NotNull UnaryOperator<@NotNull T> f) {
return update(f.apply(term));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy