Skip to content

Map.remove to return removed value #46

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

Closed
scabug opened this issue Sep 1, 2007 · 4 comments
Closed

Map.remove to return removed value #46

scabug opened this issue Sep 1, 2007 · 4 comments

Comments

@scabug
Copy link

scabug commented Sep 1, 2007

mutable.Map should have method

def remove(key: A): Option[B]

immutable.Map should have method

def remove(key: A): (Option[B], Map[A, B])

Use case for mutable.Map:

val params: mutable.Map[String, String] = ...

val force = params.remove("force").isDefined
val quiet = params.remove("quiet").isDefined
val suffix = params.remove("suffix").getOrElse("~")

if (!params.isEmpty) throw new Exception("unknown parameters: " + params.keySet)
@scabug
Copy link
Author

scabug commented Sep 1, 2007

Imported From: https://issues.scala-lang.org/browse/SI-46?orig=1
Reporter: Commit Message Bot (anonymous)
Assignee: @mcdirmid

@scabug
Copy link
Author

scabug commented Sep 4, 2007

@mcdirmid said:
Method already in JCL as removeKey, added removeKey and put (both return options) to mutable map. Didn't use remove because JCL MutableIterable has a generic remove method that will conflict in JCL Map. Both removeKey and put are not implemented efficiently for mutable maps but are for JCL maps (I don't want to muck with the mutable maps to get them to work like that).

I don't think we should add these methods to immutable maps, the APIs are already complicated enough without multi-return values.

Temporary workaround:

val params: jcl.HashMap[String, String] = ...

val force = params.removeKey("force").isDefined
val quiet = params.removeKey("quiet").isDefined
val suffix = params.removeKey("suffix").getOrElse("~")

if (!params.isEmpty) throw new Exception("unknown parameters: " +
params.keySet)
{code}

@scabug
Copy link
Author

scabug commented Nov 24, 2007

@mcdirmid said:
removeKey is in mutable map now. Use removeKey and not remove if you want a return value.

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone 2.6.1 deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant