Giter VIP home page Giter VIP logo

Comments (6)

giogonzo avatar giogonzo commented on May 22, 2024 10

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.

gcanti avatar gcanti commented on May 22, 2024
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.

gcanti avatar gcanti commented on May 22, 2024

Opss.. actually they are already implemented :) (Array module) https://github.com/gcanti/fp-ts/blob/master/src/Array.ts#L213

from fp-ts.

OliverJAsh avatar OliverJAsh commented on May 22, 2024

Thanks!

from fp-ts.

SRachamim avatar SRachamim commented on May 22, 2024

What's the status of this issue? Is there a function like array.rights that works with Option instead of Either?

from fp-ts.

SRachamim avatar SRachamim commented on May 22, 2024

Thanks!

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.