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
(source_file | |
(protocol "Animal" requirement signature=<null> | |
(func_decl "bark()" | |
(parameter_list | |
(parameter "self")) | |
(parameter_list))) | |
(struct_decl "Dog" inherits: <null> | |
(func_decl "bark()" | |
(parameter_list | |
(parameter "self")) |
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
protocol Animal {} | |
struct Dog: Animal {} | |
func hoge(_ any: Any) { | |
print("Any") | |
} | |
func hoge(_ dogOpt: Dog?) { | |
print("Optional<Dog>") |
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
#[test] | |
fn take_works_well() { | |
let a: &[i32] = &[1,2,3]; | |
let t = a.take(2); | |
assert_eq!(t.len(), 2); | |
assert_eq!(t[0], 1); | |
assert_eq!(t[1], 2); | |
} | |
#[test] |
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
@startuml | |
Decl <|-- IfConfigDecl | |
Decl <|-- ValueDecl | |
ValueDecl <|-- TypeDecl | |
TypeDecl <|-- GenericTypeDecl | |
GenericTypeDecl <|-- TypeAliasDecl | |
GenericTypeDecl <|-- NominalTypeDecl | |
NominalTypeDecl <|-- EnumDecl | |
NominalTypeDecl <|-- StructDecl |
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
struct LReader<S1, S2, E, A> { | |
let run: (E) -> A | |
init(_ run: @escaping (E) -> A) { | |
self.run = run | |
} | |
func map<B>(_ f: @escaping (A) -> B) -> LReader<S1, S2, E, B> { | |
return LReader<S1, S2, E, B> { env in f(self.run(env)) } | |
} |
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
trait Functor[F[_]] { | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
trait Monad[F[_]] extends Functor[F] { | |
def apply[A](a: A): F[A] | |
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] | |
def map[A, B](fa: F[A])(f: A => B): F[B] = flatMap(fa)(a => apply(f(a))) | |
} |
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
let o = Observable.of(1,2,3) | |
.map { n -> Int in | |
print("map1 - \(n)") | |
return n | |
} | |
.asDriver(onErrorJustReturn: 0) | |
.map { n -> Int in | |
print("map2 - \(n)") | |
return n | |
} |
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
trait From[T, S] { | |
def from(t: T): S | |
} | |
object From { | |
def from[T, S](t: T)(implicit F: From[T, S]): S = F.from(t) | |
} | |
implicit val fromIntToString = new From[Int, String] { | |
def from(i: Int): String = i.toString |
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
sealed trait Union[A, B] | |
case class Left[A, B](a: A) extends Union[A, B] | |
case class Right[A, B](b: B) extends Union[A, B] | |
type |[A, B] = Union[A, B] | |
implicit def liftLeft[A, B](a: A) = Left[A, B](a) | |
implicit def liftRight[A, B](b: B) = Right[A, B](b) | |
var intString: Int | String = 1 |
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
trait InsertIfNotExists[T <: AbstractTable[_]] { | |
val driver: JdbcProfile | |
import driver.api._ | |
val tableQuery: TableQuery[T] | |
def exists(e: T#TableElementType): Rep[Boolean] | |
def insertIfNotExists(e: T#TableElementType)(implicit executionContext: ExecutionContext): DBIO[Unit] = for { |