Skip to content

Commit f6eb4bd

Browse files
committed
feat: add immutable bi tuple
1 parent 23faaf9 commit f6eb4bd

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2024-2025 OnixByte.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.tuple;
19+
20+
/**
21+
* Represents an immutable pair of two elements, referred to as 'left' and 'right'. This class
22+
* provides a simple way to group two values without the need to create a custom class for each
23+
* specific pair.
24+
* <p>
25+
* The generic types {@code L} and {@code R} denote the types of the left and right elements,
26+
* respectively. Instances of this class are immutable once created.
27+
*
28+
* @param <L> the type of the left element
29+
* @param <R> the type of the right element
30+
* @param left the left element of this tuple
31+
* @param right the right element of this tuple
32+
* @author siujamo
33+
* @author zihluwang
34+
*/
35+
public record ImmutableBiTuple<L, R>(
36+
L left,
37+
R right
38+
) {
39+
40+
/**
41+
* Creates a new {@code ImmutableBiTuple} with the specified left and right elements.
42+
*
43+
* @param <L> the type of the left element
44+
* @param <R> the type of the right element
45+
* @param left the left element
46+
* @param right the right element
47+
* @return a new {@code ImmutableBiTuple} containing the specified elements
48+
*/
49+
public static <L, R> ImmutableBiTuple<L, R> of(L left, R right) {
50+
return new ImmutableBiTuple<>(left, right);
51+
}
52+
}

0 commit comments

Comments
 (0)