-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type Safe Ramda Functions #145
Comments
I think we can tick the box beside Is there a reason you included
This should be possible. For example: concat :: Semigroup a => a -> a -> a |
Ah yes, of course.
Oops, no, just an oversight. Fixed. |
I assume that your concat would ensure that both arguments are the same type, right? |
That's right, @jethrolarson: const $ = require('sanctuary-def');
const def = $.create(true, $.env);
// a :: Type
const a = $.TypeVariable('a');
// Semigroup :: TypeClass
const Semigroup = $.TypeClass(
'sanctuary/Semigroup',
x => x != null && typeof x.concat === 'function'
);
// concat :: Semigroup a => a -> a -> a
const concat =
def('concat',
{a: [Semigroup]},
[a, a, a],
(x, y) => x.concat(y));
concat('abc', 'def');
// => 'abcdef'
concat([1, 2, 3], [4, 5, 6]);
// => [1, 2, 3, 4, 5, 6]
concat('abc', [1, 2, 3]);
// ! TypeError: ‘concat’ expected a value of type String as its second argument; received [1, 2, 3]
concat(['a', 'b', 'c'], [1, 2, 3]);
// ! TypeError: ‘concat’ expected a value of type (Array String) as its second argument; received [1, 2, 3] |
So, I'm trying to implement |
Yeah, semigroup doesn't give you index or length. Array-like does but On Sun, Feb 28, 2016, 3:42 AM Stefano Vozza [email protected]
|
Ha. Yes, I was hoping not to go down that route... |
Array-like can mostly be approximated by So you could have length. Though i'm not exactly sure how to type it with // length : Foldable f => f a -> NonNegativeInteger
function length(x) {
return x.reduce((state, _) => state + 1, 0);
} Are there any examples in |
One straightforward solution is a "Countable" type class which checks whether a given value has a valid
I believe higher-kinded types to be doable, but sanctuary-def doesn't yet support them. |
Something that was mentioned in the Gitter room was how this issue is a good gateway for people looking to contribute for the first time. It got me thinking that it might be cool to do what they do on the nodejs project and split some of this function list into individual issues and label them with the tag 'good first contribution' like this. What do people think? |
Great idea, Stefano! |
yeah these are totally |
I'll close this issue. We've added many of the important functions, and #216 will add a handful more. Don't hesitate to open an issue if there's a particular Ramda function you'd like sanctified. :) |
@davidchambers, do you have something like |
Sanctuary doesn't yet provide such a function, @futpib. Are you interested in working on a pull request to add it? |
@davidchambers #454 poof |
Why was R.modulo removed? |
As mentioned in #141, let's start try to get a list of typesafe functions we want from Ramda. I've put together a list of way too many functions that we can whittle down here as people chip in with their views.
R.append
R.concat
R.contains
R.equals
R.filter
R.fromPairs
R.keys
R.length
R.max
R.mean
R.median
R.merge
R.mergeAll
R.min
R.modulo
R.omit
R.prepend
R.product
R.range
R.reduce
R.reject
R.reverse
R.scan
R.split
R.sum
R.toPairs
R.trim
R.values
R.when
R.unless
R.zip
R.zipObj
Something I'm not clear on though is how we deal with functions that accept both arrays and string. Do we need a new type?
The text was updated successfully, but these errors were encountered: