arrow-kt / arrow-core Goto Github PK
View Code? Open in Web Editor NEWΛrrow Core is part of Λrrow, a functional companion to Kotlin's Standard Library
Home Page: http://arrow-kt.io
License: Other
Λrrow Core is part of Λrrow, a functional companion to Kotlin's Standard Library
Home Page: http://arrow-kt.io
License: Other
Commit hash: 5ff8b7d0
Author: arrow-kt
More info: error log
Running this code causes the JVM to crash:
val some10 = Some(10)
val some11 = some10.map { it + 1 }
// if present, this next line with cause the crash
some11.getOrElse { Some(0) }
The crash is this:
Error: Unable to initialize main class dashfwd.CrashDemoKt
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
dashfwd/CrashDemoKt.main([Ljava/lang/String;)V @103: invokestatic
Reason:
Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'arrow/core/Option'
Full code to reproduce is available at https://github.com/dashfwd/arrow_crash
This is using:
https://github.com/arrow-kt/arrow-core/commit/85b8fe8bf826ee32f660e75a2cb337f3ac51ee48/checks
diff --cc arrow-core-data/src/test/kotlin/arrow/core/ListKTest.kt
index 96e0b4fe,7e360c21..00000000
--- a/arrow-core-data/src/test/kotlin/arrow/core/ListKTest.kt
+++ b/arrow-core-data/src/test/kotlin/arrow/core/ListKTest.kt
@@@ -24,25 -24,24 +24,46 @@@ import arrow.core.extensions.listk.trav
import arrow.core.extensions.listk.unalign.unalign
import arrow.core.extensions.listk.unzip.unzip
import arrow.core.extensions.show
++<<<<<<< HEAD
+import arrow.core.extensions.show
+import arrow.test.UnitSpec
+import arrow.test.generators.genK
+import arrow.test.generators.listK
+import arrow.test.laws.AlignLaws
+import arrow.test.laws.CrosswalkLaws
+import arrow.test.laws.EqKLaws
+import arrow.test.laws.HashLaws
+import arrow.test.laws.MonadCombineLaws
+import arrow.test.laws.MonadLogicLaws
+import arrow.test.laws.MonoidKLaws
+import arrow.test.laws.MonoidLaws
+import arrow.test.laws.MonoidalLaws
+import arrow.test.laws.SemigroupKLaws
+import arrow.test.laws.ShowLaws
+import arrow.test.laws.TraverseLaws
+import arrow.test.laws.UnalignLaws
+import arrow.test.laws.UnzipLaws
+import arrow.test.laws.equalUnderTheLaw
++=======
+ import arrow.core.test.UnitSpec
+ import arrow.core.test.generators.genK
+ import arrow.core.test.generators.listK
+ import arrow.core.test.laws.AlignLaws
+ import arrow.core.test.laws.CrosswalkLaws
+ import arrow.core.test.laws.EqKLaws
+ import arrow.core.test.laws.HashLaws
+ import arrow.core.test.laws.MonadCombineLaws
+ import arrow.core.test.laws.MonadLogicLaws
+ import arrow.core.test.laws.MonoidKLaws
+ import arrow.core.test.laws.MonoidLaws
+ import arrow.core.test.laws.MonoidalLaws
+ import arrow.core.test.laws.SemigroupKLaws
+ import arrow.core.test.laws.ShowLaws
+ import arrow.core.test.laws.TraverseLaws
+ import arrow.core.test.laws.UnalignLaws
+ import arrow.core.test.laws.UnzipLaws
+ import arrow.core.test.laws.equalUnderTheLaw
++>>>>>>> origin/master
import arrow.typeclasses.Eq
import io.kotlintest.properties.Gen
import io.kotlintest.properties.forAll
Commit hash: 6cb358c0
Author: Rachel M. Carmena
Committer: Rachel M. Carmena
More info: error log
Commit hash: f5200af4
Author: Rachel M. Carmena
More info: error log
Commit hash: 85b8fe8b
Author: Jannis
Committer: GitHub
More info: error log
Add following derived method to MonadFilter
as requested originally in the tweet mentioned in arrow-kt/arrow#1501.
fun <A> Kind<F, Option<A>>.flatten(): Kind<F, A> =
filterMap(::identity)
Add extension functions for factory methods so we can do:
list.toNel()
As well as:
NonEmptyList.fromList(list)
Commit hash: 4a130d3c
Author: Rachel M. Carmena
Committer: GitHub
More info: error log
Commit hash: fef24b63
Author: Rachel M. Carmena
Committer: GitHub
More info: error log
Uncovered by arrow-kt/arrow#1877
The current alternative law called right distributivity has a wrong implementation. As it's likely ported from cats (https://typelevel.org/cats/typeclasses/alternative.html) and cats has ap with reversed parameter order it cannot hold. I am not quite sure what the right version of that law would look like, or if it even holds at all. (Haskell does not include such laws in the first place)
Btw ap having a different parameter order causes a lot of issues in different places (monad-applicative consistency, arrow-kt/arrow#1879 )
The new Kind encoding should change to flatten partial application instead of using nesting over F
.
This allows for:
`Kind<F, A>` =!= `Kind22<F, ..Nothing..., A>` to support `Kind2<F, E, A>` that can use `Functor.map` and other methods designed for `Kind<F, A>`
This also allows us to establish a proper effects hierarchy and get rid of MonadThrow
bringing raiseError
for Throwable
up to MonadDefer
or wherever necessary if we consider instantiating Throwable
an effect.
This also opens the door to support Bifunctor behaviors for Rx, Reactor, and others with specialized data types that bake in EitherT like functionality.
This refactor is for 0.11 so we can follow the following steps:
This change impacts meta IDE features related to folding kinds and current proofs for kinds in meta and it's part of the first migration of the meta prelude to arrow-core to flatten the encoding.
generateSequence { 0 }.k().parTraverse(SequenceK.traverse()) {
IO { println(it) }
}.unsafeRunSync()
// => stackoverflow
While this code is nonsense anyway because it will infinite loop without ever printing values, it should not stackoverflow and it shows that traverse
is currently not stacksafe!
This is caused by poor use of Eval
:
https://github.com/arrow-kt/arrow/blob/712d7cf917cbf60958d1918c113bbc24b22c70f8/modules/core/arrow-core-data/src/main/kotlin/arrow/core/SequenceK.kt#L27
And similar:
https://github.com/arrow-kt/arrow/blob/712d7cf917cbf60958d1918c113bbc24b22c70f8/modules/core/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt#L160
I honestly don't know how to fix this. This will only become a problem if used with a stackunsafe applicative (Either, Option e.g.) When used on something that is stacksafe and implements lazyAp properly like the normal IO applicative everything will work fine.
Hi,
As far as I understand, each binding steps in a monad comprehension will leverage kotkin suspended function feature, this great for IO, or very intensive task, but what if I just want to use it as syntactic sugar to avoid nested flatmap structures ? For instance to compute simple Task.
To illustrate, let's take an snippet from the documentation :
binding {
val a = Try { "3".toInt() }.bind()
val b = Try { "4".toInt() }.bind()
val c = Try { "5".toInt() }.bind()
a + b + c
}
// Success(value=12)
In the example, am I correct to think the runtime overhead of maintaining suspended functions will be greater than what it brings me ?
Although, this is an overly simplified example, in real applications such computation does happen, top of head, for instance to validate user input before sending it to a service or a IO function.
Is there a way to have binding steps running normally on the main thread ? The current workaround I can think of is to use nested flatmaps but it quickly gets unreadable.
Thanks
Commit hash: 5ff8b7d0
Author: arrow-kt
More info: error log
What version are you currently using?
Currently firstOption(p)
will take the first element (via foldLeft iirc) and then apply the predicate to that returning None
in two cases: No-first element present or predicate failed. All other elements are not considered. firstOption
strictly gets the first element and then matches that against the predicate.
What would you like to see?
The stdlib methods first(p)
and firstOrNull(p)
act more like filter(p).first()
which will get the first element to match instead. I think it would be best if arrow followd along here as well as that is the behaviour to expect.
This would mean changing firstOption(p)
to fold rather than use get(0).filter(p)
but effectively it'd do the same thing.
Then we could also get rid of the explicit overrides in SequenceKFoldable
for these two methods.
Commit hash: d1eebfde
Author: danieh
Committer: GitHub
More info: error log
In Scala, Option(null) = None:
scala> Option(null)
res0: Option[Null] = None
But in arrow-kt, Option(null) = Some(null):
println(Option(null))
=> Some(null)
When interacting with JAVA, some libraries will return a null rather than an exception, which causes Some(null) appeared and leads when expression
into a failure.
when(anOption) {
is Some<T> -> anOption.t // is also nullable
is None -> "Nothing" // is unreachable
}
Hoping arrow-kt could work like Scala, and makes Some(null) = None
if possible.
What version are you currently using? 0.10
What would you like to see?
The documentation includes Try
examples. Since Try
is deprecated, these examples should be removed (or transitioned to Either
examples) to prevent confusion.
When I try to build the current master of Arrow (e610ca6677f9bc912691144437abb8e5fbb1b50b) I get a StackOverflowError from kapt. I'm on Ubuntu 18.04. My coworker on macOS doesn't have this problem. This is currently not blocking me (I don't need to build Arrow anymore), just filing the issue for reference. CC @nomisRev
Here is the truncated build output:
➜ arrow git:(master) java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-8u232-b09-0ubuntu1~18.04.1-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
➜ arrow git:(master) ./gradlew clean build
Configuration(s) specified but the install task does not exist in project :arrow-benchmarks-fx.
Configuration(s) specified but the install task does not exist in project :arrow-kio-benchmarks.
Configuration(s) specified but the install task does not exist in project :arrow-meta-test-models.
Configuration(s) specified but the install task does not exist in project :arrow-scala-benchmarks.
> Task :arrow-meta:kaptKotlin
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: com.google.auto.service.processor.AutoServiceProcessor (NON_INCREMENTAL).
> Task :arrow-kindedj:kaptKotlin
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: arrow.core.extensions.ExtensionProcessor (NON_INCREMENTAL), arrow.fold.AutoFoldProcessor (NON_INCREMENTAL), arrow.generic.CoproductProcessor (NON_INCREMENTAL), arrow.generic.ProductProcessor (NON_INCREMENTAL), arrow.higherkinds.HigherKindsProcessor (NON_INCREMENTAL), arrow.optics.OpticsProcessor (NON_INCREMENTAL).
> Task :arrow-core-data:kaptKotlin
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: arrow.core.extensions.ExtensionProcessor (NON_INCREMENTAL), arrow.fold.AutoFoldProcessor (NON_INCREMENTAL), arrow.generic.CoproductProcessor (NON_INCREMENTAL), arrow.generic.ProductProcessor (NON_INCREMENTAL), arrow.higherkinds.HigherKindsProcessor (NON_INCREMENTAL), arrow.optics.OpticsProcessor (NON_INCREMENTAL).
> Task :arrow-core-data:compileKotlin
[some warnings]
> Task :arrow-core:kaptKotlin FAILED
e: [kapt] An exception occurred: java.lang.StackOverflowError
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:447)
at java.lang.StringBuilder.append(StringBuilder.java:136)
at java.lang.StringBuilder.append(StringBuilder.java:76)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:484)
at java.lang.StringBuilder.append(StringBuilder.java:166)
at java.lang.StringBuilder.append(StringBuilder.java:76)
at kotlin.sequences.SequencesKt___SequencesKt.joinTo(_Sequences.kt:1719)
at kotlin.sequences.SequencesKt___SequencesKt.joinToString(_Sequences.kt:1743)
at kotlin.sequences.SequencesKt___SequencesKt.joinToString$default(_Sequences.kt:1742)
at kotlin.text.StringsKt__StringsJVMKt.replace(StringsJVM.kt:76)
at kotlin.text.StringsKt__StringsJVMKt.replace$default(StringsJVM.kt:75)
at arrow.meta.encoder.jvm.StringTypeExtensionsKt.removeVariance(StringTypeExtensions.kt:9)
at arrow.meta.encoder.jvm.KotlinPoetEncoder$DefaultImpls.toMeta(KotlinPoetEncoder.kt:71)
at arrow.meta.encoder.jvm.KotlinPoetEncoder$DefaultImpls.typeNameToMetaImpl(KotlinPoetEncoder.kt:154)
at arrow.meta.encoder.jvm.TypeElementEncoder$DefaultImpls.typeNameToMetaImpl(TypeElementEncoder.kt)
at arrow.meta.encoder.jvm.JvmMetaApi$DefaultImpls.typeNameToMetaImpl(JvmMetaApi.kt)
at arrow.meta.processor.MetaProcessor.typeNameToMetaImpl(MetaProcessor.kt:33)
at arrow.meta.processor.MetaProcessor$typeNameToMeta$1.invoke(MetaProcessor.kt:50)
at arrow.meta.processor.MetaProcessor$typeNameToMeta$1.invoke(MetaProcessor.kt:33)
at arrow.meta.internal.MemoizeKey1.invoke(memoization.kt:15)
at arrow.meta.internal.MemoizeKey1.invoke(memoization.kt:14)
at arrow.meta.internal.MemoizedHandler.invoke(memoization.kt:20)
at arrow.meta.internal.MemoizationKt$memoize$1.invoke(memoization.kt:7)
at arrow.meta.encoder.jvm.KotlinPoetEncoder$DefaultImpls.toMeta(KotlinPoetEncoder.kt:147)
at arrow.meta.encoder.jvm.TypeElementEncoder$DefaultImpls.toMeta(TypeElementEncoder.kt)
at arrow.meta.encoder.jvm.JvmMetaApi$DefaultImpls.toMeta(JvmMetaApi.kt)
at arrow.meta.processor.MetaProcessor.toMeta(MetaProcessor.kt:33)
at arrow.meta.encoder.jvm.KotlinPoetEncoder$DefaultImpls.toMeta(KotlinPoetEncoder.kt:94)
at arrow.meta.encoder.jvm.KotlinPoetEncoder$DefaultImpls.typeNameToMetaImpl(KotlinPoetEncoder.kt:152)
at arrow.meta.encoder.jvm.TypeElementEncoder$DefaultImpls.typeNameToMetaImpl(TypeElementEncoder.kt)
at arrow.meta.encoder.jvm.JvmMetaApi$DefaultImpls.typeNameToMetaImpl(JvmMetaApi.kt)
at arrow.meta.processor.MetaProcessor.typeNameToMetaImpl(MetaProcessor.kt:33)
at arrow.meta.processor.MetaProcessor$typeNameToMeta$1.invoke(MetaProcessor.kt:50)
at arrow.meta.processor.MetaProcessor$typeNameToMeta$1.invoke(MetaProcessor.kt:33)
at arrow.meta.internal.MemoizeKey1.invoke(memoization.kt:15)
at arrow.meta.internal.MemoizeKey1.invoke(memoization.kt:14)
at arrow.meta.internal.MemoizedHandler.invoke(memoization.kt:20)
at arrow.meta.internal.MemoizationKt$memoize$1.invoke(memoization.kt:7)
at arrow.meta.encoder.jvm.KotlinPoetEncoder$DefaultImpls.toMeta(KotlinPoetEncoder.kt:147)
at arrow.meta.encoder.jvm.TypeElementEncoder$DefaultImpls.toMeta(TypeElementEncoder.kt)
at arrow.meta.encoder.jvm.JvmMetaApi$DefaultImpls.toMeta(JvmMetaApi.kt)
at arrow.meta.processor.MetaProcessor.toMeta(MetaProcessor.kt:33)
at arrow.meta.encoder.jvm.KotlinPoetEncoder$DefaultImpls.toMeta(KotlinPoetEncoder.kt:136)
[etc...]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':arrow-core:kaptKotlin'.
> Compilation error. See log for more details
Here is the full build output with --info
logging: https://gist.github.com/abelkov/98a6a0e23e097b076a4e0a90c7c38aa9
Commit hash: f5200af4
Author: Rachel M. Carmena
More info: error log
Have versions of map
, bimap
, dimap
, etc that accept suspend functions.
suspend fun <A, B> Kind<F, A>.suspendMap(f: suspend (A) -> B): Kind<F, B>
suspend fun <E, A, B> EitherOf<E, A>.suspendMap(f: suspend (A) -> B): Either<E, B> =
fold(::Left, { f(b).right() })
something like filterIsInstance
from the stdlib, generalised for all FunctorFilter or Foldable.
Commit hash: f9b99c08
Author: Rachel M. Carmena
Committer: GitHub
More info: error log
found the issue in arrow-kt/arrow-fx#17
Functor does not generate the correct type arguments for extension functions if the Functor generic argument not named correctly.
@extension
@undocumented
interface QueueFunctor<F, A> : Functor<QueuePartialOf<F, A>> {
override fun <B, C> QueueOf<F, E, B>.map(f: (B) -> C): Queue<F, E, C>
// ...
}
the Code above will fail with the error : Type argument is not within its bounds: should be subtype of 'B'
The generated code:
fun <F, A, B> Kind<Kind<Kind<ForQueue, F>, A>, A>.widen(functorF: Functor<F>): Queue<F, A, B> =
arrow.fx.Queue.functor<F, A>(functorF).run {
[email protected]<B, A>() as arrow.fx.Queue<F, A, B>
}
The correct generated code:
fun <F, E, B, A : B> Kind<Kind<Kind<ForQueue, F>, E>, A>.widen(functorF: Functor<F>): Queue<F, E, B>
= arrow.fx.Queue.functor<F, E>(functorF).run {
[email protected]<B, A>() as arrow.fx.Queue<F, E, B>
}
The correct generated code can be achieved by changing the generic type argument name from A
to E
:
interface QueueFunctor<F, E> : Functor<QueuePartialOf<F, E>>
Commit hash: f27078e2
Author: Rachel M. Carmena
Committer: GitHub
More info: error log
What version are you currently using? 0.9.0
What would you like to see? Arrow's Option
and Try
classes implement Iterable
Consider the case where you're using Kotlin's flatMap
over its lists:
public inline fun <T, R> Iterable<T>.flatMap(transform: (T) -> Iterable<R>): List<R>
The transform
lambda can return any Iterable
. It would be handy to be able to return an Option
or Try
in a circumstance like this, where iterating an empty option would return nothing, and iterating a non-empty option would return the contents.
FWIW, VAVR's Option extends its Value, which in turn extends Java's Iterable
, so VAVR's flatMap
can accept Option
instances.
VAVR's Try
class is also Iterable
, behaving much the same as Option
, returning one or zero values when iterated.
What version are you currently using?
0.9.0
What would you like to see?
I really, really struggle with Validated / ValidatedNel
I simply do not understand why easy things like flatMap or aka bind are not available.
I have a ValidatedNel<ErrorType, Data> variable x and another function f that takes a Data and produces a ValidatedNel<ErrorType, Data> f(Data): ValidatedNel<Error, Data>
I cannot find a way to do
x.flatMap(::f)
What I want is easy:
if x is valid, take the data, run f(data) and return its result.
if x in invalid, just return x
What am I missing?
Commit hash: 2fcf3b33
Author: Jannis
Committer: GitHub
More info: error log
Embarrassingly, the Option
code samples don't compile.
The import of arrow.core.extensions.option.monad.binding
can't be resolved. Apparently fx
is in there, because it can't be resolved. The same goes for bind()
. IntelliJ doesn't come up with suggestions on where to import fx
from.
The Crosswalk instance is giving this error when proguard is enabled:
Warning: arrow.core.extensions.ListKCrosswalk$crosswalk$1$2$1$1: can't find referenced class arrow.core.extensions.ListKCrosswalk$crosswalk$1$2
More info in arrow-kt/arrow#807
Related to https://youtrack.jetbrains.com/issue/KT-16084
Commit hash: 2fcf3b33
Author: Jannis
Committer: GitHub
More info: error log
Many nested values have their own identifiers:
Some.t
Left.l
Right.r
...
This issue is to track the creation of extension syntax for all those datatypes that bring a unified access to the inner property through property extension.
Ex taken from slack where @hastebrot proposed:
package arrow.syntax.option
inline val <T> Some<T>.value get() = this.t
All these property should live in arrow.syntax.[datatype]
for consistency.
Commit hash: f5200af4
Author: Rachel M. Carmena
More info: error log
In the 0.10.x
deprecation cycle we can take the opportunity to make the Foldable
API more Kotlin idiomatic. We differ in quite some function names from the typical Kotlin naming.
nonEmpty
vs isNotEmpty
forAll
vs all
find
vs first
Foldable does have two tests covering firstOption
but they only concern the two cases F
is empty and the predicate always returns false.
This does not cover the multiple elements match the predicate case so we would have to extend the laws to cover this case.
Blocker: Split of arrow-test
into the correspondent repos (so in this case, FoldableLaws should be part of arrow-core
)
Needed to complete #32
Commit hash: 4b548a11
Author: Rachel M. Carmena
Committer: GitHub
More info: error log
Commit hash: c2b5b2d0
Author: danieh
Committer: GitHub
More info: error log
Commit hash: 5ff8b7d0
Author: arrow-kt
More info: error log
Commit hash: 0d970fb6
Author: Rachel M. Carmena
Committer: Rachel M. Carmena
More info: error log
I maintain http://pitest.org, a mutation testing system for java, which is also being increasingly used with kotlin.
Pitest includes a block coverage system, the implementation of which adds a synthetic static final field to each class.
This causes a runtime error with arrow as it attempts to write to the final field via reflection.
The problem can be reproduced in the following repo by running gradlew pitest
https://github.com/Octogonapus/reproduce-pitest-problem
Unfortunately I don't speak kotlin, and have only a hazy idea of what arrow is trying to achieve, but it seems likely that it should avoid writing to synthetic fields (and probably also final static ones).
If it does need to write to final fields then
should first change the field's modifier as well as making it accessible. e.g.
it.getModifiers() & ~Modifier.FINAL
Arrow seems to work ok with jacoco as the probe field it adds to classes is non final. There may be issues with other coverage systems however (and would be with jacoco for interfaces, as the jvm spec requires final fields in this case, but I don't know enough about arrow to know if this is a valid scenario).
From:
Current runner version: '2.168.0'
Operating System
Ubuntu
18.04.4
LTS
Virtual Environment
Environment: ubuntu-18.04
Version: 20200330.1
to:
Current runner version: '2.168.0'
Operating System
Ubuntu
18.04.4
LTS
Virtual Environment
Environment: ubuntu-18.04
Version: 20200406.2
:arrow-core:kaptKotlin
task raises this issue:
e: [kapt] An exception occurred: java.lang.StackOverflowError
It seems it comes from this piece of source code:
arrow-meta/src/main/java/arrow/meta/encoder/jvm/KotlinPoetEncoder.kt
fun com.squareup.kotlinpoet.TypeVariableName.toMeta(): TypeName.TypeVariable =
TypeName.TypeVariable(
name = name.asKotlin(),
bounds = bounds.map
{ metaApi().run { it.toMeta().removeConstrains() } },
annotations = annotations.map
{ it.toMeta() },
nullable = isNullable,
reified = isReified,
variance = variance?.toMeta()
)
val typeNameToMeta: (typeName: com.squareup.kotlinpoet.TypeName) -> TypeName
fun com.squareup.kotlinpoet.TypeName.toMeta(): TypeName =
typeNameToMeta(this)
fun typeNameToMetaImpl(typeName: com.squareup.kotlinpoet.TypeName): TypeName =
when (typeName) {
is ClassName -> typeName.toMeta()
is ParameterizedTypeName -> typeName.toMeta()
is TypeVariableName -> typeName.toMeta()
is WildcardTypeName -> typeName.toMeta()
else -> throw IllegalArgumentException("arrow-meta has no bindings for unsupported type name: $typeName")
}
Instead of using latest Ubuntu for CI environmentst, Ubuntu 16.04 is going to be used for arrow-core
and global integration checks where arrow-core
is also built. macOS
works except for some actions (Linux-compatible commands).
With switching from generified Try.Failure to Try.Failure<Nothing> by default (PR: arrow-kt/arrow#971 ), a strange issue pops up:
fun causesVerifyError(): Try<Boolean> {
val b = someBooleanFunction()
return Try.Success(b)
.map {
!it
}
}
causes
java.lang.VerifyError: Bad return type
Exception Details:
Location:
MainKt.causesVerifyError()Larrow/core/Try; @88: areturn
Reason:
Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'arrow/core/Try' (from method signature)
Current Frame:
bci: @88
flags: { }
locals: { integer, 'arrow/core/Try$Success', 'arrow/core/Try$Success', 'arrow/core/Try$Success' }
stack: { 'java/lang/Object' }
Bytecode:
0x0000000: b800 223b bb00 2459 1ab8 002a b700 2e4c
0x0000010: 002b 4d2c 4e2d c100 3099 0007 2ca7 0039
0x0000020: 2cb6 0034 3a04 1904 c000 26b6 0037 3605
0x0000030: 1505 9a00 0704 a700 0403 b800 2a3a 0e19
0x0000040: 0e3a 0fbb 0024 5919 0fb7 002e c000 393a
0x0000050: 0719 07c0 003b 0000 b0
Stackmap Table:
full_frame(@32,{Integer,Object[#36],Object[#36],Object[#36]},{})
append_frame(@57,Object[#4],Integer)
same_locals_1_stack_item_frame(@58,Integer)
full_frame(@86,{Integer,Object[#36],Object[#36],Object[#36]},{Object[#4]})
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Error: A JNI error has occurred, please check your installation and try again
Whereas following workaround works:
fun causesVerifyError(): Try<Boolean> =
with(someBooleanFunction()) {
Try.Success(this)
.map {
!it
}
}
Kotlin version: 1.3.11
JDK Target: 1.8
JDK: 1.8.0_181
Hi, I am trying to use monadError and face a trouble that let me think it might be a trouble there.
I made an easy implementation of two functions returning a higherKind function:
private val objectGateway: objectGateway = object : ObjectGateway {
override fun <F> getObject1(number: String, ME: MonadError<F, DummyException>): Kind<F, String> {
return ME.just("NUMBER")
}
override fun <F> getObject2(number: String, anotherNumber: String, ME: MonadError<F, DummyException>): Kind<F, Int> {
// return ME.just(1)
return ME.raiseError(DummyException("There is the cause"))
}
}
I am capable to call them using the Either MonadError like that:
val monadError = Either.monadError<DummyException>()
val object1 = objectGateway.getObject1("NUMBER", monadError)
val object2 = objectGateway.getObject2("1", "NUMBER", monadError)
and it works fine. I get the object in right and exception in left part of the either.
But then if I try to change for an Option monad Error it does not compile
val monadError = Option.monadError()
val object1 = objectGateway.getObject1("NUMBER", monadError)
val object2 = objectGateway.getObject2("1", "NUMBER", monadError)
I get a type inference failed, cannot be applied to (String, OptionMonadError)
From my understanding I should be able by the monadError to swap from Either to Option of Try. The Monad assume the behaviours and adapt to one of those Type classes.
Thanks in advance for your answer.
In arrow-kt/arrow#1898 ap parameter order was changed. This should be deprecated in 0.10.x
We have a duplicated function name that performs 2 completely different things
unit for Applicative
fun unit(): Kind<F, Unit> = just(Unit)
and unit for Functor
fun <A> Kind<F, A>.unit(): Kind<F, Unit> = map { Unit }
The problem with this can be easily spotted when having an extension function over an interface extending, for example, MonadError, where you wanna start calling unit(), as both functions can be resolved, there's no guarantee of which one will be called, causing possible bugs. Here unit could either mean just(Unit)
or this.map { Unit }
:
fun <A> Kind<F, A>.something(...): Kind<F, A> =
unit().doSomethingElse()
I'd suggest removing/renaming the unit() from Functor as the name is not indicating a map transformation whatsoever. Maybe simply mapUnit
? cc @arrow-kt/maintainers
EDIT: Functor#void
should be renamed to void
which is similar to Haskell and implies that the output is mapped to Unit
or void'ed rather than returning a lifted Unit
value from Applicative
.
Since this is a breaking change this should be deprecated in 0.10.x and fully replaced in 0.11.0.
Each inline declaration of a function, i.e. pipe
, it may force callsites to create an anonymous class to capture the scope. This is an issue in Android land, due to the dex format and its limitations around method count and size.
If we can validate this assumption in the bytecode viewer, it's worth consider doing a pass on the codebase and remove many unnecessary inline annotations.
What'cha think.
Commit hash: 0d970fb6
Author: Rachel M. Carmena
Committer: Rachel M. Carmena
More info: error log
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.