Java Code Examples for com.mojang.datafixers.util.Either#map()
The following examples show how to use
com.mojang.datafixers.util.Either#map() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EitherMapCodec.java From DataFixerUpper with MIT License | 5 votes |
@Override public <T> RecordBuilder<T> encode(final Either<F, S> input, final DynamicOps<T> ops, final RecordBuilder<T> prefix) { return input.map( value1 -> first.encode(value1, ops, prefix), value2 -> second.encode(value2, ops, prefix) ); }
Example 2
Source File: EitherCodec.java From DataFixerUpper with MIT License | 5 votes |
@Override public <T> DataResult<T> encode(final Either<F, S> input, final DynamicOps<T> ops, final T prefix) { return input.map( value1 -> first.encode(value1, ops, prefix), value2 -> second.encode(value2, ops, prefix) ); }
Example 3
Source File: Sum.java From DataFixerUpper with MIT License | 5 votes |
@Override public <FT, FR> Either<TypeTemplate, Type.FieldNotFoundException> findFieldOrType(final int index, @Nullable final String name, final Type<FT> type, final Type<FR> resultType) { final Either<TypeTemplate, Type.FieldNotFoundException> either = f.findFieldOrType(index, name, type, resultType); return either.map( f2 -> Either.left(new Sum(f2, g)), r -> g.findFieldOrType(index, name, type, resultType).mapLeft(g2 -> new Sum(f, g2)) ); }
Example 4
Source File: CompoundList.java From DataFixerUpper with MIT License | 5 votes |
@Override public <FT, FR> Either<TypedOptic<List<Pair<K, V>>, ?, FT, FR>, FieldNotFoundException> findTypeInChildren(final Type<FT> type, final Type<FR> resultType, final TypeMatcher<FT, FR> matcher, final boolean recurse) { final Either<TypedOptic<K, ?, FT, FR>, FieldNotFoundException> firstFieldLens = key.findType(type, resultType, matcher, recurse); return firstFieldLens.map( this::capLeft, r -> { final Either<TypedOptic<V, ?, FT, FR>, FieldNotFoundException> secondFieldLens = element.findType(type, resultType, matcher, recurse); return secondFieldLens.mapLeft(this::capRight); } ); }
Example 5
Source File: Product.java From DataFixerUpper with MIT License | 5 votes |
@Override public <FT, FR> Either<TypeTemplate, Type.FieldNotFoundException> findFieldOrType(final int index, @Nullable final String name, final Type<FT> type, final Type<FR> resultType) { final Either<TypeTemplate, Type.FieldNotFoundException> either = f.findFieldOrType(index, name, type, resultType); return either.map( f2 -> Either.left(new Product(f2, g)), r -> g.findFieldOrType(index, name, type, resultType).mapLeft(g2 -> new Product(f, g2)) ); }
Example 6
Source File: Product.java From DataFixerUpper with MIT License | 5 votes |
@Override public <FT, FR> Either<TypedOptic<Pair<F, G>, ?, FT, FR>, FieldNotFoundException> findTypeInChildren(final Type<FT> type, final Type<FR> resultType, final TypeMatcher<FT, FR> matcher, final boolean recurse) { final Either<TypedOptic<F, ?, FT, FR>, FieldNotFoundException> firstFieldLens = first.findType(type, resultType, matcher, recurse); return firstFieldLens.map( this::capLeft, r -> { final Either<TypedOptic<G, ?, FT, FR>, FieldNotFoundException> secondFieldLens = second.findType(type, resultType, matcher, recurse); return secondFieldLens.mapLeft(this::capRight); } ); }
Example 7
Source File: Inj2.java From DataFixerUpper with MIT License | 4 votes |
@Override public Either<Either<F, G2>, G> match(final Either<F, G> either) { return either.map(f -> Either.left(Either.left(f)), Either::right); }
Example 8
Source File: Inj1.java From DataFixerUpper with MIT License | 4 votes |
@Override public Either<Either<F2, G>, F> match(final Either<F, G> either) { return either.map(Either::right, g -> Either.left(Either.right(g))); }