Let
A,B,Cbe typesunit: A -> Monad<A>a constructorf: A -> Monad<B>,g: B -> Monad<C>functionsabe an object of typeAmbe an object of typeMonad<a>
| >> IF = -> b { b } | |
| => #<Proc:0x007fb4e4049cc8 (lambda)> | |
| >> LEFT = -> p { p[-> x { -> y { x } } ] } | |
| => #<Proc:0x007fb4e403d680 (lambda)> | |
| >> RIGHT = -> p { p[-> x { -> y { y } } ] } | |
| => #<Proc:0x007fb4e4028ff0 (lambda)> | |
| >> IS_EMPTY = LEFT |
| scala> case class Bad(a: Int) { override def equals(a:Any) = true } | |
| scala> val f = (n:Int) => Bad(n) | |
| scala> val g = (b:Bad) => b.a | |
| ... | |
| scala> Set(1,2,3).map(f andThen g) | |
| res2: scala.collection.immutable.Set[Int] = Set(1, 2, 3) | |
| scala> Set(1,2,3).map(f).map(g) |
The list is now hosted on a repository so you can PR -> https://github.com/jeroenvdgulik/awesome-talks/blob/master/README.md
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| module MonoidalFizzBuzz where | |
| import Data.Monoid | |
| import Data.Maybe | |
| -- based on @mittie https://twitter.com/mittie/status/798257339736453120 | |
| monoidalFizzbuzz = zipWith fromMaybe numbers strings | |
| where | |
| fizzes = cycle [Nothing, Nothing, Just "Fizz"] | |
| buzzes = cycle [Nothing, Nothing, Nothing, Nothing, Just "Buzz"] |
This document aims to show and compare three alternatives for achieving polymorphism in Scala.
Additionally, when implementing the typeclass pattern in Scala,
| -- X filter | |
| -- -- maybe some tests with List.all and List.any | |
| -- | |
| -- intersperse | |
| -- X head | |
| -- X isEmpty | |
| -- X tail | |
| -- X init | |
| -- X last |