Skip to content

Instantly share code, notes, and snippets.

softberries

Block or report user

Report or block softberries

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View play-fp-7.scala
@Singleton
class PersonRepository @Inject()(dbConfigProvider: DatabaseConfigProvider)
(implicit ec: ExecutionContext) {
implicit val cs = IO.contextShift(ec)
.....
View play-fp-6.scala
def list(): IO[Seq[Person]] = IO.fromFuture {
IO {
db.run {
people.result
}
}
View play-fp-5.scala
val ioa2 = IO.fromFuture(IO {
Future { println("hey fut 2!") }
})
val program2 =
for {
_ <- ioa2
_ <- ioa2
} yield ()
program2.unsafeRunSync()
View play-fp-4.scala
val fut = Future { println("hey fut!") }
val ioa = IO.fromFuture(IO {
fut
})
val program =
for {
_ <- ioa
_ <- ioa
} yield ()
program.unsafeRunSync()
View play-fp-3.scala
val ioa = IO { println("hey!") }
val program: IO[Unit] =
for {
_ <- ioa
_ <- ioa
} yield ()
program.unsafeRunSync()
View play-fp-2.scala
val fut = Future { println("hey!") }
val program: Future[Unit] =
for {
_ <- fut
_ <- fut
} yield ()
program.onComplete {
case Success(value) => value
View play-fp-1.scala
def create(name: String, age: Int): Future[Person] = db.run {
// We create a projection of just the name and age columns, since we're not inserting a value for the id column
(people.map(p => (p.name, p.age))
// Now define it to return the id, because we want to know what id was generated for the person
returning people.map(_.id)
// And we define a transformation for the returned value, which combines our original parameters with the
// returned id
into ((nameAge, id) => Person(id, nameAge._1, nameAge._2))
// And finally, insert the person into the database
) += (name, age)
View functor8.scala
import cats.instances.list._
import cats.instances.option._
val complexContainer = List(
List(
Some(Map(1 -> false, 2 -> true)),
None
),
List(
View functor7.scala
val complexProduct = List(
List(
Some(10),
None
),
List(
Some(22)
)
)
View functor6.scala
val nested: Nested[List, Option, Int] = Nested(lst)
val doubleNested = nested.map(_ * 2)
println(doubleNested.value)//List(Some(2), None, Some(4))
You can’t perform that action at this time.