This file contains 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
class Availability extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
calendar: null | |
}; | |
} | |
componentDidMount() { | |
setTimeout(() => { | |
this.setState({ |
This file contains 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
const Kitten = (props) => { | |
return ( | |
<h1>Cats</h1> // put jsx in here | |
) | |
} | |
// or | |
class Kitten extends React.Component { | |
constructor(props) { | |
super(props); | |
} |
This file contains 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
object Main extends App { | |
import cats._ | |
import cats.implicits._ | |
val ans: Eval[Int] = for { | |
a <- Eval.now { println("a"); 40 } | |
b <- Eval.always { println( "b" ); 2 } | |
c <- Eval.later { println( "c" ); 2 } | |
} yield { |
This file contains 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
object Main extends App { | |
import cats._ | |
import cats.implicits._ | |
private val now: Eval[Double] = Eval.now(math.random) | |
println(now.value) | |
println(now.value) | |
private val later: Eval[Double] = Eval.later(math.random) |
This file contains 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
object Main extends App { | |
import cats._ | |
import cats.implicits._ | |
println(123.show) | |
println("xyc".show) | |
println(true.show) | |
// using show on custom objects |
This file contains 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
/* | |
3 Monad laws | |
1. Right identity: pure(a).flatMap(func) == func(a) | |
2. m.flatMap(pure) = m | |
3. m.flatMap(f).flatMap(g) = m.flatMap(x => f(x).flatMap(g)) | |
*/ | |
trait MyMonad[F[_]] { |
This file contains 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
// has a contramap method | |
trait MyContravariantFunctor[F[_]] { | |
def contramap[A, B](fa: F[A], f: B => A): F[B] | |
} | |
// We can use contramap to build a show for Salary from the show for Money | |
import cats._ | |
import cats.implicits._ |
This file contains 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
object Main extends App { | |
import cats._ | |
import cats.implicits._ | |
def power[F[_]](f: F[Int])(implicit func: Functor[F]): F[Int] = { | |
f.map(x => x*x) | |
} |
This file contains 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 Laws: | |
1. Identity | |
fa.map(a => a) == fa | |
2. Composition | |
fa.map(f).map(g) = fa.map(g(f(_))) | |
*/ | |
trait MyFunctor[F[_]] { | |
def map[A, B](fa: F[A], f: A => B): F[B] | |
} |
This file contains 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
// eg union of non empty sets | |
trait MySemigroup[A] { | |
// must be associative | |
def combine(a1: A, a2: A): A | |
} | |
// eg union of sets, where the empty set is the identity element | |
trait MyMonoid[A] extends MySemigroup[A] { | |
// is an identity element | |
def empty: A |
NewerOlder