Comments (3)
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.
- It's trivial to create that behavior from Array's traverse export.
- 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.
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.
@baetheus Nice, thanks! I will do a review.
from fun.
Related Issues (20)
- DecodeError 2.0
- Pair 2.0
- Predicate 2.0
- Refinement 2.0
- NonEmptyArray - Post 2.0 HOT 1
- Kind: Implement variance for kind.ts
- Free - Post 2.0
- ReadableStream - Post 2.0 HOT 1
- Partition and Filterable - Post 2.0 HOT 1
- Remove null from PartialSchemable
- Move all type and interface definitions out of types.ts
- Rename some ADTS HOT 4
- Moving Primary Development off Github HOT 6
- Module not found "https://deno.land/x/[email protected]/decode_error.ts" HOT 10
- "tap" function? HOT 6
- Async flow? HOT 4
- Peacetime Tasks
- Type Extractors
- Fixes for JSR HOT 1
- Audit Stream and Promise
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fun.