Giter Site home page Giter Site logo

handsonscala / handsonscala Goto Github PK

View Code? Open in Web Editor NEW
659.0 26.0 163.0 57.76 MB

Discussion and and code examples for the book Hands-on Scala Programming

Home Page: https://www.handsonscala.com/

License: Other

HTML 15.42% TSQL 53.35% Scala 24.28% Shell 0.92% Jsonnet 0.12% Java 0.04% JavaScript 0.04% CSS 5.82%

handsonscala's Introduction

Hands-on Scala Programming

This repository is the online hub for the book Hands-on Scala Programming:

Executable Code Examples

The executable code examples from Hands-on Scala are freely available online, and open source under an MIT license. These examples are meant to be useful to anyone who is interested in learning Scala, whether or not they are working through Hands-on Scala Programming, though following along with the book will give you the best experience and help you get the most out of them.

Each example is:

  • Self-contained: to be run either using the Ammonite script runner or Mill build tool, with no other setup

  • Tested: with simple test suites provided and instructions on how to run each example in that folder's readme.md file

  • Executable: you can download the folder and run the example yourself to see it in action

Many of the examples are related, with only small code changes between them to illustrate a new feature or technique. The readme.md file of such downstream examples will show a diff from the upstream example that it was based upon, so you can focus your attention on the important code changes that are happening, with a link back up to the upstream example.

The executable code examples below are organized by each part and each chapter of the book.

  • 3.1 - Values: Using Numbers, Strings, Options and Arrays
  • 3.2 - LoopsConditionals: Using Loops, If-Else statements and expressions, and List Comprehensions
  • 3.3 - MethodsFunctions: Basic Usage of Methods and Function Values
  • 3.4 - ClassesTraits: Basic usage of Classes and Traits
  • 3.5 - FlexibleFizzBuzz: Implementation of FizzBuzz that takes a callback used to handle the generated strings
  • 3.6 - PrintMessages: A method to render a flat array of Msg instances into a "threaded" conversation with child messages printed nested under their parents
  • 3.7 - ContextManagers: Methods that act as Python "context managers", opening a file reader/writer, passing the reader/writer to a callback, and closing the file after.
  • 6.1 - MergeSort: Simple merge-sort implemention, hard-coded to only work on Array[Int]
  • 6.2 - GenericMergeSort: Generic merge sort implemention, that can sort any IndexedSeq[T] with an Ordering
  • 6.3 - Trie: A simple mutable Trie implemention
  • 6.4 - Search: Breadth-first-search implemention
  • 6.5 - SearchPaths: Breadth-first-search implemention that keeps track of the shortest paths to every node
  • 6.6 - BinarySearch: Binary search implementation
  • 6.7 - ImmutableTrie: Immutable trie implementation
  • 6.8 - DepthSearchPaths: Depth-first search implementation that keeps track of shortest paths
  • 6.9 - Sudoku: Sudoku solver implemented via depth-first search
  • 6.10 - TrieMap: Using a trie to implement a Map[String, T]-like data structure
  • 6.11 - FloodFill: Breadth-first implemention of a floodfill algorithm, taking a callback that allows the user to specify what color pairs are similar enough to traverse
  • 9.1 - Printing: Listing blog-post-like files in a folder and printing them out
  • 9.2 - Index: Rendering an index.html for our static blog using Scalatags
  • 9.3 - Markdown: Rendering individual blog posts using Atlassian's Commonmark-Java library
  • 9.4 - Links: Adding links between our index.html and the individual blog posts
  • 9.5 - Bootstrap: Prettifying our static blog using the Bootstrap CSS framework
  • 9.6 - Deploy: Optionally deploying our static blog to a Git repository
  • 9.7 - DeployTimestamp: Displaying the .md file last-modified time on each blog post
  • 10.1 - Simple: Simple linear build pipeline
  • 10.2 - Nonlinear: Simple non-linear build pipeline with two branches
  • 10.3 - Modules: Simple non-linear build pipeline, replicated in several modules
  • 10.4 - NestedModules: Nested modules in a Mill build pipeline
  • 10.5 - CrossModules: Using cross-modules to dynamically construct a build graph based on the filesystem
  • 10.6 - Blog: Our static blog generator, converted into an incremental Mill build pipeline
  • 10.7 - ExtendedBlog: Adding previews and bundled Bootstrap CSS to our static blog build pipeline
  • 10.8 - Push: Re-adding the ability to deploy our static blog by defining a T.command
  • 10.9 - PostPdf: Static blog pipeline which can generate PDFs for each blog post using Puppeteer
  • 10.10 - ConcatPdf: Static blog pipeline which can generate PDFs for each blog post and concatenate them using Apache PDFBox
  • 11.1 - ScrapingWiki: Scraping headlines off the Wikipedia front page using Jsoup
  • 11.2 - ScrapingDocs: Scraping semi-structured content off of the Mozilla Development Network Web API docs
  • 11.3 - ApiStatus: Using Jsoup to scrape the status annotations for every Web API on MDN
  • 11.4 - ExternalLinks: Crawling the pages of a static website to extract every external link on the site
  • 11.5 - ScrapingTrees: Using Jsoup to scrape the tree-shaped comments of a threaded discussion forum
  • 17.1 - Main: Simple two-process batch file synchronizer that could work over a network
  • 17.2 - FileSyncer: Simple two-process batch file synchronizer that could work over a network
  • 17.3 - Pipelined: Pipelined version of our two-process file synchronizer, minimizing the chattiness of the protocol
  • 17.4 - Deletes: Pipelined two-process file synchronizer that supports deletions
  • 17.5 - Gzip: File syncer with compressed data exchange between the Sync and Agent processes
  • 17.6 - Ssh: Networked of our two-process file synchronizer, running the agent on a separate computer and interacting with it over SSH
  • 18.1 - Simple: Simple real-time file synchronizer that uses os.watch to react to filesystem changes as they happen
  • 18.2 - Pipelined: Pipelined real-time file synchronizer, allowing RPCs and hashing to take place in parallel
  • 18.3 - InitialFiles: Real-time file synchronizer that supports syncing an initial set of files
  • 18.4 - ForkJoinHashing: Real-time file synchronizer that does hashing of files in parallel
  • 18.5 - Deletes: Real-time file synchronizer supporting deletion of files
  • 18.6 - VirtualFileSystem: Real-time file synchronizer that keeps track of synced files, avoiding RPCs for destination file hashes

