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
public static void main(String[] args) { | |
class Player { | |
Integer id; | |
String team; | |
public Player(Integer id, String team) { | |
this.id = id; | |
this.team = team; | |
} |
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
def loggedRequest(magnet: LoggingMagnet[String ⇒ Unit]): Directive0 = extractRequestContext.flatMap { ctx ⇒ | |
val timer = Timer.start | |
mapRouteResult { | |
case result: Complete => | |
//extracting request and complete route result here | |
result | |
case result: Rejected => | |
//extracting request and rejected route result here | |
result |
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 me.lavando.user.api.features | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.{Await, Future} | |
import scala.util.Failure | |
/** | |
* @author Gabriel Francisco <[email protected]> | |
*/ |
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
Stream<Integer> xs = Stream.of(5, 3, 7, 3, 2, 7); | |
final List<Integer> range = IntStream.range(0, 100).boxed().collect(toList()); | |
final List<List<Integer>> result = | |
range | |
.parallelStream() | |
.map(e -> xs.sorted().collect(toList())) | |
.collect(toList()); |
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
private object Validations { | |
trait NotEmpty[F[_], T] { | |
def validate(field: F[T]): Boolean | |
} | |
implicit def optionNotEmpty[T]: NotEmpty[Option, T] = field => field.isDefined | |
implicit def listNotEmpty[T]: NotEmpty[List, T] = field => field.nonEmpty | |
def notEmpty[F[_], T](field: F[T])(implicit ev: NotEmpty[F, T]): Boolean = ev.validate(field) | |
} |
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
private object Validations { | |
trait Validator[F[_], T] { | |
def validate(field: F[T]): Boolean | |
} | |
trait NotEmpty[F[_], T] extends Validator[F, T] | |
trait NotBlank[F[_], T] extends Validator[F, T] | |
trait Contains[F[_], T] extends Validator[F, T] |
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 org.validation.java; | |
import java.util.Collection; | |
import java.util.Collections; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
/** | |
* @author Gabriel Francisco <[email protected]> |
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
interface DatabaseAccess { | |
void save(Object entity); | |
} | |
class MySQL implements DatabaseAccess{ | |
@Override | |
void save(Object entity) { | |
//saving obj into MySQL | |
} | |
} |
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
abstract class Person | |
case class Worker(id: Long, name: String, company: String) extends Person | |
case class Student(id: Long, name: String, university: String) extends Person | |
object App { | |
def handle(p: Person) = { | |
p match { | |
case Worker(id, name, company) => println(s"this is a worker from $company") | |
case Student(id, name, university) => println(s"this is a student from $university") |
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 org.springframework.data.repository.PagingAndSortingRepository; | |
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | |
import javax.persistence.Entity; | |
import javax.persistence.Table; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.boot.SpringApplication; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.Id; | |
@Entity |