quick question about ANK let's say I have a seale...
# arrow
s
quick question about ANK let's say I have a sealed class in a code snippet:
Copy code
sealed class ValidationResult<out E, out A> {
    data class Valid<A>(val a: A) : ValidationResult<Nothing, A>()
    data class Invalid<E>(val e: E) : ValidationResult<E, Nothing>()
}
And I want to use `Valid`/`Invalid` without prefixing with
ValidationResult
. How can I do that... I tried
Copy code
import ValidationResult.Valid
import ValidationResult.Invalid
but it doesn't work.... Error I am getting is (when trying to use just `Valid`:
Copy code
error: unresolved reference: Valid
            if (a is Valid && b is Valid) valid(f(a.a, b.a))
PS I know about
Validated
from arrow... I am doing poor mans validated first 😄
i
This works for me:
Copy code
val b = {a: ValidationResult<*,*>, b: ValidationResult<*,*> ->  if (a is ValidationResult.Valid && b is ValidationResult.Valid) valid(f(a.a, b.a)) }
Whatever your valid function is
s
I would like to use
Valid
instead of
ValidationResukt.Vali
(fits better on slides) I can do it in IDEA, but not in ANK
in IDEA I can do
import <package>.ValidationResult.Valid
I could also use a shorter name.....
r
there is something off with the way the evaluation of snippets works in script vs regular KtFiles related to scopes
A workaround in this case may be to define those typealiases in the script itself hidden before the example code. Otherwise you may try moving the classes outside at the same level as ValidationResult
s
I will try the first workaround... The second one I already tried.... but it complains it can't access <init> of ValidationResult..... i guess It treats it like it's not in the same file... thanks @raulraja
typealias did the trick: BUILD SUCCESSFUL in 15s 🕺 thanks again
👍 1
and how do I hide the typealiases? could not find that in the docs 😕
r
it’s only possible in ank playgrounds
since it colapses that with JS in the rendering
if you are using simple ank rendering is not possible at the moment
s
just plain Ank.... but it's still better than using the long name.... do you have a sample with Ank Playground + Reveal JS that I could check? I believe Jorge used that for Kotliners but not sure if the source is shared publicly somewhere
The arrow docs themselves are packed with examples of playgrounds
And instructions to embed it in any website. @paco is making changes to the server in these days though to accommodate multiple arrow versions.