A Monad is something that supports flatMap.
Examples: Option
, List
, Future
flatMap
is the same as >>=
in Haskell.
package auth | |
import ( | |
"encoding/json" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"net" | |
"net/http" | |
"net/url" |
A Monad is something that supports flatMap.
Examples: Option
, List
, Future
flatMap
is the same as >>=
in Haskell.
For testing purposes, the easiest way to go is jitpack:
resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.User" % "Repo" % "Tag"
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
It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.
Using JSON in Postgres by example.
docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
import scala.io.StdIn | |
import scala.util._ | |
import akka.actor._ | |
import akka.stream._ | |
import akka.stream.scaladsl._ | |
import akka.stream.stage._ | |
import akka.util._ | |
object ComplexTcpClient extends App { |
// this works in play 2.4 with the 1.9.29 version of async http client | |
def securePostMultipart(requestPath: String, etsyToken: RequestToken, | |
fileName: String, file: File, fileMimeType: String, | |
stringParts: (String, String)*): Future[WSResponse] = { | |
val fullUrl = "http://foo/bar/zar" | |
val parts : List[Part] = List( | |
new FilePart(fileName, file, fileMimeType), |
A primer/refresher on the category theory concepts that most commonly crop up in conversations about Scala or FP. (Because it's embarassing when I forget this stuff!)
I'll be assuming Scalaz imports in code samples, and some of the code may be pseudo-Scala.
A functor is something that supports map
.
/** | |
* Pretty prints a Scala value similar to its source represention. | |
* Particularly useful for case classes. | |
* @param a - The value to pretty print. | |
* @param indentSize - Number of spaces for each indent. | |
* @param maxElementWidth - Largest element size before wrapping. | |
* @param depth - Initial depth to pretty print indents. | |
* @return | |
*/ | |
private def prettyPrint(a: Any, indentSize: Int = 2, maxElementWidth: Int = 30, depth: Int = 0): String = { |