On Mac, Homebrew is the de-facto package manager, and Homebrew Cask is the app manager. I’m going to use Cask to install Java 7 and 8.
Install Homebrew Cask first if you haven’t:
brew update
brew tap caskroom/cask
| import scala.language.higherKinds | |
| object Lenses { | |
| trait Profunctor[P[_, _]] { | |
| def dimap[A, B, C, D](f: C => A, g: B => D)(p: P[A, B]): P[C, D] | |
| } | |
| object Profunctor { |
| -- A sequential series of parallel program fragments in `f`: | |
| type SeqPar f a = Free (FreeAp f) a | |
| liftFA :: forall f a. f a -> SeqPar f a | |
| liftFA = pure >>> pure | |
| liftSeq :: forall f a. Free f a -> SeqPar f a | |
| liftSeq fa = foldFree fa liftFA | |
| liftPar :: forall f a. FreeAp f a -> SeqPar f a |
This is my attempt to give Scala newcomers a quick-and-easy rundown to the prerequisite steps they need to a) try Scala, and b) get a standard project up and running on their machine. I'm not going to talk about the language at all; there are plenty of better resources a google search away. This is just focused on the prerequisite tooling and machine setup. I will not be assuming you have any background in JVM languages. So if you're coming from Python, Ruby, JavaScript, Haskell, or anywhere… I hope to present the information you need without assuming anything.
Disclaimer It has been over a decade since I was new to Scala, and when I was new to Scala, I was coming from a Java and Ruby background. This has probably caused me to unknowingly make some assumptions. Please feel free to call me out in comments/tweets!
One assumption I'm knowingly making is that you're on a Unix-like platform. Sorry, Windows users.
Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.
A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.
val square : Int => Int = x => x * x| case class IO[A](unsafePerformIO: () => A) { | |
| def map[B](ab: A => B): IO[B] = IO(() => ab(unsafePerformIO())) | |
| def flatMap[B](afb: A => IO[B]): IO[B] =IO(() => afb(unsafePerformIO()).unsafePerformIO()) | |
| def tryIO(ta: Throwable => A): IO[A] = | |
| IO(() => IO.tryIO(unsafePerformIO()).unsafePerformIO() match { | |
| case Left(t) => ta(t) | |
| case Right(a) => a | |
| }) | |
| } | |
| object IO { |
| package com.softwaremill.freemonads | |
| import cats.free.Free | |
| import cats.~> | |
| import cats._, cats.std.all._ | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| import scala.concurrent.Future | |
| sealed trait External[A] | |
| case class Tickets(count: Int) extends AnyVal |
| // | |
| // Validation[E, A] represents either: | |
| // - Success[A] | |
| // - Failure[E] | |
| // | |
| // Isomporphic to scala.Either[E, A] and scalaz.\/[E, A] | |
| // | |
| // Unlike \/[E, A], Validation is not a Monad, but an Applicative | |
| // Functor. So if you want to use it as a Monad you can convert back | |
| // and forth using the `validation` and `disjunction` method |