Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ReplaceFirstInTuple with shapeless
import shapeless._
import shapeless.ops.tuple._
trait ReplaceFirstInTuple[Head, Replacement, Tup, TupReplaced] {
def replace(ik: Tup, j: Replacement): TupReplaced
def first(ik: Tup): Head
}
object ReplaceFirstInTuple {
implicit def instance[Tup, Replacement, Head, TupReplaced](
implicit replacer: ReplaceAt.Aux[Tup, Nat._0, Replacement, (Head, TupReplaced)],
atHead: At.Aux[Tup, Nat._0, Head]
): ReplaceFirstInTuple[Head, Replacement, Tup, TupReplaced] = new ReplaceFirstInTuple[Head, Replacement, Tup, TupReplaced] {
def replace(ik: Tup, j: Replacement): TupReplaced = replacer(ik, j)._2
def first(ik: Tup): Head = atHead(ik)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment