/* * 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())); } }