Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
util: WithPos
Browse files Browse the repository at this point in the history
  • Loading branch information
HoshinoTented committed Jan 4, 2024
1 parent e14478c commit e18a6f8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/src/main/java/org/aya/util/error/WithPos.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import java.util.function.Function;

public record WithPos<T>(@NotNull SourcePos sourcePos, T data) {
public record WithPos<T>(@NotNull SourcePos sourcePos, T data) implements SourceNode {
public <U> @Contract("_->new") WithPos<U> map(@NotNull Function<T, U> mapper) {
return new WithPos<>(sourcePos, mapper.apply(data));
var result = mapper.apply(data);
return result == data ? ((WithPos<U>) this) : new WithPos<>(sourcePos, mapper.apply(data));
}
}

0 comments on commit e18a6f8

Please sign in to comment.