handsonscala's People

Contributors

lihaoyi 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

handsonscala's Issues

Failed to resolve ivy dependencies:Boxed Exception

I am trying to import build with metals:

// build.sc
import mill._, scalalib._

object foo extends ScalaModule{
  def scalaVersion = "2.13.2"
  object test extends Tests{
    def ivyDeps = Agg(ivi"com.lihaoyi::utest:0.7.4")
    def testFrameworks = Seq("utest.runner.Framework")
  }
}

And I get
Failed to resolve ivy dependencies:Boxed Exception
I tried with both 0.8.0 and 0.9.9 Mill versions

testing with utest

I copied build.sc (2.18.scala) on page 31 of the book into a VSCode /mill setup. I keep getting:
compiling 1 Scala source to /.../.../WorkSpaces/ScalaWS/HOS/chap2/out/mill-build/compile.dest/classes ...
[error] /.../.../WorkSpaces/ScalaWS/HOS/chap2/build.sc:8:23: not found: type Tests
[error] object test extends Tests
[error] ^

Know what is wrong, everything works as long as I leave out the testing parts

PDF downloads as HTML file containing raw postscript

I just bought your book as PDF, but unfortunately it downloads with an ".html" extension and/or mime type so it opens to a page of raw postscript code on my iPad, which is really not very useful. By downloading on a computer, and changing the extension manually, I could open the file and load it in to books. But really it would make life a lot easier if you could change this.

Thanks!

Installing Mill issue

Hello - i am @ section 2.4 "Installing Mill". I have downloaded the example-3.zip package and unzipped it.

printing the values of an array string

how scala handles printing of the contents of an array is like doing assembly language. i found two ways to do it:

val X = new ArrayString
X(0)="Hello"
X(1)=", "
X(2)="world!"

X.foreach(println) will print:
Hello
,
world!

in that order or format.

another way is:
println(X.mkString("")) will print:
Hello, world!

but why so primitive!?

can't we just say:
println(&X) OR
println($X)

and be done with it? far easier to read too.

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.