Giter Site home page Giter Site logo

spacelift's Introduction

spacelift's People

Contributors

alexgalays avatar alx-l avatar aurelienrichez avatar bigbluehat avatar chris2cant avatar denis-mludek avatar qwefgh90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spacelift's Issues

Pattern matching for Option and Result

I saw this here https://github.com/Threestup/monads
Looks like a neat approach for pseudo pattern matching.

let result = Some("Sam")

let message = result.match({
    Some: res => `Hello ${res}`,
    None : () => 'Hello World',
})

It would be great to have this. In the example above I made the None case be a function, because you might have an expensive computation there or side effects.

Please do not remove Option and Result from this library

Follow up issue on #18

Version 1.x.x won't have Option (nor Result) as [...] the addition of ?. in the language, I feel like it's no longer offsetting the choice burden it adds on top of T | undefined or ?: T.

I disagree with this conclusion. Option is both more explicit and more expressive than the undefined syntax. Option allows you to compose functions in ways that undefined just does not have a comparable API for.

Compare (undefined version)

function go(x: string) {
  const a = mayFailA(x);
  if (a !== undefined) {
    const b = mayFailB(a);
    if (b !== undefined) {
      const c = mayFailC(b);
      if (c !== undefined) return c;
    }
  }
  return attemptTwo(x);
}
const result = go('x')
if(result !== undefined) console.log(result);

with (Option version), same logic

mayFailA('x')
  .flatMap(mayFailB)
  .flatMap(mayFailC)
  .orElse(() => attemptTwo('x'))
  .forEach(console.log);

This is currently my go-to lightweight library for Option and Result. I argue if those fundamental monads should be removed, it should be published under a new name, rather than as an "upgrade".

tuple(a, b, ...etc) always returns first element, instead of tuple

Problem

> tuple(1, 2)
=> 1

expected [1, 2], but got 1

> tuple("first", "second", "third")
=> "first"

expected ["first", "second", "third"], but got "first"

Solution

I think this code

export function tuple(arr: any[]): any {
  return arr
}

... just needs to be changed to

export function tuple(...arr: any[]): any {
  return arr
}

Cannot use library

Hey!
Thanks for your work!

I came back to space-lift after some time and I cannot really run it. I immediately get errors when trying to run examples.

index.ts(10,4): error TS2339: Property 'findIndex' does not exist on type 'ArrayOps<{ id: number; name: string; }>'.
index.ts(11,30): error TS2339: Property 'updateAt' does not exist on type 'ArrayOps<{ id: number; name: string; }>'.

You can also see it some online coding environments. https://codesandbox.io/s/4xn0zj3o40

space_lift_1.default(...).findIndex is not a function

import lift, { update } from 'space-lift'

const people = [
  { id: 1, name: 'jon' },
  { id: 2, name: 'sarah' },
  { id: 3, name: 'nina' }
]

const updatedPeople = lift(people)
  .findIndex(p => p.id === 2)
  .map(index => lift(people).updateAt(index, person => update(person, { name: 'Nick' })))
  .getOrElse(people)
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "tsc": "tsc" 
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "space-lift": "^0.6.5",
    "typescript": "^2.7.2"
  }
}

Typescript: Interface 'None' incorrectly extends interface 'Option<never>'

I'm trying to use the lib in my angular/typescript project, but unfortunately I can't compile it because of this error. I'm using angular-cli 1.7.3, where I configured it's "scripts" section like this:

      "scripts": [
        "../node_modules/space-lift/es/all.js",
        "../node_modules/lodash/core.min.js"
      ],

And here is my tsconfig:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

The error itself is here:

image

Any ideas, what I'm doing wrong?

Option.toResult and Result.toMaybe

Nice lib!

When working with function than return Option or Result it is very useful to convert one to the other. In that way is possible to chain these e.g.

Some(34)
    .toResult("No number")
    .flatMap(n => Ok(x * 2))

See
http://package.elm-lang.org/packages/elm-lang/core/latest/Result#fromMaybe
https://doc.rust-lang.org/core/option/enum.Option.html#method.ok_or

Result.toMaybe would also be great.
https://doc.rust-lang.org/core/result/enum.Result.html#method.ok

Please consider adding these.

Depend on @types/mocha via package.json?

Instead of vendoring Mocha's types, would you be up for a PR that pulled them in using @types/mocha in the package.json? Happy to do that legwork myself, probably mid-to-late next week.

None.get(): undefined is incompatible with never

doesn't compile:

error TS2430: Interface 'None' incorrectly extends interface 'Option<never>'.
  Types of property 'get' are incompatible.
    Type '() => undefined' is not assignable to type '() => never'.
      Type 'undefined' is not assignable to type 'never'.

Option (and whatever else) missing

Posting this here mainly for others. I spent considerable time trying to make my import statement work without success.

Turns out that the latest tag on npm is pointing to 1.0.0-beta.3. This version does not contain [all] the classes of the 0.8.x version listed in the README. So if something is missing, downgrade to 0.8.7 and you'll be fine.

Would be good to fix the latest tag on npm until the 1.x series actually has a release.

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.