> [ R.head([]), R.head('') ]
Array [ undefined, '' ]
> [[][0], ''[0]]
[undefined, undefined]
[S.head([]), S.head('')] //=> [Nothing(),Nothing()]
R.head('')
should evaluate to ''
, in my view. Its type in this case is String -> String
. Those disturbed by the handling of empty inputs (as I am) can use S.head
instead.
thanks @algesten, yes, with lodash I use defaults function
imagin I have 3 objects
let a = {prop1: ‘a', prop2: ‘a'}
let b = {prop1: ‘b'}
let c = {prop2: ‘c'}
how implement next transformation: f(a, c) -> a' and f(b, c) -> b' and get
a' = {prop1: ‘a', prop2: ‘a’}
b' = {prop1: ‘b', prop2: ‘c’}
R.head('') -> ''
sort of also an expression of you being disturbed by empty inputs? .. i mean a why shy away from undefined? ;)
I would rather the types be
head :: [a] -> a?
head :: String -> String
than
head :: [a] -> a?
head :: String -> String?
One can view head(s)
as taking a slice of s
from index 0 to index 1, which gives ''
when s
is ''
.
That's my justification, at any rate. ;)
[a] -> a
and in the other case we have a -> a
is very odd!
String
is really [Char]
, since we don't even have Char.
string -> char
?
head
working with an interface?
[R.head(''), R.tail(''), R.last('')] // => ["", "", ""]
[R.head([]), R.tail([]), R.last([])] // => [undefined, [], undefined]
head
, tail
, cons
as the things you need to implement, then you have certain laws, cons(head(xs), tail(xs)) == xs
or whatever.
undefined
, as a value, is as much part of the type string as it is part of the type array.
cons(undefined, [])
really should be []
cons(undefined, '')
should be ''
R.cons
to arbitrate whether those rules are upheld.
We have R.prepend
, which for some reason does this:
> R.prepend('', '')
['']
It's not supposed to accept a string as its second argument, of course.
> R.prepend('a', 'bc')
["a", "b", "c"]
length(cons(x, xs)) == length(xs) + 1
cons
you gave above would not be true any longer.
(a, b, c) => …
into a => b => c => …
.
(a, b, c) =>
into a => b => c =>
the crowd there was very new to FP, so was trying to simplify.
@joneshf: I'm a little confused by the types of what you'd want: You made two suggestions very close together. You want
head([]); //=> Nothing
which presumably implies:
head :: [a] -> Maybe(a)
But cons
, as I've always thought of it, is something like
cons: a -> [a] -> [a]
So with those two, I can make little sense of your proposed law that
cons(head(xs), tail(xs)) == xs
It's not that I don't like the law, but I can't see how it works with Maybe(a)
for its first parameter. Am I missing something simple?
fn(a)(b)(c)(d)
, and never as fn(a, b, c, d)
or fn(a, b)(c)(d)
, etc.