| Scalaz | |||
| Symbol | Code | Ascii | Example |
|---|---|---|---|
| η | 951 | pure | 1.η[List] |
| μ | 03BC | join | List(List(1,2,3), nil, List(5,6,7)) μ |
| ∅ | 2205 | zero | ∅[Int] |
| <∅> | empty | <∅>[Option, Int] |
|
| ∙ | 2219 | contramap | ((_:String).length ∙ (_:Int).toString ∙ ((_:Int) + 6))(5) |
| ∘ | 2218 | map | (((_:Int) + 6) ∘ (_:Int).toString ∘ (_:String).length)(5) |
| ∘∘ | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Tuples, integers and maps all have monoid | |
| // instances we can easily combine them | |
| @ val data = "Hello Hello This is some data data data yo" | |
| data: String = "Hello Hello This is some data data data yo" | |
| @ def step(word: String) = (1, word.length, Map(word -> 1)) | |
| defined function step | |
| @ def run(data: String) = data.split(" ").toList.map(step).combineAll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package examples | |
| import scalaz._, Scalaz._ | |
| object ContravariantMap { | |
| // Example of contravariant using Scalaz | |
| trait Printable[A] { | |
| def format(value: A): String | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.concurrent.TimeoutException | |
| import java.util.{Timer, TimerTask} | |
| import scala.concurrent.duration._ | |
| import scala.concurrent.{Await, ExecutionContext, Future, Promise} | |
| import scala.language.postfixOps | |
| import scala.util.{Failure, Success, Try} | |
| object FutureUtil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.List | |
| -- Graham Scan | |
| -- Direction data type | |
| data Direction = Left | |
| | Right | |
| | Straight | |
| deriving (Eq, Show) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html | |
| # Colours | |
| print "\u001b[30m A \u001b[31m B \u001b[32m C \u001b[33m D \u001b[0m\n" | |
| print "\u001b[34m E \u001b[35m F \u001b[36m G \u001b[37m H \u001b[0m\n" | |
| print "\n" | |
| # Bright colours |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| val CatsMTLVersion = "0.4.0" | |
| val CatsVersion = "1.4.0" | |
| val CatsEffectVersion = "1.0.0" | |
| libraryDependencies ++= Seq( | |
| "org.typelevel" %% "cats-core" % CatsVersion, | |
| "org.typelevel" %% "cats-effect" % CatsEffectVersion, | |
| "org.typelevel" %% "cats-mtl-core" % CatsMTLVersion, | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Functor | |
| trait JFunctor[F[_]] { | |
| def map[A,B](fa: F[A])(f: A => B) : F[B] | |
| } | |
| trait JMapFunctor[K] extends JFunctor[({type LT[V] = Map[K, V]})#LT] { | |
| def map[A, B](fa: Map[K,A])(f: A => B): Map[K,B] = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module RomanConvert exposing (..) | |
| import Dict exposing (Dict, fromList) | |
| import List.Extra exposing (find) | |
| import Set exposing (..) | |
| -- Elm implementation of converting to and from Integer and a string representation of a Roman Numeral | |
| -- (C)2018 Justin Heyes-Jones | |
| -- These are the valid characters that make up Roman Numerals |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.heyesjones.fs2redis | |
| import cats.effect.{Effect, IO} | |
| import com.redis._ | |
| import com.typesafe.scalalogging.LazyLogging | |
| import fs2.{async, _} | |
| import scala.concurrent.ExecutionContext | |
| import scala.util.{Failure, Success, Try} |