Comments (6)
Hi, you can use compact
:
import { compact } from 'fp-ts/lib/Array';
declare const as: Array<Option<number>>
const bs: Array<number> = compact(as)
from fp-ts.
import { Option, some, none } from 'fp-ts/lib/Option'
import * as array from 'fp-ts/lib/Array'
import { identity } from 'fp-ts/lib/unction'
export function mapOption<A, B>(f: (a: A) => Option<B>, as: Array<A>): Array<B> {
return array.chain(a => f(a).fold(() => array.empty(), array.of), as)
}
export function catOptions<A>(as: Array<Option<A>>): Array<A> {
return mapOption<Option<A>, A>(identity, as)
}
const as = [none, some(1), none, some(2)]
console.log(catOptions(as)) // => [1, 2]
Is this something you think could be added to the library?
Good idea
from fp-ts.
Opss.. actually they are already implemented :) (Array
module) https://github.com/gcanti/fp-ts/blob/master/src/Array.ts#L213
from fp-ts.
Thanks!
from fp-ts.
What's the status of this issue? Is there a function like array.rights
that works with Option
instead of Either
?
from fp-ts.
Thanks!
from fp-ts.
Related Issues (20)
- Reproduce `Promise.all` behaviour HOT 2
- What is the idiomatic way to do pattern matching in the fp-ts ecosystem HOT 7
- Type signature of RTE.tapReaderIO is wrong
- Either.Do: `left` to be structurally similar to `right` HOT 1
- 🐠 Give `map` the same overloaded signature as `flatMap` HOT 2
- record.modifyAt doesn't infer value type at given key HOT 4
- lookup types incorrect HOT 4
- [Question (feature?)] Clean way to define a Semigroup over a (partially) partial type HOT 1
- `readonlyNonEmptyArray.union()` should accept `ReadonlyArray` as second argument
- Why does `Json.stringify` return an `Either`? HOT 2
- Directory import is not supported resolving ES modules HOT 6
- Add installation instructions to the docs HOT 1
- Is the signature of TaskEither.tapError as intended? HOT 1
- Add tapNoneIO for Option, TaskOption and IOOption and tapErrorIO for Either, TaskEither and IOEither
- Comment-related warnings when building with Vite HOT 3
- Improving option.getOrElse type inference HOT 1
- How can I do recursion in an array and make the isShow flag true?
- Sequencing is incompatible with array.map
- Misplaced/useless PURE comments with latest vite/rollup HOT 1
- [ReadonlyArray.ts] `flatten` can trigger `RangeError: Maximum call stack size exceeded`
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 fp-ts.