[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BZ5MVC6EYSA789RTXQKMS2":3,"skill-same:01M7BZ5MVC6EYSA789RTXQKMS2":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M7BZ5MVC6EYSA789RTXQKMS2","python-scala-functional",null,"Guide for translating Python code to functional Scala style. Use when converting Python code involving higher-order functions, decorators, closures, generators, or when aiming for idiomatic functional Scala with pattern matching, Option handling, and monadic operations.","linyouxue\u002Fskill-repair-benchmark","linyouxue","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F216151464?v=4","01M7BJEVCXKD74KH6FG9CBVSQB","林宥学","01M7BJEVE02NP217V93BKZFC0J",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fevaluation\u002Fresults\u002FSkillAxe\u002Ftasks\u002Fpython-scala-translation\u002Frepaired_skill\u002Fpython-scala-functional\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: python-scala-functional\ndescription: Guide for translating Python code to functional Scala style. Use when converting Python code involving higher-order functions, decorators, closures, generators, or when aiming for idiomatic functional Scala with pattern matching, Option handling, and monadic operations.\n---\n\n# Python to Scala Functional Programming Translation\n\n## Higher-Order Functions\n\n```python\n# Python\ndef apply_twice(f, x):\n    return f(f(x))\n\ndef make_multiplier(n):\n    return lambda x: x * n\n\ndouble = make_multiplier(2)\nresult = apply_twice(double, 5)  # 20\n```\n\n```scala\n\u002F\u002F Scala\ndef applyTwice[A](f: A => A, x: A): A = f(f(x))\n\ndef makeMultiplier(n: Int): Int => Int = x => x * n\n\nval double = makeMultiplier(2)\nval result = applyTwice(double, 5)  \u002F\u002F 20\n```\n\n## Decorators → Function Composition\n\n```python\n# Python\ndef log_calls(func):\n    def wrapper(*args, **kwargs):\n        print(f\"Calling {func.__name__}\")\n        result = func(*args, **kwargs)\n        print(f\"Finished {func.__name__}\")\n        return result\n    return wrapper\n\n@log_calls\ndef add(a, b):\n    return a + b\n```\n\n```scala\n\u002F\u002F Scala - function composition\ndef logCalls[A, B](f: A => B, name: String): A => B = { a =>\n  println(s\"Calling $name\")\n  val result = f(a)\n  println(s\"Finished $name\")\n  result\n}\n\nval add = (a: Int, b: Int) => a + b\nval loggedAdd = logCalls(add.tupled, \"add\")\n\n\u002F\u002F Alternative: using by-name parameters\ndef withLogging[A](name: String)(block: => A): A = {\n  println(s\"Calling $name\")\n  val result = block\n  println(s\"Finished $name\")\n  result\n}\n```\n\n## Pattern Matching\n\n```python\n# Python (3.10+)\ndef describe(value):\n    match value:\n        case 0:\n            return \"zero\"\n        case int(x) if x > 0:\n            return \"positive int\"\n        case int(x):\n            return \"negative int\"\n        case [x, y]:\n            return f\"pair: {x}, {y}\"\n        case {\"name\": name, \"age\": age}:\n            return f\"{name} is {age}\"\n        case _:\n            return \"unknown\"\n```\n\n```scala\n\u002F\u002F Scala - pattern matching is more powerful\ndef describe(value: Any): String = value match {\n  case 0 => \"zero\"\n  case x: Int if x > 0 => \"positive int\"\n  case _: Int => \"negative int\"\n  case (x, y) => s\"pair: $x, $y\"\n  case List(x, y) => s\"list of two: $x, $y\"\n  case m: Map[_, _] if m.contains(\"name\") =>\n    s\"${m(\"name\")} is ${m(\"age\")}\"  \u002F\u002F beware: Map.apply throws if missing\n  case _ => \"unknown\"\n}\n\n\u002F\u002F Case class pattern matching (preferred)\nsealed trait Result\ncase class Success(value: Int) extends Result\ncase class Error(message: String) extends Result\n\ndef handle(result: Result): String = result match {\n  case Success(v) if v > 100 => s\"Big success: $v\"\n  case Success(v) => s\"Success: $v\"\n  case Error(msg) => s\"Failed: $msg\"\n}\n```\n\n## Option Handling (None\u002Fnull Safety)\n\n```python\n# Python\ndef find_user(user_id: int) -> Optional[User]:\n    user = db.get(user_id)\n    return user if user else None\n```\n\n```scala\n\u002F\u002F Scala - Option\ndef findUser(userId: Int): Option[User] = db.get(userId)\n```\n\n### Translating Python runtime dispatch (duck typing + None)\n\nPython often accepts many runtime types in one function (e.g., `def tokenize(value: Any)`) and explicitly handles `None`.\nIn Scala, you can keep behavior **without** making the whole codebase `Any`-typed:\n\n- Provide **typed entry points** where possible (overloads or distinct methods).\n- Provide **one runtime-dispatch entry point** only where the Python truly does so.\n- If the Python accepts `None`, the Scala runtime entry point should either:\n  - accept `Any` and treat `null` as “missing”, or\n  - accept `Option[Any]` and handle `None`.\n\nPrefer a small “boundary” method with `Any`\u002F`null` handling, and keep internal logic typed.\n\n## Generators → Iterators\u002FLazyList\n\n```python\n# Python\ndef fibonacci():\n    a, b = 0, 1\n    while True:\n        yield a\n        a, b = b, a + b\n```\n\n```scala\n\u002F\u002F Scala - LazyList (was Stream in Scala 2.12)\ndef fibonacci: LazyList[BigInt] = {\n  def loop(a: BigInt, b: BigInt): LazyList[BigInt] =\n    a #:: loop(b, a + b)\n  loop(0, 1)\n}\n```\n\n## Try\u002FEither for Error Handling\n\n```python\n# Python - exceptions\ndef parse_int(s: str) -> int:\n    try:\n        return int(s)\n    except ValueError:\n        return 0\n```\n\n```scala\n\u002F\u002F Scala - Try monad\nimport scala.util.{Try, Success, Failure}\n\ndef parseInt(s: String): Try[Int] = Try(s.toInt)\n```\n\n## Function Composition\n\n```python\n# Python\ndef compose(f, g):\n    return lambda x: f(g(x))\n```\n\n```scala\nval addOne: Int => Int = _ + 1\nval double: Int => Int = _ * 2\n\nval composed = addOne.compose(double)  \u002F\u002F addOne(double(x))\nval pipeline = addOne.andThen(double).andThen(addOne)\n```\n\n## Currying and Partial Application\n\n```python\n# Python\nfrom functools import partial\n\ndef add(a, b, c):\n    return a + b + c\n```\n\n```scala\n\u002F\u002F Scala - curried functions\ndef add(a: Int)(b: Int)(c: Int): Int = a + b + c\n```\n\n## Tail Recursion\n\n```python\n# Python - no tail call optimization\ndef factorial(n):\n    if n \u003C= 1:\n        return 1\n    return n * factorial(n - 1)\n```\n\n```scala\n\u002F\u002F Scala - tail recursion with annotation\nimport scala.annotation.tailrec\n\ndef factorial(n: Int): BigInt = {\n  @tailrec\n  def loop(n: Int, acc: BigInt): BigInt = {\n    if (n \u003C= 1) acc\n    else loop(n - 1, n * acc)\n  }\n  loop(n, 1)\n}\n```\n\n### `@tailrec` safety rule (Scala 2.13)\n\nOnly annotate with `@tailrec` when the recursive call is syntactically in **tail position**.\nA common non-tail pattern is mixing recursion with `Option.map\u002FflatMap` or other higher-order calls:\n\n```scala\n\u002F\u002F NOT tail-recursive (recursive call occurs inside flatMap)\n\u002F\u002F @tailrec  \u002F\u002F would fail compilation\nfinal def loop(parts: List[String], cur: Node): Option[Node] = parts match {\n  case Nil => Some(cur)\n  case p :: ps => cur.child(p).flatMap(loop(ps, _))\n}\n```\n\nFix by either:\n- removing `@tailrec`, or\n- rewriting to an explicit loop\u002Ffold that is actually tail-recursive.\n\n## Implicit Conversions and Type Classes\n\n```scala\n\u002F\u002F Scala 2 - type classes via implicits\ntrait Show[A] { def show(a: A): String }\n\nimplicit val intShow: Show[Int] = new Show[Int] {\n  def show(a: Int): String = s\"Int: $a\"\n}\n\ndef display[A](a: A)(implicit s: Show[A]): String = s.show(a)\n```\n","# Python to Scala Functional Programming Translation\n\n## Higher-Order Functions\n\n```python\n# Python\ndef apply_twice(f, x):\n    return f(f(x))\n\ndef make_multiplier(n):\n    return lambda x: x * n\n\ndouble = make_multiplier(2)\nresult = apply_twice(double, 5)  # 20\n```\n\n```scala\n\u002F\u002F Scala\ndef applyTwice[A](f: A => A, x: A): A = f(f(x))\n\ndef makeMultiplier(n: Int): Int => Int = x => x * n\n\nval double = makeMultiplier(2)\nval result = applyTwice(double, 5)  \u002F\u002F 20\n```\n\n## Decorators → Function Composition\n\n```python\n# Python\ndef log_calls(func):\n    def wrapper(*args, **kwargs):\n        print(f\"Calling {func.__name__}\")\n        result = func(*args, **kwargs)\n        print(f\"Finished {func.__name__}\")\n        return result\n    return wrapper\n\n@log_calls\ndef add(a, b):\n    return a + b\n```\n\n```scala\n\u002F\u002F Scala - function composition\ndef logCalls[A, B](f: A => B, name: String): A => B = { a =>\n  println(s\"Calling $name\")\n  val result = f(a)\n  println(s\"Finished $name\")\n  result\n}\n\nval add = (a: Int, b: Int) => a + b\nval loggedAdd = logCalls(add.tupled, \"add\")\n\n\u002F\u002F Alternative: using by-name parameters\ndef withLogging[A](name: String)(block: => A): A = {\n  println(s\"Calling $name\")\n  val result = block\n  println(s\"Finished $name\")\n  result\n}\n```\n\n## Pattern Matching\n\n```python\n# Python (3.10+)\ndef describe(value):\n    match value:\n        case 0:\n            return \"zero\"\n        case int(x) if x > 0:\n            return \"positive int\"\n        case int(x):\n            return \"negative int\"\n        case [x, y]:\n            return f\"pair: {x}, {y}\"\n        case {\"name\": name, \"age\": age}:\n            return f\"{name} is {age}\"\n        case _:\n            return \"unknown\"\n```\n\n```scala\n\u002F\u002F Scala - pattern matching is more powerful\ndef describe(value: Any): String = value match {\n  case 0 => \"zero\"\n  case x: Int if x > 0 => \"positive int\"\n  case _: Int => \"negative int\"\n  case (x, y) => s\"pair: $x, $y\"\n  case List(x, y) => s\"list of two: $x, $y\"\n  case m: Map[_, _] if m.contains(\"name\") =>\n    s\"${m(\"name\")} is ${m(\"age\")}\"  \u002F\u002F beware: Map.apply throws if missing\n  case _ => \"unknown\"\n}\n\n\u002F\u002F Case class pattern matching (preferred)\nsealed trait Result\ncase class Success(value: Int) extends Result\ncase class Error(message: String) extends Result\n\ndef handle(result: Result): String = result match {\n  case Success(v) if v > 100 => s\"Big success: $v\"\n  case Success(v) => s\"Success: $v\"\n  case Error(msg) => s\"Failed: $msg\"\n}\n```\n\n## Option Handling (None\u002Fnull Safety)\n\n```python\n# Python\ndef find_user(user_id: int) -> Optional[User]:\n    user = db.get(user_id)\n    return user if user else None\n```\n\n```scala\n\u002F\u002F Scala - Option\ndef findUser(userId: Int): Option[User] = db.get(userId)\n```\n\n### Translating Python runtime dispatch (duck typing + None)\n\nPython often accepts many runtime types in one function (e.g., `def tokenize(value: Any)`) and explicitly handles `None`.\nIn Scala, you can keep behavior **without** making the whole codebase `Any`-typed:\n\n- Provide **typed entry points** where possible (overloads or distinct methods).\n- Provide **one runtime-dispatch entry point** only where the Python truly does so.\n- If the Python accepts `None`, the Scala runtime entry point should either:\n  - accept `Any` and treat `null` as “missing”, or\n  - accept `Option[Any]` and handle `None`.\n\nPrefer a small “boundary” method with `Any`\u002F`null` handling, and keep internal logic typed.\n\n## Generators → Iterators\u002FLazyList\n\n```python\n# Python\ndef fibonacci():\n    a, b = 0, 1\n    while True:\n        yield a\n        a, b = b, a + b\n```\n\n```scala\n\u002F\u002F Scala - LazyList (was Stream in Scala 2.12)\ndef fibonacci: LazyList[BigInt] = {\n  def loop(a: BigInt, b: BigInt): LazyList[BigInt] =\n    a #:: loop(b, a + b)\n  loop(0, 1)\n}\n```\n\n## Try\u002FEither for Error Handling\n\n```python\n# Python - exceptions\ndef parse_int(s: str) -> int:\n    try:\n        return int(s)\n    except ValueError:\n        return 0\n```\n\n```scala\n\u002F\u002F Scala - Try monad\nimport scala.util.{Try, Success, Failure}\n\ndef parseInt(s: String): Try[Int] = Try(s.toInt)\n```\n\n## Function Composition\n\n```python\n# Python\ndef compose(f, g):\n    return lambda x: f(g(x))\n```\n\n```scala\nval addOne: Int => Int = _ + 1\nval double: Int => Int = _ * 2\n\nval composed = addOne.compose(double)  \u002F\u002F addOne(double(x))\nval pipeline = addOne.andThen(double).andThen(addOne)\n```\n\n## Currying and Partial Application\n\n```python\n# Python\nfrom functools import partial\n\ndef add(a, b, c):\n    return a + b + c\n```\n\n```scala\n\u002F\u002F Scala - curried functions\ndef add(a: Int)(b: Int)(c: Int): Int = a + b + c\n```\n\n## Tail Recursion\n\n```python\n# Python - no tail call optimization\ndef factorial(n):\n    if n \u003C= 1:\n        return 1\n    return n * factorial(n - 1)\n```\n\n```scala\n\u002F\u002F Scala - tail recursion with annotation\nimport scala.annotation.tailrec\n\ndef factorial(n: Int): BigInt = {\n  @tailrec\n  def loop(n: Int, acc: BigInt): BigInt = {\n    if (n \u003C= 1) acc\n    else loop(n - 1, n * acc)\n  }\n  loop(n, 1)\n}\n```\n\n### `@tailrec` safety rule (Scala 2.13)\n\nOnly annotate with `@tailrec` when the recursive call is syntactically in **tail position**.\nA common non-tail pattern is mixing recursion with `Option.map\u002FflatMap` or other higher-order calls:\n\n```scala\n\u002F\u002F NOT tail-recursive (recursive call occurs inside flatMap)\n\u002F\u002F @tailrec  \u002F\u002F would fail compilation\nfinal def loop(parts: List[String], cur: Node): Option[Node] = parts match {\n  case Nil => Some(cur)\n  case p :: ps => cur.child(p).flatMap(loop(ps, _))\n}\n```\n\nFix by either:\n- removing `@tailrec`, or\n- rewriting to an explicit loop\u002Ffold that is actually tail-recursive.\n\n## Implicit Conversions and Type Classes\n\n```scala\n\u002F\u002F Scala 2 - type classes via implicits\ntrait Show[A] { def show(a: A): String }\n\nimplicit val intShow: Show[Int] = new Show[Int] {\n  def show(a: Int): String = s\"Int: $a\"\n}\n\ndef display[A](a: A)(implicit s: Show[A]): String = s.show(a)\n```\n",{"name":5,"description":7},"main","cdcb6d230f3b15c3c33f8a2bdd16439f43602cbe","evaluation\u002Fresults\u002FSkillAxe\u002Ftasks\u002Fpython-scala-translation\u002Frepaired_skill\u002Fpython-scala-functional",1,"https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark","https:\u002F\u002Fgithub.com\u002Flinyouxue","2026-11-14 20:28:35",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add linyouxue\u002Fskill-repair-benchmark --skill python-scala-functional",{"tool":37,"command":38},"bunx","bunx skills add linyouxue\u002Fskill-repair-benchmark --skill python-scala-functional",{"tool":40,"command":41},"pnpm","pnpm dlx skills add linyouxue\u002Fskill-repair-benchmark --skill python-scala-functional","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fevaluation\u002Fresults\u002FSkillAxe\u002Ftasks\u002Fpython-scala-translation\u002Frepaired_skill\u002Fpython-scala-functional\u002FSKILL.md",true,[],[46,53,60,67,72,77],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":19},"01M7E1HGVRY73NBJ022CJG13X6","video-frame-extraction","Extract frames from video files and save them as images using OpenCV","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fvideo-frame-extraction\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M7E1HAG5R7CJ9C8NYJS771MB","openai-vision","Analyze images and multi-frame sequences using OpenAI GPT vision models","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fopenai-vision\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M7E1H7DADKB6QBWKC2KQ63SZ","image-ocr","Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",[],[],{"skillNo":68,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M7E1H0WBNT43TENGQY7AVZHD","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fvideo-frame-extraction\u002FSKILL.md",[],[],{"skillNo":73,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M7E1GTC7D4N4Q2EF03875J9E","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fopenai-vision\u002FSKILL.md",[],[],{"skillNo":78,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7E1GQ92CWFMGH53KSSE4WER","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",[],[]]