Just want to voice my love for `impure`! I'm writi...
# arrow
y
Just want to voice my love for
impure
! I'm writing an IntelliJ plugin, and
impure
is a perfect fit for the Visitor pattern.
very nice 1
Tell me this isn't readable!
Copy code
override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) = impure {
  super.visitSimpleNameExpression(expression)

  ensure(expression.parent !is KtThisExpression && expression.parent !is KtSuperExpression && expression !is KtLabelReferenceExpression)
  analyze(expression) {
    val reference = expression.mainReference.resolveToSymbol()
    ensure(reference is KaAnnotated)
    val annotation = reference.annotations[PRETTY].singleOrNull().bind()
    val name = annotation.findConstantArgument(PRETTY_NAME)
    ensure(name is String)

    add(PrettyFoldingDescriptor(expression, name))
  }
}
c
not easy finding its documentation laugh cry face palm
is it the same as
Copy code
nullable {
    ignoreErrors {

    }
}
?
y
I'm pretty sure impure was a suggestion by you lol! It's like
nullable
but always returns
Unit
, so both the error side and success side are
Unit
c
was it 😅
oh so it just shortcircuits, right?
I see, yeah, could've been me 🤣
y
Yeah, so it lets me short circuit out of the visitor method early, while getting smartcasts and stuff. I could just use
return
a whole bunch of times, but
ensure
and
bind
are cleaner
c
Yeah that definitely sounds like me, I completely forgot it got merged