denofun icon indicating copy to clipboard operation
denofun copied to clipboard

add more functions

Open tkgalk opened this issue 5 years ago • 6 comments

  • [x] concat
  • [x] equals
  • [x] find
  • [x] flatten
  • [x] groupBy
  • [x] has
  • [x] includes
  • [x] last
  • [x] lens
  • [ ] lift
  • [x] memoize
  • [x] nth
  • [x] pick
  • [x] pluck
  • [x] prop
  • [x] slice

tkgalk avatar Jul 17 '19 15:07 tkgalk

A getOrElse method for Maybe would also be nice!

MergHQ avatar May 20 '20 21:05 MergHQ

Thanks for the suggestion, that's a good idea I think. :)

Current Either and Maybe implementations in TS are very hacky due to TS not really supporting them. I'll revisit the current implementation. I also have an alternative way of working with unknown values using TypeScript's unknown in the pipeline. The API would be different and less "proper" but it would be more idiomatic TypeScript.

Thanks to Deno it'd be entirely optional and you can still only import specific files and not the whole package. :)

tkgalk avatar May 21 '20 06:05 tkgalk

Hello, a headMaybe method would be nice, I'm happy to create a PR if you agree

nicholasnbg avatar May 30 '20 02:05 nicholasnbg

So, I had a moment to sit down to those (finally, COVID really meant I had to focus on my paying job).

@MergHQ getOrElse is already there, its called default, ie: maybe(5).default(2) will return 2. I'm thinking of simplifying the Maybe/Either code but for now, it's not going anywhere.

tkgalk avatar Jun 09 '20 15:06 tkgalk

@nicholasnbg I'm not sure if that's something that I'd like to be added. Currently, it is pretty easy to create that by composing the functions we already have:

import head from "./lib/head.ts";
import maybe from "./lib/maybe.ts";
import compose from "./lib/compose.ts";

const a = [1, 2, 3, 4];
const b: number[] = [];

const maybeHead = compose(maybe, head);

const maybeA = maybeHead(a);
const maybeB = maybeHead(b);

console.log(maybeA); // => just(1)
console.log(maybeB); // => nothing()

tkgalk avatar Jun 09 '20 15:06 tkgalk

@galkowskit Sure, I can understand that, I guess the main reason I'd have for wanting to add something like maybeHead is it guides people to, and promotes a typesafe way of accessing the first item in an array, which is think is important in an FP library. (Pure functions etc)

Calling .head has a return type: A | undefined, which will most likely be met with a if(x !== undefined) somewhere in the code, feels like we should guide people to working with Option in this case.

nicholasnbg avatar Jun 09 '20 22:06 nicholasnbg