pair

Last updated:

0 purchases

pair Image
pair Images
Add to Cart

Description:

pair

pair #
A Pair class in dart that inspired from Pair in java
Features #

Create New Pair
Transform pair to Map
Transfor pair to list (if pair has same type between key and value)
Mutate to other Pair
Transform to single new type

Getting started #
dart pub add pair
copied to clipboard
Usage #
Intialize new pair #

import 'package:pair/pair.dart';

void main() {
var pair = Pair<int, int>(
1, // key
2, // value
);

print("pair: $pair");
print("pair.toList(): ${pair.toList}");
print("pair.toMap(): ${pair.toMap}");

// transform pair to new value with difference type
//
// by passing transform function
var tranformed = pair.transform(tranformFunction);

print("transformed pair : $tranformed");

// mutate pair to another pair
//
// by passing mutate function
var mutated = pair.mutate(mutateFunction<int, int>);

print("mutated pair : $mutated");

var reversedPair = pair.reverse;

print("reversedPair $reversedPair");

// deserialized pair
var (a, b) = pair();

print("deserialized value. a=$a, b=$b");

// Pair with difference type between key and val
var pair2 = Pair<String, int>(
"index", // key
1, // value
);
print("pair $pair2");

var pairToList =
pair2.toList; // it will throw because key and value do not have same type
}

int tranformFunction(int a, int b) {
return a + b;
}

Pair<String, String> mutateFunction<K, V>(K key, V value) {
return Pair(
key.toString(),
value.toString(),
);
}
copied to clipboard
Additional information #
You can make a pull request to create a new feature or bug fixing

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.