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
function Idea { | |
param ( | |
$PROJECT | |
) | |
$IDEA_PATH="YOURPATHTOIDEA\bin\idea64.exe" | |
Invoke-Expression "& '$IDEA_PATH' $PROJECT" | |
} | |
function CloneIdea { | |
param ( |
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 arrow.core.None | |
import arrow.core.Option | |
import arrow.core.some | |
import arrow.fx.IO | |
fun insertOrUpdate(fruit: FruitMetadata): IO<Int> = | |
findByAuthorityId(fruit.fruitAuthorityId) | |
.flatMapNone { findByCouncilId(fruit.fruitCouncilId) } | |
.flatMapNone { findByName(fruit.name) } | |
.flatMap { it.fold({ insert(fruit) }, { id -> update(id, fruit) }) } |
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 arrow.core.None | |
import arrow.core.Option | |
import arrow.core.Some | |
fun insertOrUpdate(fruit: FruitMetadata): Int = | |
findByAuthorityId(fruit.fruitAuthorityId) | |
.fold({ findByCouncilId(fruit.fruitCouncilId) }, ::Some) | |
.fold({ findByName(fruit.name) }, ::Some) | |
.fold({ insert(fruit) }, { update(it, fruit) }) |
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
namespace Sandbox.InserOrUpdate | |
{ | |
public class FruitRepository | |
{ | |
public int InsertOrUpdate(FruitMetadata fruit) | |
{ | |
var id = FindByAuthorityId(fruit.FruitAuthorityId) ?? FindByCouncilId(fruit.FruitCouncilId) ?? FindByName(fruit.Name); | |
return id.HasValue ? Update(id.Value, fruit) : Insert(fruit); | |
} |