You may have already seen that `Try` is deprecated...
# arrow
r
You may have already seen that
Try
is deprecated in favor of IO and suspend. Changes like this are coming to other data types to eliminate nesting and improve ergonomics. Once Arrow Meta is available if you choose to use it you can entirely eliminate
Either
and all result types in Kotlin of Arbitrary arity. We are working on a plugin for Arrow Meta for Union Types. These union types are Coproducts of arbitrary arity that can be used without nesting:
Copy code
@optics
@recursion
typealias Result<A> = Union<Error, A> // Union<A, B, ...> synthetic and of arbitrary arity up to 22

val a: Result<Int> = error //ok, no need to error.left()
val b: Result<Int> = 1 // ok, no need to 1.right()
val c: Int? = a // ok because it's an error becomes `null`
val d: Int? = b // ok because it's an Int and stays Int
val e: Result<Int> = "other type" // not ok because not an error or an Int. String is not part of the union

val exhaustiveChecks = 
  when (a) {
    is Error -> TODO()
    is Int -> TODO()
  }

a.fold({ e: Error -> TODO() }, { n: Int -> TODO() }) //@recursion folds cata and recursion schemes

Result.error.msg.modify(a, String::trim) // @optics DSLs for all union and products
As you can see in the example above there is no notion of left/right constructors and the datatype type args won’t be constrained to
2
. This also removes the need to use ADTs or sealed classes when your intention is just representing a disjoint union with types you don’t own or can’t modify. Additionally it will include a leaner runtime than Arrow Either or Arrow Coproduct because we can use the type checker in meta at compile time to determine when values are of the union and avoid allocation with unnecessary wrapping
p
where does the lens
.error
comes from? Is it synthesised from the type name? @raulraja