Skip to content

Instantly share code, notes, and snippets.

View alexamorales's full-sized avatar

Aleksey Lisun alexamorales

View GitHub Profile
@alexamorales
alexamorales / duplicatesBy.scala
Created September 5, 2019 13:52
distinctBy and duplicatesBy
def distinctBy[A, B](f: A => B)(list: List[A]): Iterable[A] =
list.zip(list.map(f))
.groupBy { case (_, k) => k }
.values
.filter(_.size == 1)
.map(_.headOption)
.collect { case Some((e, _)) => e }
def duplicatesBy[A, B](f: A => B)(list: List[A]): List[A] =
list.diff(distinctBy(f)(list).toList).distinct
@alexamorales
alexamorales / BCDDate.scala
Created August 30, 2019 07:41
Binary-coded decimal
object BCDDate {
/**
* Method creates local date from BCD (https://en.wikipedia.org/wiki/Binary-coded_decimal) encoded hex string
*
* @param bcdDate HEX representation of BCD date
* @return local date instance
*/
def apply(bcdDate: HexString): Try[LocalDate] =
Try {