Git Product home page Git Product logo

fpinkotlin's Introduction

Function Programming in Kotlin

master build

This is the official source code repository for Manning's Functional Programming in Kotlin book. It contains all code samples and exercises that appear in the book.

Book build process

The book itself is written in AsciiDoc, and is built using Asciidoctor. The code in the repo is the exact code that appears in the book. Asciidoctor pulls all code snippets from this repo via a git submodule, which implies that all code in the book has been compiled, and where applicable, tested. The exercise listings are also taken from this repo, as are the solutions found in the appendix at the back of the book. All exercises and solutions have unit tests to prove their validity.

Running the tests when doing the exercises

This repo is not only used for the purpose of providing the code in book, but can also be used by the reader to complete the exercises. All unimplemented exercises can be found under src/test/kotlin/chapterX/exercises, and are marked with the builtin TODO() function that Kotlin provides. Each unit test has been ignored, and can be re-enabled by removing the ! prefix in the test methods while implementing the exercises in a TDD fashion. Solutions are also provided for verification of the exercises, but should be avoided until at least an attempt has been made at doing the exercises. The solutions can be found under src/test/kotlin/chapterX/solutions. It is encouraged that the student works through all exercises in the book to gain the required proficiency.

Building the project

The project is built using Gradle with the Kotlin DSL. The project requires JDK 11 to build. You can install the correct version of JDK using SDKMAN! as follows.

$ sdk env

Next, run the build locally. Simply execute the following on the command line:

$ ./gradlew check

Alternatively, the project can be imported into IntelliJ IDEA and run from within the IDE.

Continuous Integration

The project builds with GitHub actions, ensuring that the code always compiles, is correctly formatted and all tests pass, thus validating all the code in the book.

Contributions

See something that doesn't look correct, or do you have a better solution to an exercise? Feel free to raise a PR to improve or correct it.

fpinkotlin's People

Contributors

avilaplana avatar jeffmorin avatar jj97 avatar kalistace avatar lgtout avatar marc0der avatar xuebingli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fpinkotlin's Issues

Project Does Not Build

I believe the build instructions are out of date and no longer work. I'm only able to get the project to build by deleting content from Chapters 13-15.

Machine: MacBook Pro, 16-inch, 2021, Apple M1 Pro
OS: macOS 13.1 (22C65)
IDE: IntelliJ IDEA 2022.3 (Community Edition)

Command: ./gradlew clean check

Output:

> Task :kaptKotlin FAILED
e: java.lang.IllegalStateException: failed to analyze: java.lang.reflect.InvocationTargetException
        at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:56)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:128)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:159)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:442)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:102)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1013)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
        at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1055)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1012)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:441)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
        at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:55)
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:31)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:223)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:187)
        at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:98)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:96)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:106)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:384)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:70)
        at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:375)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:123)
        ... 30 more
Caused by: com.sun.tools.javac.processing.AnnotationProcessingError: javax.lang.model.type.UnknownTypeException: Unknown type: "none"
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1037)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:940)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1269)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1384)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1261)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1160)
        ... 47 more
