Last active
May 25, 2024 10:18
-
-
Save dacr/40b50823f17d82d78dceb0cda345cfde to your computer and use it in GitHub Desktop.
lift/unlift scala feature / published by https://github.com/dacr/code-examples-manager #3d4c01e1-0654-4485-b77d-0b393eee934a/4ee57d58a5e13948b5056c0a25a942fe2dc196d9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : lift/unlift scala feature | |
// keywords : scala, language-feature, lift, unlift, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 3d4c01e1-0654-4485-b77d-0b393eee934a | |
// created-on : 2022-06-15T20:39:26+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
// --------------------- | |
val accesserA = Array(1,2,3).lift | |
assert(accesserA(1) == Some(2)) | |
val accesserM = Map(1->"a", 2->"b").lift | |
assert(accesserM(1) == Some("a")) | |
def f(i:Int)=Some(i) | |
val ua = Function.unlift(f) | |
ua(42) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment