Models | Examples |
---|---|
Display ads | Yahoo! |
Search ads |
This file contains 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
//Check if the password is long enough | |
func isPasswordLongEnough(_ password:String) -> Validation<[String], String> { | |
if password.characters.count < 8 { | |
return Validation.Failure(["Password must have more than 8 characters."]) | |
} else { | |
return Validation.Success(password) | |
} | |
} | |
This file contains 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
func validatePassword(username: String, password:String) -> [String]{ | |
var errors:[String] = [] | |
if password.characters.count < 8 { | |
errors.append("Password must have more than 8 characters.") | |
} | |
if (password.range(of:"[\\W]", options: .regularExpression) == nil){ | |
errors.append("Password must contain a special character.") |
This file contains 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
//Validate min length | |
func minLength(_ value:String, min:Int, fieldName:String) -> Validation<[String], String>{ | |
if(value.characters.count < min){ | |
return Validation.Failure(["\(fieldName) must have more than \(min) characters"]) | |
} else { | |
return Validation.Success(value) | |
} | |
} | |
//Validate match a regular expression |
This file contains 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
//Validate min length | |
func minLength(_ value:String, min:Int, fieldName:String) -> Validation<[String], String>{ | |
if(value.characters.count < min){ | |
return Validation.Failure(["\(fieldName) must have more than \(min) characters"]) | |
} else { | |
return Validation.Success(value) | |
} | |
} | |
//Validate match a regular expression |
This file contains 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
//The fmap function is only applied on Success values. | |
let success: Validation<String, Int> = Validation.Success(1) | |
success.fmap{ $0 + 1 } | |
// ==> Validation.Success(2) | |
let failure: Validation<String, Int> = Validation.Failure("error") | |
failure.fmap{$0 + 1} | |
// ==> Validation.Failure("error") |
This file contains 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
//You can react to the validation result value, either it's a success or a failure | |
let success: Validation<String, Int> = Validation.Success(1) | |
switch(success){ | |
case .Success(let value): | |
print(value) | |
case .Failure(let error): | |
print(error) | |
} | |
// ==> Print(1) |
This file contains 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
'use strict'; | |
const R = require('ramda'); | |
const S = require('sanctuary'); | |
const data = { | |
id: 1, | |
orderName: 'Order from spain', | |
teamName: 'Portland penguins', |
This file contains 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
import Monads | |
func test() { | |
typealias DeferredResult<T> = Deferred<Result<T, String>> | |
typealias AsyncResult<T> = Effect<DeferredResult<T>> | |
struct User { | |
var name: String | |
var dateOfBirth: String | |
} |
This file contains 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
struct Todo { | |
var text: String | |
var completed: Bool | |
} | |
enum VisibilityFilter { | |
case showCompleted | |
case showAll | |
} | |
OlderNewer