Skip to content

Instantly share code, notes, and snippets.

Amir Karimi amirkarimi

Block or report user

Report or block amirkarimi

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 blog_practical_cats_06.scala
def getCountryByUserId(id: Int): Future[Either[String, Country]] = {
val result = for {
user <- EitherT(getUser(id))
city <- EitherT(getCity(user))
country <- EitherT(getCountry(city))
} yield {
country
}
result.value
}
View blog_practical_cats_05.scala
def getUser(id: Int): Future[Either[String, User]] = ???
def getCity(user: User): Future[Either[String, City]] = ???
def getCountry(city: City): Future[Either[String, Country]] = ???
def getCountryByUserId(id: Int): Future[Either[String, Country]] = {
getUser(id) flatMap {
case Left(err) => Future.successful(Left(err))
case Right(user) =>
getCity(user) flatMap {
case Left(err) => Future.successful(Left(err))
View blog_practical_cats_04.scala
def getCountryByUserId(id: Int): Future[Option[Country]] = {
val result = for {
user <- OptionT(getUser(id))
city <- OptionT(getCity(user))
country <- OptionT(getCountry(city))
} yield {
country
}
result.value
}
View blog_practical_cats_03.scala
def getUser(id: Int): Future[Option[User]] = ???
def getCity(user: User): Future[Option[City]] = ???
def getCountry(city: City): Future[Option[Country]] = ???
def getCountryByUserId(id: Int): Future[Option[Country]] = {
getUser(id) flatMap {
case None => Future.successful(None)
case Some(user) =>
getCity(user) flatMap {
case None => Future.successful(None)
View blog_practical_cats_02.scala
def getUser(id: Int): Future[Option[User]] = ???
getUser(10).map {
case None => println(“User not found”)
case Some(user) => println(s”User: $user”)
}
@amirkarimi
amirkarimi / blog_practical_cats_01.scala
Last active Jan 3, 2018
Don’t listen to them, learn Cats this way
View blog_practical_cats_01.scala
def getUser(id: Int): Option[User] = ???
getUser(10) match {
case None => println(“User not found”)
case Some(user) => println(s”User: $user”)
}
@amirkarimi
amirkarimi / sort-import-group.el
Last active Aug 7, 2017
My Emacs Lisp Scripts
View sort-import-group.el
(defun sort-import-group ()
"This function basically sorts a comma separated list of strings but it's been
written to sort grouped imports in Scala.
Example:
`import org.temp.{ B, C, A }`
By selecting the grouped imported items (`B, C, A`) from the above code sample and run (M-x) `sort-group`
you'll get the following result:
`import org.temp.{ A, B, C }`"
(interactive)
(let* ((bounds (cons (region-beginning) (region-end)))
View linux_init.el
;; global variables
(setq
inhibit-startup-screen t
create-lockfiles nil
make-backup-files nil
column-number-mode t
scroll-error-top-bottom t
show-paren-delay 0.5
use-package-always-ensure t
sentence-end-double-space nil
@amirkarimi
amirkarimi / 01.scala
Last active May 17, 2017
01-apply-settings-using-sbt-triggered-plugin
View 01.scala
lazy val commonSettings = Seq(
organization := "com.example",
version := "0.1.0-SNAPSHOT"
)
lazy val core = (project in file("core"))
.settings(
commonSettings,
// other settings
)
@amirkarimi
amirkarimi / dist-play-app-initd
Last active Aug 29, 2015 — forked from RadoBuransky/dist-play-app-initd
Init.d shell script for Play framework distributed application. Provides start, stop, restart and status commands to control applications packaged using standard "play dist" packaging command.
View dist-play-app-initd
#!/bin/bash
#
# =========================================================================
# Copyright 2014 Rado Buransky, Dominion Marine Media
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
You can’t perform that action at this time.