Giter VIP home page Giter VIP logo

Comments (7)

gcanti avatar gcanti commented on June 3, 2024 1

There's no module in fp-ts for generic pattern matching, all data types have its own specialized match function, you can use something like ts-pattern

from fp-ts.

DenisFrezzato avatar DenisFrezzato commented on June 3, 2024 1

Perhaps https://github.com/pfgray/ts-adt is more close to what you're looking for.

from fp-ts.

siwatanejo avatar siwatanejo commented on June 3, 2024 1

Holy shit that's ugly

from fp-ts.

CarpentersKeys avatar CarpentersKeys commented on June 3, 2024

Would it make sense to have Record.match to do this?

Would also like the options to match("key")([predicate, operation])(value)

from fp-ts.

siwatanejo avatar siwatanejo commented on June 3, 2024

all data types have its own specialized match function, you can use something like ts-pattern

Can you give an example? I'm finding very hard to use fp-ts from TS (mind you, I don't have zero FP experience, I come from F#).

from fp-ts.

samhh avatar samhh commented on June 3, 2024

There's also @unsplash/sum-types if you can accept the constraint of no generics.

from fp-ts.

kingjordan avatar kingjordan commented on June 3, 2024

I use ts-adt like @DenisFrezzato mentioned

use it like:

import { makeMatch } from "ts-adt/MakeADT";

interface ICounterActions {type: "increment" | "decrement"}
 matchType = makeMatch("type");

const counterReducer = (state: number, action: ICounterActions) => {
  return pipe(
    action,
    matchType({
      increment: ()=> { state => state + 1 },
      decrement: ()=> { state => state - 1 },
   })
};

This will throw an error if have not implemented a type or implement a type that does not exist. I personally like this because if I make a change it forces me to handle the new type anywhere I match it.

This video explains it well

from fp-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.