Socket
Socket
Sign inDemoInstall

pop-zip

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pop-zip

Zip and unzip, also called matrix transpose


Version published
Weekly downloads
1.8K
decreased by-0.38%
Maintainers
1
Weekly downloads
 
Created
Source

Zip and Unzip Transposition

This package provides zip, unzip, and "polymorphic" versions of these operators.

Zip is a function that accepts any number of arrays and returns an array of the respective values from each of the given arrays.

var unzip = require("pop-zip/zip");
expect(zip(
    ['a', 'b', 'c'],
    [1, 2, 3],
    ['x', 'y', 'z']
)).toEqual([
    ['a', 1, 'x'],
    ['b', 2, 'y'],
    ['c', 3, 'z']
]);

Unzip is identical but accepts an array of arrays. Unzip is behaviorally identical to a matrix transpose for matricies modeled as nested arrays.

var unzip = require("pop-zip/unzip");
expect(unzip(
    ['a', 'b', 'c'],
    [1, 2, 3],
    ['x', 'y', 'z']
)).toEqual([
    ['a', 1, 'x'],
    ['b', 2, 'y'],
    ['c', 3, 'z']
]);

Polymorphic operator

A well-planned system of objects is beautiful: a system where every meaningful method for an object has been anticipated in the design. Inevitably, another layer of architecture introduces a new concept and with it the temptation to monkey-patch, dunk-punch, or otherwise cover-up the omission. But reaching backward in time, up through the layers of architecture doesn't always compose well, when different levels introduce concepts of the same name but distinct behavior.

A polymorphic operator is a function that accepts as its first argument an object and varies its behavior depending on its type. Such an operator has the benefit of covering for the types from higher layers of architecture, but defers to the eponymous method name of types yet to be defined.

This package also exports polymorphic versions of zip and unzip, on the off-chance you may be working with an array or some more sophisticated collection.

Other collection objects are expected to implement toArray, and both zip and unzip will use these methods to funnel the resulting object array of arrays into the non-polymorphic unzip.

Copyright (c) 2015 by Kristopher Michael Kowal and contributors. All rights reserved. MIT License.

Keywords

FAQs

Package last updated on 02 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc