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 scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext | |
import scala.concurrent.Future | |
import akka.pattern.after | |
import akka.actor.Scheduler | |
/** | |
* Given an operation that produces a T, returns a Future containing the result of T, unless an exception is thrown, | |
* in which case the operation will be retried after _delay_ time, if there are more possible retries, which is configured through | |
* the _retries_ parameter. If the operation does not succeed and there is no retries left, the resulting Future will contain the last failure. |
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 scalaz._ | |
object Tram { | |
type Tram[A] = FreeT[Function0, Id.Id, A] | |
implicit val instance: Monad[Tram] = FreeT.freeTMonad[Function0, Id.Id] | |
def suspend[A](a: => Tram[A]): Tram[A] = | |
instance.point(a).flatMap(conforms) |
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
/* | |
* Copyright (C) 2017 Shinya Yamaoka | |
* Licensed under the MIT License.; you may not use this file except in | |
* compliance with the license. You may obtain a copy of the License at | |
* https://opensource.org/licenses/mit-license.php | |
*/ | |
object ReaderMonad { | |
class Reader[-E, +R] private (g: E => R) { | |
def apply(env: E): R = g(env) |
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
scala> def foo[T : Manifest](a : List[T]) = { | |
| val m = implicitly[Manifest[T]] | |
| val I = classOf[Int] | |
| val S = classOf[String] | |
| m.erasure match { | |
| case I => "hi" | |
| case S => "bye" | |
| case _ => "whatever" | |
| } | |
| } |
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
#!/bin/bash | |
# scrape all leaked bitcoin private keys into a tab separated text | |
# <private key>\t<bitcoin_address> | |
# | |
# support autoresume. just add these line into your cron : * * * * bash bitcoinkey.sh | |
# results stored on keys.txt | |
if [ ! -f last.page ]; then prev=`echo 0`; else prev=`cat last.page`; fi; | |
if [ -z $1 ]; then akhir=`echo 10`; else akhir=`echo $1`; fi; | |
abis=$(($prev+$akhir)) |
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.monads | |
case class User(id: Int, username: String, name: String) | |
trait UserRepository{ | |
def getById(id: Int) : Option[User] | |
def save(user: Option[User]) : Unit | |
} | |
trait UserService{ |
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
// rank 1 | |
type num[a] = (a => a) => a => a | |
def zero[a]: num[a] = f => x => x | |
def succ[a](n: num[a]): num[a] = f => x => f(n(f)(x)) | |
def eval(n: num[Int]): Int = n(_ + 1)(0) | |
// rank 2 |
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
//Warning: Uses Akka internal APIs (not binary compatible), | |
//can be written not to depend on that but implemented like this for brevity. | |
package akka.util | |
trait CallbackExecutionContext { this: akka.actor.Actor ⇒ | |
// Defines our signal for callback execution | |
case object Execute | |
// ``SerializedSuspendableExecutionContext`` is Akka-internal | |
private[this] final val ssec: SerializedSuspendableExecutionContext = { |
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
case class Inject[-E, +A](inject: E => A) { | |
// covariant functor and monad | |
def map[B](f: A => B): Inject[E, B] = | |
Inject { e => f(inject(e)) } | |
def flatMap[ε <: E, B](f: A => Inject[ε, B]): Inject[ε, B] = | |
Inject { e => f(inject(e)).inject(e) } | |
// to satisfy for-comprehension desugaring in scala < 2.10 | |
def filter(f: A => Boolean): Inject[E, A] = |
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
/** | |
* A monad to abstract dependencies in the code, see https://coderwall.com/p/kh_z5g | |
*/ | |
object Reader { | |
/** | |
* an implicit to convert a function A => B in a Reader[A, B] | |
*/ | |
implicit def reader[C, R](block: C => R): Reader[C, R] = Reader(block) |