From 44be6e6cd7671dd243056107ffa6201504f7fbce Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sun, 25 Jun 2023 15:50:38 -0400 Subject: Update a number of things --- src/main/java/bjc/optics/Adapters.java | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/java/bjc/optics/Adapters.java (limited to 'src/main/java/bjc/optics/Adapters.java') diff --git a/src/main/java/bjc/optics/Adapters.java b/src/main/java/bjc/optics/Adapters.java new file mode 100644 index 0000000..13a9d02 --- /dev/null +++ b/src/main/java/bjc/optics/Adapters.java @@ -0,0 +1,47 @@ +/* + * esodata - data structures of varying use + * Copyright 2022, Ben Culkin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package bjc.optics; + +import bjc.data.Pair; +import bjc.data.Triple; + +/** + * Various utilities for dealing with adapters + * + * @author bjcul + * + */ +public class Adapters { + /** + * Create an adapter between triples and left-nested pairs. + * + * @param The first left type + * @param The second left type + * @param The first middle type + * @param The second middle type + * @param The first right type + * @param The second right type + * + * @return An adapter between triples and left-nested pairs + */ + public static AdapterX, Triple, Pair, C1>, + Pair, C2>> flatten() { + return AdapterX.of((par) -> Triple.of(par.getLeft().getLeft(), par.getLeft().getRight(), par.getRight()), + (trp) -> Pair.pair(Pair.pair(trp.left(), trp.middle()), trp.right())); + } +} -- cgit v1.2.3