Raymond Barlow
11/07/2019, 4:41 AMbenleggiero
11/07/2019, 5:05 AMkevindmoore
11/07/2019, 5:59 AMRaymond Barlow
11/07/2019, 11:44 AMconst x _ = x
Scala:
const(a: A) = _ => a
Raymond Barlow
11/07/2019, 11:47 AMMike
11/07/2019, 1:01 PM{ it }
. So no built-in identity function, but depending on scenario, some succinct ways to accomplish it.Mike
11/07/2019, 1:01 PMRaymond Barlow
11/08/2019, 6:47 PMMike
11/08/2019, 7:30 PMconst
looks like it is a function that returns the passed parameter. Identity does the same thing, so aren't they equivalent, just a different name?Raymond Barlow
11/09/2019, 10:53 AMidentity()
returns what it is given when called. const(a)
will always return the value a
, no matter what the input.Raymond Barlow
11/09/2019, 10:54 AMconst(5)
would be the same as { _ -> 5 }
Raymond Barlow
11/09/2019, 10:55 AMRaymond Barlow
11/09/2019, 10:58 AMRaymond Barlow
11/09/2019, 11:01 AMRaymond Barlow
11/09/2019, 11:02 AMlistOf(1,2,3).map(identity()) == listOf(1,2,3)
Raymond Barlow
11/09/2019, 11:03 AMlistOf(1,2,3).map(const(5)) == listOf(5,5,5)
benleggiero
11/12/2019, 4:41 AMRaymond Barlow
11/12/2019, 8:15 AMMike
11/12/2019, 11:13 AM