Skip to content

Instantly share code, notes, and snippets.

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))
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
}
@amirkarimi
amirkarimi / my_useful_regexes.md
Last active June 17, 2020 16:24
My Useful Regular Expressions

My Useful Regular Expressions

The first lines are the regex to find and the last line are the replace expressions.

YAML

Convert single quoted values to double in YAML

:(\s?)'(.*)'
@amirkarimi
amirkarimi / karabiner-elements-linux-rules.json
Last active December 10, 2022 04:50
Karabiner Elements Linux shortcuts for Mac
[
{
"description": "Control+Click to Command+Click",
"manipulators": [
{
"from": {
"modifiers": {
"mandatory": [
"control"
],