Rich2 / openstrat

Cross Platform Scala 2d graphics (but 3d compatible), basic geometry, maps, Earth maps, hex-tiling and strategy library(s).
https://richstrat.com
Apache License 2.0
22 stars 8 forks source link

Emon[T] Errors Handler #81

Closed w0d closed 5 years ago

w0d commented 5 years ago

i could hack this but in the interest of writing reasonable code how can you extract the Good from ostrat.EMon[string]?

    val loadData = canv.loadFile("test")  //this returns a EMon
    if (loadData.isGood)  //make sure its good
    {
      turn = loadData.XXX.toString.split("\n")(0).toInt
      deb("turn=" + turn)
    }

have tried various XXX but no joy :(

also need help converting a string to colour: this line seems to work: val myColor = Colour.strToValue("Red") but this one doesn't: players = "Red,Blue,Green,Yellow".split(",").map[Colour](c => Colour.strToValue(c))

any pointers appreciated

Rich2 commented 5 years ago

@w0d The simplest way to consume an EMon is with a foreach. Will give more detailed response later.

Rich2 commented 5 years ago

@w0d So the name needs to be short because the Emon should be used over and over again in code. However Emon is short for Errors Monad which is cryptic to most programmers let alone most people, so I suggest possibly Ehan, which would be short for errors handler.

Once a name has been agreed, I suggest closing the issue and starting a new general issue on the documentation of the trait under the new name.

w0d commented 5 years ago

not so sure about the starting premise there. im only just beginning to understand about the error monand and need to acquire a bit more knowledge to contribute more fully - though as i stand now "result" feels more encompassing without being cryptic (monand) / misdirecting (handler)

happy for this to be closed as i now have a solution to the original issue: use foreach to access element in Emon