Name |
Ceylon Chayote - Various Utility Functions and Classes |
---|---|
Backends | JVM JavaScript |
Maven coordinates | |
Compatible Ceylon release |
JVM: 1.1.0 (outdated) JavaScript: 1.1.0 (outdated) |
Published | Apr 25, 2015 |
Stats |
Downloads (JVM): 393 Downloads (JS): 144 Source downloads: 484 |
Authors |
Luke deGruchy |
License | Apache Software License |
Description |
Various utility classes and methods for Ceylon. These are intended to all be written in native Ceylon, with no dependency on JDK-specific modules. Format Integers as either hex or bits Strings with padding and underscores to make them more readable. print(formatAndPadAsBits(30)); > <b>0001_1110</b> print(formatAndPadAsHex(500000); > <b>0007_a120</b> Functions to return immutable collections succinctly: List<String> anImmutableList = immutableList{"one","two","three"}; Set<Integer> anImmutableSet = immutableSet{1,2,3}; Map<String,Integer> anImmutableMap = immutableMap{"one"->1,"two"->2,"three"->3}; Helper functions for equals() and hash: hashes(myObject.myInteger,myObject.myString); > <b>1312847</b> equalsWith(myObject.myInteger,otherObject.myInteger); > <b>true</b> or <b>false</b> equalsWithMultiple([myObject.myInteger,otherObject.myInteger], [myObject.myString,otherObject.myString]); > <b>true</b> or <b>false</b> Functions to translate Integers into Sequences of Bytes integerToBytes(941226); > <b>[0, 0, 0, 0, 0, $1110.byte, $0101_1100.byte, $1010_1010.byte]</b> integerToBytesNoZeros(941226); > <b>[$1110.byte, $0101_1100.byte, $1010_1010.byte]</b> Support left and right bit rotation on [[Integer]]s. rotateLeft($1010_0101, 4); > <b>$1010_0101_0000</b> rotateRight($1010_0101, 4); > <b>$0101_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1010</b> Convenience function: helpString() to help output class string attributes. helpString("Thing", "Name"->"FirstThing", "Number"->1, "Optional"->null); > <b>"Thing:{Name=FirstThing,Number=1,Optional=null}"</b> Wrapper types for commonly used types to add unique typing. Example, in contexts where several Integer variables are used for different concepts such as AccountNumber, ReferenceNumber, etc Examples: class AccountNumber(Integer baseValue) extends TypedInteger<AccountNumber>(baseValue) {} class ReferenceNumber(Integer baseValue) extends TypedInteger<ReferenceNumber>(baseValue) {} value accountNum1 = AccountNumber("1"); value accountNum2 = AccountNumber("2"); value refNum1 = ReferenceNumber("1"); value refNum2 = ReferenceNumber("2"); assertFalse(accountNum1.equals(accountNum2); assertFalse(accountNum1.equals(referenceNum1); assertFalse(referenceNum2.equals(accountNum2); |
Dependencies | |
Usage |
import herd.chayote "0.0.8"; |
Module links |
Members Imported By Home Code repository Issue tracker Browse Download .car Download .js Download source archive Download module documentation View API documentation |