Custom Primitive Object pairs?

Hi All,

Should Scala support Custom Primitive Object pairs?

Here are my thoughts on why it might be a good idea;

I have been messing around with some lower level IO / Tube (Byte <-> Character (/String)) conversion code in Java. Adding a few feature that always annoyed me with reading files, for example I want to process character by character from the bytes and I might want to know;

Which Line, Character and Byte in the Character has issues!

For Example in the one character UTF-8 file with binary;
1110 1111, 1011 1111, 1111 11111

The First Line, First Character Third Byte has issues since it doesn’t start with ‘10xx’.

Although I was able to get this to work, it involved building a new IO / Tube API with an interface I_Char that wrapped a String;

Char (my I_Char impl) was suppose to wrap a String length 1 but was sometimes length 2 (I believe due to issues in new String(byte[], Charset) that I never found a work around to). Found on this char (often length of 2 near the start of sequences and length of 1 after roughly 8 other characters);

‘𠜱’ //Hoping this forum is UTF-8 compatible :wink:

After all of this I briefly looked at Scala to see if it had custom primitive and Object pairs? I don’t see anything about it, but might like the following pairs, and also allow for extension;

Class / Primitive / Charset
AChar / achar / ASCII
A8Char / a8char / Union of ASII and UTF-8
LChar / lchar / ISO_8859_1
U8Char / u8char / UTF-8
U16Char / u16char / UTF-16

Also perhaps Chars a replacement for String might be necessary for clean separation?

P.S. Although I will probably not use Scala for this project right away (due to wanting GWT support), I though it worth asking the community. It might be possible to create interfaces in Java and two implementations (just optimizing a small amount of code in Scala for the JVM runtime).

I am on JVM & Java

java version “11.0.1” 2018-10-16 LTS

Java™ SE Runtime Environment 18.9 (build 11.0.1+13-LTS)

Java HotSpot™ 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

I’m not sure I understand your problem, but if I do, then Scala Value Classes are there for you.

Yes that’s pretty close to what I was looking for. I’m not sure if it will do exactly what I want, but it’s a good place to start. Thanks!