Langsung ke konten
Skillpedia
Pemrograman umum48k Β· #4652

fp-types-ref

Fungsinya

Membantu Anda memilih tipe yang tepat (seperti Option, Either, Task) di library fp-ts untuk menyusun kode TypeScript, terutama saat berhadapan dengan nilai yang mungkin tidak ada atau operasi asinkron yang bisa menghasilkan error.

Kapan dipakai

  • βœ“Perlu memutuskan antara Option, Either, Task, atau TaskEither.
  • βœ“Belum yakin cara mengimpor tipe fp-ts.
  • βœ“Ingin panduan singkat untuk pola fp-ts yang umum digunakan.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-types-ref/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œTipe fp-ts mana yang sebaiknya saya gunakan untuk fungsi yang bersifat asinkron dan bisa gagal?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

AI menggunakan diagram alur sederhana untuk membantu Anda memilih, berdasarkan apakah operasinya asinkron, bisa gagal, atau apakah nilainya mungkin tidak ada. AI juga memberikan contoh kode untuk impor dan pola yang umum.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

fp-ts Quick Reference

When to Use

  • You need help choosing between Option, Either, Task, TaskEither, or related fp-ts types.
  • The task is about imports, decision guidance, or selecting the right abstraction for a TypeScript flow.
  • You want a compact reference for common fp-ts type choices and patterns.

Which Type Should I Use?

Is the operation async?
β”œβ”€ NO: Does it involve errors?
β”‚   β”œβ”€ YES β†’ Either<Error, Value>
β”‚   └─ NO: Might value be missing?
β”‚       β”œβ”€ YES β†’ Option<Value>
β”‚       └─ NO β†’ Just use the value
└─ YES: Does it involve errors?
    β”œβ”€ YES β†’ TaskEither<Error, Value>
    └─ NO: Might value be missing?
        β”œβ”€ YES β†’ TaskOption<Value>
        └─ NO β†’ Task<Value>

Common Imports

// Core
import { pipe, flow } from 'fp-ts/function'

// Types
import * as O from 'fp-ts/Option'      // Maybe exists
import * as E from 'fp-ts/Either'      // Success or failure
import * as TE from 'fp-ts/TaskEither' // Async + failure
import * as T from 'fp-ts/Task'        // Lazy async; no typed error channel
import * as A from 'fp-ts/Array'       // Array utilities

One-Line Patterns

Need Code
Wrap nullable O.fromNullable(value)
Default value O.getOrElse(() => fallbackValue)
Transform if exists O.map(fn)
Chain optionals O.flatMap(fn)
Wrap try/catch E.tryCatch(() => risky(), toError)
Wrap async TE.tryCatch(() => fetch(url), toError)
Run pipe pipe(value, fn1, fn2, fn3)

Pattern Match

// Option
pipe(maybe, O.match(
  () => 'nothing',
  (val) => `got ${val}`
))

// Either
pipe(result, E.match(
  (err) => `error: ${err}`,
  (val) => `success: ${val}`
))

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.

Pertanyaan umum

Apa itu Option, Either, dan Task?

Ini adalah tipe yang membantu Anda menangani situasi pemrograman yang umum dengan lebih aman dan terstruktur, seperti nilai yang mungkin tidak ada (Option), operasi yang bisa berhasil atau gagal (Either), dan operasi yang membutuhkan waktu untuk selesai (Task).

Apa arti 'asinkron'?

Artinya operasi tidak selesai seketika, melainkan terjadi di waktu berikutnya. Contohnya mengambil data dari server atau membaca sebuah file.

Apa itu fp-ts?

Ini adalah library populer untuk TypeScript yang membawa konsep functional programming agar kode lebih andal dan mudah diprediksi.

Detail

Deskripsi asli dari pembuat

Quick reference for fp-ts types. Use when user asks which type to use, needs Option/Either/Task decision help, or wants fp-ts imports.

repo: sickn33/agentic-awesome-skills

Popularitas

Bintang GitHub
48k
Peringkat
#4652
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa