本文へスキップ
Skillpedia
一般的なプログラミング48k · #4643

fp-option-ref

できること

このツールは、コード内で存在するかもしれないし、しないかもしれない値を扱うのに役立ちます。値が欠けている可能性のあるデータを安全に扱う方法を提供し、よくあるエラーを防ぎます。

使う場面

  • ✓値を使う前に、それが存在するかを確認する必要があるとき。
  • ✓外部から届き、不完全かもしれないデータを扱うとき。
  • ✓期待した値が見つからないときにエラーメッセージが出るのを避けたいとき。

スキルのリンク

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-option-ref/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-option-ref/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“ユーザーの名前が存在するかどうかを、安全に確認するにはどうすればよいですか?”

毎週5つの新しいスキル。1分で読めます。

仕組み

「Option」という考え方を使います。値が存在すれば「Some(値)」、存在しなければ「None」となります。これにより、処理を安全につなげて書けます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Option Quick Reference

Option = value that might not exist. Some(value) or None.

When to Use

  • You need a quick fp-ts reference for nullable or optional values.
  • The task involves eliminating null checks, safe property access, or optional chaining with Option.
  • You want a short reference card rather than a full migration guide.

Create

import * as O from 'fp-ts/Option'

O.some(5)              // Some(5)
O.none                 // None
O.fromNullable(x)      // null/undefined → None, else Some(x)
O.fromPredicate((n: number) => n > 0)(x) // false → None, true → Some(x)

Transform

O.map(fn)              // Transform inner value
O.flatMap(fn)          // Chain Options (fn returns Option)
O.filter(predicate)    // None if predicate false

Extract

O.getOrElse(() => fallbackValue)  // Get value or default
O.toNullable(opt)           // Back to T | null
O.toUndefined(opt)          // Back to T | undefined
O.match(onNone, onSome)     // Pattern match

Common Patterns

import { pipe } from 'fp-ts/function'
import * as O from 'fp-ts/Option'

// Safe property access
pipe(
  O.fromNullable(user),
  O.flatMap(u => O.fromNullable(u.profile)),
  O.flatMap(p => O.fromNullable(p.avatar)),
  O.getOrElse(() => '/default-avatar.png')
)

// Array first element
import * as A from 'fp-ts/Array'
pipe(
  users,
  A.head,  // Option<User>
  O.map(u => u.name),
  O.getOrElse(() => 'No users')
)

vs Nullable

// Nullable: concise and safe for a short access chain
const name = user?.profile?.name ?? 'Guest'

// Option: explicit and composable across multiple operations
pipe(
  O.fromNullable(user),
  O.flatMap(u => O.fromNullable(u.profile)),
  O.flatMap(p => O.fromNullable(p.name)),
  O.getOrElse(() => 'Guest')
)

Use Option when you need to chain operations on optional values.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Reference scope

These are fp-ts 2.x fragments. Supply application variables, types, validators and imports, and check the installed version. map does not catch thrown exceptions. Task has no typed error channel; an improperly wrapped promise can still reject. Use tryCatch at fallible boundaries.

Official API: fp-ts modules.

よくある質問

「Option」を使うのと、単に「null」や「undefined」かどうかを確認するのとでは、何が違いますか?

長い連続した確認を行う場合、「Option」のほうが安全です。値がある場合とない場合の両方を、明示的かつ整理された形で扱うことが求められるためです。

「null」や「undefined」の値を「Option」に変換できますか?

できます。`fromNullable`などの関数を使うと、null になりうる値を「Option」に変換できます。

存在しない値を「Option」で使おうとするとどうなりますか?

エラーになるのではなく、設定の仕方によって、通常はデフォルト値か、値がなかったことを示す結果が返されます。

詳細

作者による元の説明

Quick reference for Option type. Use when user needs to handle nullable values, optional data, or wants to avoid null checks.

repo: sickn33/agentic-awesome-skills

人気

GitHubのスター
48k
ランキング
#4643
ライセンス
MIT
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル