Utility for recursively unzipping tuples, Options of tuples and Results of tuples.

Related tags

Miscellaneous zipped
Overview

Zipped

Utility for recursively unzipping tuples, Options of tuples and Results of tuples.

Install

cargo add zipped

Usage

This crate is quiet straightforward.

Unzipping (((A, B), C), ...)

If you have a left- or right-recursively zipped tuple, you can use UnzipInto::unzip_into to turn it into a non-recursive tuple. This works for up to 26 tuple elements.

use zipped::UnzipInto;

let (a, b, c) = ((1, 2), 3).unzip_into(); // left-recursive
let (a, b, c) = (1, (2, 3)).unzip_into(); // right-recursive

Unzipping Option<(((A, B), C), ...)>

If you have an Option that contains a left- or right-recursively zipped tuple, you can also use UnzipInto::unzip_into to turn it into an Option of a non-recursive tuple. This also works for up to 26 tuple elements.

use zipped::UnzipInto;

let zipped = Some(1).zip(Some(2)).zip(Some(3));

match zipped.unzip_into() {
    Some((a, b, c)) => {}
    None => {}
}

While it's also possible to unzip Options with right-recursively zipped tuples, these don't occur naturally since Option::zip is left-recursive.

Unzipping Result<(((A, B), C), ...), E>

If you have a Result that contains a left- or right-recursively zipped tuple, you can also use UnzipInto::unzip_into to turn it into a Result of a non-recursive tuple. This also works for up to 26 tuple elements.

use zipped::UnzipInto;

let zipped = Ok::<_, ()>(1)
    .and_then(|a| Ok((a, 2)))
    .and_then(|ab| Ok((ab, 3)));

match zipped.unzip_into() {
    Ok((a, b, c)) => {}
    Err(_) => {}
}

Again, while it's also possible to unzip Results with right-recursively zipped tuples, I found that these occur much less often.

Limitations

  • Type inference. The compiler cannot automatically infer T in UnzipInto<T>. Eventually, you will need to specify the return value's arity.
  • Maximum arity. UnzipFrom is implemented for tuples of up to 26 elements.
  • Strict. It only works for completely zipped tuples where each tuple contains 2 elements and only the left (or the right) element can be another tuple, i.e. it does not work for ((A, B), C, D).

License

Copyright 2022 Glacyr B.V.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...
The simplest way to de-Google your life and business: Inbox, Calendar, Files, Contacts & much more
The simplest way to de-Google your life and business: Inbox, Calendar, Files, Contacts & much more

Bloom The all-in-one private workspace Try it for free! You no longer trust tech monopolies with your data? You are done with your privacy invaded by

MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine
MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine

MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box. For more information about features go to our documentation.

A job queue built on sqlx and PostgreSQL.

sqlxmq A job queue built on sqlx and PostgreSQL. This library allows a CRUD application to run background jobs without complicating its deployment. Th

Modify fonts to remove bitmap and disable gridfit for Windows font rendering.

Since Windows 10 version 1703 (Creators Update), its built-in TrueType renderer now supports vertical anti-aliasing. Despite there are only 30 levels of grayscale shade, it dramatically improves text rendering, especially for CJK languages. Sadly, it is only enabled for selected fonts at selected sizes.

An example project demonstrating integration with Rust for the ESP32-S2 and ESP32-C3 microcontrollers.

Rust ESP32 Example An example project demonstrating integration with Rust for the ESP32-S2 and ESP32-C3 microcontrollers.

Small and simple stateful applications, designed to facilitate the monitoring of unwanted behaviors of the same.

Violet Violet é um pequeno e simples monitorador de aplicação, voltado para receber eventos de erro e estado. Instalação simples: Dependencias: Docker

Vue, React, Solid, Angular, Svelte, and Liquid From JS Objects.

Vue, React, Solid, Angular, Svelte, and Liquid From JS Objects.

Meteor Client Installer - Installer to automate the install of Fabric and Meteor Client
Meteor Client Installer - Installer to automate the install of Fabric and Meteor Client

This is an installer that automates the install of Meteor and Fabric

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle!

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle (such as rewriting/refactroing your DM code).

Releases(v0.1.0)
Owner
Glacyr B.V.
Glacyr B.V.
🗃 Decoder and utility for the Flipnote Studios .ppm animation format.

?? para What? A decoder and utility for the Flipnote Studios .ppm animation format. Why this implementation over the original? This implementation is

Fuwn 11 Dec 12, 2022
Utility to quickly setup Starcraft Broodwar matches between 2 or more bots

BWAIShotgun Utility to quickly setup Starcraft Broodwar matches between 2 or more bots Be aware that all bots will be executed directly, without any l

Dennis Waldherr 5 Nov 25, 2022
A Rust proc-macro crate which derives functions to compile and parse back enums and structs to and from a bytecode representation

Bytecode A simple way to derive bytecode for you Enums and Structs. What is this This is a crate that provides a proc macro which will derive bytecode

null 4 Sep 3, 2022
A library and tool for automata and formal languages, inspired by JFLAP

Sugarcubes is a library and application for automata and formal languages. It is inspired by JFLAP, and is intended to eventually to be an alternative to JFLAP.

Henry Sloan 22 Nov 2, 2022
A stupid macro that compiles and executes Rust and spits the output directly into your Rust code

inline-rust This is a stupid macro inspired by inline-python that compiles and executes Rust and spits the output directly into your Rust code. There

William 19 Nov 29, 2022
This is a Discord bot written in Rust to translate to and from the Bottom Encoding Standard using bottom-rs and Serenity.

bottom-bot This is a Discord bot written in Rust to translate to and from the Bottom Encoding Standard using bottom-rs and Serenity. Ever had this pro

Bottom Software Foundation 11 Dec 10, 2022
An implementation of Code Generation and Factoring for Fast Evaluation of Low-order Spherical Harmonic Products and Squares

sh_product An implementation of Code Generation and Factoring for Fast Evaluation of Low-order Spherical Harmonic Products and Squares (paper by John

Simon Brown 7 Dec 2, 2022
lightweight and customizable rust s-expression (s-expr) parser and printer

s-expr Rust library for S-expression like parsing and printing parser keeps track of spans, and representation (e.g. number base) number and decimal d

Vincent Hanquez 5 Oct 26, 2022
Crates Registry is a tool for serving and publishing crates and serving rustup installation in offline networks.

Crates Registry Description Crates Registry is a tool for serving and publishing crates and serving rustup installation in offline networks. (like Ver

TalYRoni 5 Jul 6, 2023
Simplify temporary email management and interaction, including message retrieval and attachment downloads, using Rust.

Tempmail The Tempmail simplifies temporary email management and interaction, including message retrieval and attachment downloads, using the Rust prog

Dilshad 6 Sep 21, 2023