Skip to content

Latest commit

 

History

History
89 lines (70 loc) · 1.45 KB

README.md

File metadata and controls

89 lines (70 loc) · 1.45 KB

cassava

java csv encoder/decoder

csv encoding

// only object(data class ~> not equiv of data class in haskell) based encoding
var encoded = Csv.encode(new Audience(
        "android",
        "Luyata",
        1,
        10.0, 
        true
));

// output
android,Luyata,1,10.0,true

//encode with header
var encodeWithHeader = Csv.encodeWithHeader(new Audience(
        "android",
        "Jumla",
        1,
        10.9, 
        false
));

// output
platform,location,deviceId,dwell,reached
android,Jumla,1,10.9,false

csv decoding

Audience audience = Csv.decode("android,Jumla,1,10.9, false", Audience.class);

async csv writer

var success = FileWriter.openStream("/tmp/abc.csv")
        .thenCompose($ -> $.append(encoded))
        .thenCompose($ -> $.flushStream())
        .thenCompose($ -> $.closeStream());

//failure example
var failure = FileWriter.openStream("/dont_exist/abc.csv")
        .thenCompose($ -> $.append(encoded))
        .thenCompose($ -> $.flushStream())
        .thenCompose($ -> $.closeStream());

failure.handle((s, f) -> {
    if (f != null)
        System.out.println("error: " + f);
    return s;
});

TODO

  • encode nested data classes
class A {
    B b;
}

class B {
    String s;
    Double d;
}

// output
s,d
  • release jar 0.1

reference