Coder Social home page Coder Social logo

Comments (3)

baetheus avatar baetheus commented on August 20, 2024

This was a decision made early on when working out the type classes in hkts. You can see a discussion on it here. You can create a sequence function for any ADT with an Applicative class by doing this:

import * as A from "https://deno.land/x/fun/array.ts";
import * as O from "https://deno.land/x/fun/option.ts";
import { identity, pipe } from "https://deno.land/x/fun/fns.ts";

const sequence = pipe(
  O.map(identity),
  A.traverse(O.Applicative)
)

console.log(sequence([O.some(1), O.some(2)])) // { tag: "Some", value: [ 1, 2 ] }
console.log(sequence([O.none, O.some(2)])) // { tag: "None" }

I have two reasons for not creating a sequence function for each adt.

  1. It's trivial to create that behavior from Array's traverse export.
  2. I want to keep cross module imports low (ie. not pulling in all of the array.ts file for people that only want option or either).

I hope that previous issue link and the above code work for you!

from fun.

baetheus avatar baetheus commented on August 20, 2024

After playing around with the traverse function for awhile I found that the generic is not inferred properly by TypeScript still in the above example. I've implemented a createSequence function that coerces to the correct type in PR #8. Perhaps you wouldn't mind reviewing that?

from fun.

noverby avatar noverby commented on August 20, 2024

@baetheus Nice, thanks! I will do a review.

from fun.

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.