A tiny tuple implementation
This version is quite different to my original implementation (which received quite a bit of critique on Hacker News). I have dropped a few things that meant it was not a real tuple, so now it's closer to the mark. I have tried to follow a KISS (Keep It Simple Stupid) mentality whilst solidifying my ideas within this repository. As a result the API and source are absolutely tiny.
Tuple instance containing some values.
// No values.var empty = ;// A single value.var one = 'hello';// Loads of values!var loads = 'foo' 'bar' 'baz';
Extracting those values.
var point = 50 75;// You can unpack them into any names you want.// They're just function arguments!pointunpackdoStuffx * y;;
Getting a value from
var guy = 'Oliver' 'Caldwell';// Unpack returns the value that was returned by the function you passed to it.var name = guyunpackreturnfirstNamelastNamejoin' ';;name; // "Oliver Caldwell"
You can make this unpacking cleaner by passing predefined functions.
return a + b;var numbers = 10 20;var result = numbersunpackadd;result; // 30
Getting a string representation of a tuple.
var t = 'foo' 'bar';// Manual call to toString.ttoString; // "(foo, bar)"// Automatic coercion too!'Hello! ' + t; // "Hello! (foo, bar)"
Simple tuple implementation. This constructor will create new instances and store immutable values within them.
Passes the values as arguments, in the same order they were set, to the provided unpacker function. It will return the value that the unpacker returns.
Flattens the tuples values into a string.
You can execute the tests by running the local Python HTTP server (
./tools/server.sh) and navigating to http://localhost:8000/tests/.
Copyright (c) 2013 Oliver Caldwell
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.