{"id":18828603,"url":"https://github.com/bizzabo/typeless","last_synced_at":"2025-04-14T03:15:16.848Z","repository":{"id":57714890,"uuid":"82202092","full_name":"bizzabo/typeless","owner":"bizzabo","description":"running wild with shapeless","archived":false,"fork":false,"pushed_at":"2018-12-18T15:42:55.000Z","size":100,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":45,"default_branch":"master","last_synced_at":"2025-04-14T03:15:08.504Z","etag":null,"topics":["backend","rnd","xdotai"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bizzabo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-16T16:36:25.000Z","updated_at":"2024-12-09T19:53:15.000Z","dependencies_parsed_at":"2022-09-02T22:00:11.480Z","dependency_job_id":null,"html_url":"https://github.com/bizzabo/typeless","commit_stats":null,"previous_names":["xdotai/typeless","xdotai/x-shapeless"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bizzabo%2Ftypeless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bizzabo%2Ftypeless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bizzabo%2Ftypeless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bizzabo%2Ftypeless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bizzabo","download_url":"https://codeload.github.com/bizzabo/typeless/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813803,"owners_count":21165634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","rnd","xdotai"],"created_at":"2024-11-08T01:33:37.872Z","updated_at":"2025-04-14T03:15:16.815Z","avatar_url":"https://github.com/bizzabo.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typeless\n\nSome typeclasses inspired and powered by shapeless\n\n#### `Find[L \u003c: HList, A]`\n\nWill allow to find a type `A` in an `HList` `L`, if the type is not present it returns `None`, otherwise `Some[A]`\n\n#### `Subset[L \u003c: HList,S \u003c: HList]`\n\nSimilar to `Find`, but for a group of elements, if **all** the elements of the  `S` are present in `L` it returns `Some[S]` otherwise `None`\n\n#### `ListToHList[L, H \u003c HList]`\n\nConverts a `List[L]` to an `Option[HList]`. The `ListToHList` implicit class exposes two features. \n\n`.toProduct[A]`: convert `List[L]` to an `Option[A]`.\n\n`.findByType[B]`: find type `B` within `List[L]`\n\n```scala\n\n  import ListToHList.Ops\n\n  sealed trait A\n  case class B() extends A\n  case class C() extends A\n\n  case class D(b: B, c: C)\n  \n  val listA: List[A] = List(B(), C())\n  \n  listA.toProduct[D] === Some(D(B(), C()))\n  \n  listA.findByType[B] === Some(B())\n```\n\n#### `Convert[L \u003c: Coproduct, S \u003c: Coproduct]`\n\nFor Coproducts `L` and `S`, `Convert` takes a value of type `L` and converts it to type `S`.\n\n#### example\n\n```scala\n  type A = String :+: Double :+: CNil\n  type B = Double :+: String :+: List[Int] :+: CNil\n\n  Coproduct[A](\"test\").convert[B] === Some(Coproduct[B](\"test\"))\n\n```\n\n#### `CoproductToHList[C \u003c: Coproduct, L \u003c: HList]`\n\nFor a `Seq` of Coproducts `C`, convert to `HList` of type `L`\n\n#### example \n\n```scala\n    type A = Int :+: String :+: CNil\n    type L = String :: Int :: HNil\n\n    Seq(Coproduct[A](1), Coproduct[A](\"a\")).toHList[L] === Some(\"a\" :: 1 :: HNil))\n    \n    case class Foo(i:Int, s:String)\n    \n    Seq(Coproduct[A](1), Coproduct[A](\"a\")).toHList[Foo] === Some(Food(\"a\", 1))\n\n```\n\n#### `SelectFunctions[L \u003c: HList, FF \u003c: HList]`\n\nTakes an `HList` of functions `FF` and an `HList` of potential arguments `Context`. It applies the arguments to the functions for which all the arguments are present. It returns an `HList` with the results. It will *not compile* if there is a function that cannot be applied.\n\n#### example\n\n```scala\nval functions =\n    { (x: String, i: Int, d: Double) =\u003e d.toInt * i } ::\n      { (x: String, i: Int) =\u003e s\"$x + $i\" } ::\n      { (x: String, s: Char, i: Int) =\u003e i.toDouble } :: \n      { (x: String, s: Char, i: Int) =\u003e s.toInt + i * 2 + x.size } ::\n      { (x: String) =\u003e x.size } ::\n      { (x: Char) =\u003e x.toInt } ::\n      HNil\n\nSelectFunctions.applyAll(1, hi)(functions) // won't compile\nSelectFunctions.applyAll(hi, 'a', 1)(functions) == \"hi + 1\" :: 1.0 :: 101 :: 2 :: 97 :: HNil\n```\n\n#### `FlattenFunctions[Context \u003c: HList, FFF \u003c: HList]` \n\nTakes an `HList` of `HLists` of functions and an `HList` of potential arguments, and uses `SelectFunctions[Context, FF]` to calculate the resulting `HList`.\n\n#### example\n\n```scala\n val functions1 =\n      { (x: String, i: Int) =\u003e (x.size + i) } ::\n        { (x: String, s: Char, i: Int) =\u003e (s.toInt + i * 2 + x.size) } ::\n        HNil\nval functions2 =\n      { (x: String, s: Char, i: Int) =\u003e (s.toInt + i + x.size) } ::\n        { (i: Int) =\u003e i.toDouble } ::\n        HNil\n\nval functions = functions1 ::\n      functions2 ::\n      HNil\n\nFlattenFunctions.applyAll(1, \"a\", 'a')(functions) === 2 :: 1.0 :: 99 :: HNil\n```\n\n#### `EqualsIgnoringFields[T]`\n\nIt compares two cases classes excluding specific *field names* rather than types.\n\n#### example:\n```scala\n\nimport typeless.hlist.EqualsIgnoringFields.Ops\n\nsealed trait Monarch\n\ncase class Butterflies(\n  _id: Long,\n  date: Long,\n  count: Int\n) extends Monarch\n\ncase class Dictator(\n  _id: Long,\n  date: Long,\n  count: Int\n) extends Monarch\n\nval butterfliesStation1 = Butterflies(\n      _id = 1,\n      date = 1131,\n      count = 3\n    )\nval butterfliesStation2 = Butterflies(\n      _id = 2,\n      date = 1131,\n      count = 2\n    )\n\n// the two objects are the same if we ignore those two fields\nassert(butterfliesStation1.equalsIgnoringFields(field =\u003e field == '_id || field == 'count)(butterfliesStation2)) \n// the two objects are different if not ignoring `count`\nassert(!butterfliesStation1.equalsIgnoringFields(_ == '_id)(butterfliesStation2))\n// the two objects are different, period\nassert(butterfliesStation1 != butterfliesStation2) \n\n```\n\n## Getting started\n\n### Scala 2.11/2.12\n```scala\nlibraryDependencies += \"ai.x\" %% \"typeless\" % \"0.6.0\"\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbizzabo%2Ftypeless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbizzabo%2Ftypeless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbizzabo%2Ftypeless/lists"}