Caused by: javax.lang.model.type.UnknownTypeException: Unknown type: "none"
        at [email protected]/javax.lang.model.util.AbstractTypeVisitor6.visitUnknown(AbstractTypeVisitor6.java:160)
        at com.squareup.kotlinpoet.TypeName$Companion$get$1.visitNoType(TypeName.kt:177)
        at com.squareup.kotlinpoet.TypeName$Companion$get$1.visitNoType(TypeName.kt:121)
        at jdk.compiler/com.sun.tools.javac.code.Type$JCNoType.accept(Type.java:2241)
        at com.squareup.kotlinpoet.TypeName$Companion.get$kotlinpoet(TypeName.kt:121)
        at com.squareup.kotlinpoet.TypeNames.get(TypeName.kt:231)
        at arrow.meta.encoder.jvm.TypeElementEncoder$DefaultImpls.asConstructor(TypeElementEncoder.kt:398)
        at arrow.meta.encoder.jvm.JvmMetaApi$DefaultImpls.asConstructor(JvmMetaApi.kt)
        at arrow.meta.processor.MetaProcessor.asConstructor(MetaProcessor.kt:33)
        at arrow.meta.encoder.jvm.TypeElementEncoder$DefaultImpls.type(TypeElementEncoder.kt:88)
        at arrow.meta.encoder.jvm.JvmMetaApi$DefaultImpls.type(JvmMetaApi.kt)
        at arrow.meta.processor.MetaProcessor.type(MetaProcessor.kt:33)
        at arrow.meta.encoder.jvm.TypeElementEncoder$DefaultImpls.asMetaType(TypeElementEncoder.kt:447)
        at arrow.meta.encoder.jvm.JvmMetaApi$DefaultImpls.asMetaType(JvmMetaApi.kt)
        at arrow.meta.processor.MetaProcessor.asMetaType(MetaProcessor.kt:33)
        at arrow.meta.encoder.jvm.JvmMetaApi$DefaultImpls.getType(JvmMetaApi.kt:274)
        at arrow.meta.processor.MetaProcessor.getType(MetaProcessor.kt:33)
        at arrow.meta.encoder.jvm.JvmMetaApi$DefaultImpls.typeClassInstance(JvmMetaApi.kt:636)
        at arrow.meta.processor.MetaProcessor.typeClassInstance(MetaProcessor.kt:33)
        at arrow.core.extensions.ExtensionProcessor.transform(ExtensionProcessor.kt:26)
        at arrow.meta.processor.MetaProcessor.onProcess(MetaProcessor.kt:76)
        at arrow.common.utils.AbstractProcessor.process(AbstractProcessor.kt:108)
        at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:106)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1025)
        ... 52 more


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':kaptKotlin'.
> Internal compiler error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 10s
6 actionable tasks: 6 executed

The instructions from the README and here on Issue 40 don't fix the problem. See below:
Command: sdk env

Output:

Stop! Candidate version is not installed.

Tip: Run the following to install this version

$ sdk install java 11.0.13-tem

Command: sdk install java 11.0.13-tem

Output:



Stop! java 11.0.13-tem is not available. Possible causes:
 * 11.0.13-tem is an invalid version
 * java binaries are incompatible with your platform
 * java has not been released yet

Tip: see all available versions for your platform:

  $ sdk list java

Still, I tried using java 11.0.17-tem, but it still doesn't work. Any ideas how I can get this project working?

Exercise 9.5 solution produces a StackOverflowError

If you checkout #45 and run the main function in src/test/kotlin/chapter9/solutions/ex5/listing.kt, you should get a StackOverflowError. I'm guessing this is wrong, as the whole point of the exercise was to produce a non-strict combinator.

Refactored Ch8 code for ease of understanding

Hello, @marc0der!

I had quite a bit of difficulty following the code in 8.3.3 listing.kt and in ch 8 Boilerplate.kt.

So as an exercise to get me through the chapter, I refactored the code into a shape I found more accessible.

Here's the gist.

The main things changes are:

  1. I replaced data classes that have no state and only serve as wrappers for functions with true function types. The code-noise from wrapping and unwrapping made it harder to follow.

  2. I added 2 private "Prop-lite" interfaces that exclude parameters that are ignored. Creating Props with parameters that are ignored or calling them with arguments that are ignored introduced cognitive overhead that made it harder to follow.

  3. Converted functions that would otherwise be standalone functions after my changes to extension functions for better ergonomics.

I'm not submitting it as a PR because the changes ripple through the project, beyond just chapter 8. And the approach I take may diverge too greatly from the text in the book. It's also possible that the approach is too specific to how my mind works.

But I wanted to share it nonetheless. If you do prefer it, let me know and I'll put together a proper PR.

Cheers!

Julian

Suggestion for Exercise 10.11 test

How about showing that wordCount works well with text that contains whitespace of various patterns on the test like below?

class Exercise11 : WordSpec({
    val words: List<String> =
        " lorem ipsum dolor sit amet,  consectetur adipiscing elit, sed do "
            .split(" ")

    "word count" should {
        "count words using balanced folding" {
            assertAll(Gen.list(Gen.from(words))) { ls: List<String> ->
                val text = ls.joinToString(" ")
                val expectedWordCount = ls.filter { s -> s.isNotEmpty() }.size

                println("${expectedWordCount}: $text")
                wordCount(text) shouldBe expectedWordCount
            }
        }
    }
})

The seed text has a whitespace at the start and end.
It also has two whitespaces after sit amet,.
So it is needed to filter the empty string to get the right expectedWordCont.

Complete JSON parser implementation

This issue is a placeholder for a task that still needs to be completed for chapter 9 on parser combinator library design. The chapter focuses heavily on algebraic design with deferred implementation of the algebra.

All code samples and exercises for the chapter compile, although the focal point of the chapter is to implement a working JSON parser. Due to time constraints in delivering subsequent chapters, this implementation was deferred.

The correct way to get this parser operational is by using tests to prove the implementation of all primitives and combinators. It would be best to start with the primitives, then build up towards increasingly complex combinators. Finally, tests should be put in place that test the parser in its entirety.

Also worth mentioning that this is a port of the original parser that appears in the solutions of the original FP in Scala red book. The Scala implementation is fully operational and can be used as a reference for the Kotlin version.

Code no longer builds with latest Arrow library

The code does not seem to compile any more with the latest version of Arrow. I suspect some functionality described in the book has since been removed.

Please update the book and the source, this is very confusing.

Java 11 openjdk, IntelliJ IDEA 2023.3.1

Java 11 openjdk, IntelliJ IDEA 2023.3.1

11 Version of java set globally by jenv on my m1-mac.
I try to solve first task in project, but project doesn't compile:

#java --version
openjdk 11.0.21 2023-10-17
OpenJDK Runtime Environment Homebrew (build 11.0.21+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.21+0, mixed mode)

 #./gradlew check
> Task :ktlintKotlinScriptCheck UP-TO-DATE
> Task :ktlintMainSourceSetCheck UP-TO-DATE
> Task :ktlintTestSourceSetCheck UP-TO-DATE

> Task :kaptGenerateStubsKotlin FAILED
e: java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x3cf646a4) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x3cf646a4
        at org.jetbrains.kotlin.kapt3.base.KaptContext.<init>(KaptContext.kt:27)
        at org.jetbrains.kotlin.kapt3.KaptContextForStubGeneration.<init>(KaptContextForStubGeneration.kt:40)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.contextForStubGeneration(Kapt3Extension.kt:277)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:164)
        at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:98)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:96)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:106)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:384)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:70)
        at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:375)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:123)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:159)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
        at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:357)
        at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:99)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:222)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:37)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:88)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:100)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:590)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:102)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:455)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1013)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
        at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1055)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1012)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:454)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:840)


FAILURE: Build failed with an exception.

When run test from IDE: in class Par unresolved reference for completeAsync and project doesn't compile too.

изображение

./gradlew check fails to build

Running a test within IntelliJ (lastest version) or even gradlew check from the command line results in this failure.

e: java.lang.IllegalStateException: failed to analyze: java.lang.reflect.InvocationTargetException
        at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:56)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:128)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:159)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:442)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:102)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1013)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
        at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1055)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1012)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:441)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
        at java.base/java.lang.Thread.run(Thread.java:832)

Exercise 10.11 solution has a typo

In the code below, wc.rs should be wc.ls.

return when (val wc = foldMap(s.asSequence(), WCM) { wc(it) }) {
        is Stub -> unstub(wc.chars)
        is Part -> unstub(wc.rs) + wc.words + unstub(wc.rs)
    }

Ch 8 Gen#choose may bias generated number distribution

fun choose(start: Int, stopExclusive: Int): Gen<Int> =
Gen(State { rng: RNG -> nonNegativeInt(rng) }
.map { start + (it % (stopExclusive - start)) })

I don't know if this is important, but choose cannot produce random numbers with uniform distribution even if nonNegativeInt can, because the range of non-negative Ints may not be a perfect multiple of stopExclusive - start. In this case some numbers within the range of (start, stopExclusive] will appear more frequently than others.

Exercise 3.9 foldLeft tailrec doesn't work

Using foldLeft on a large list causes a StackOverflowError. But I was under the impression that the tailrec keyword would be compiled to a loop and remove the recursion.

This new failing test highlights the issue: #47

I don't think I've done something stupid in the test! Any idea why the recursion isn't removed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.