denofun
denofun copied to clipboard
add more functions
- [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
A getOrElse
method for Maybe
would also be nice!
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. :)
Hello, a headMaybe
method would be nice, I'm happy to create a PR if you agree
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.
@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()
@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.